首页 > 解决方案 > Botkit 4 + SlackAdapter:无法触发基本对话的回调

问题描述

我无法让基本的对话回调被解雇。谁能指出我使用 botkit 4 从 Slack 中的对话中获取响应的工作示例?我设置了 SlackAdapter 并使用了 SlackEventMiddleware 和 SlackMessageTypeMiddleware,但我的回调没有被调用。

我从 botkit 文档中获取了这个基本代码,并在 /slash 命令之后调用它。问题已写,但无论我写什么,都不会触发任何回调。我看到事件来到我的服务器,但没有看到这些回调。

这是我正在测试的代码:

    let convo = new BotkitConversation('cheese', controller)

    await bot.startPrivateConversation(message.user)

    // create a path for when a user says YES
    convo.addMessage('You said yes! How wonderful.', 'yes_thread')

    // create a path for when a user says NO
    convo.addMessage('You said no, that is too bad.', 'no_thread')

    // create a path where neither option was matched
    // this message has an action field, which directs botkit to go back to the `default` thread after sending this message.
    convo.addMessage('Sorry I did not understand.', 'bad_response')

    // Create a yes/no question in the default thread...
    convo.addQuestion(
        'Do you like cheese?',
        [
            {
                pattern: 'yes',
                handler: async (response, convo, bot) => {
                    await convo.gotoThread('yes_thread')
                }
            },
            {
                pattern: 'no',
                handler: async (response, convo, bot) => {
                    await convo.gotoThread('no_thread')
                }
            },
            {
                default: true,
                handler: async (response, convo, bot) => {
                    await convo.gotoThread('bad_response')
                }
            }
        ],
        'likes_cheese',
        'default'
    )

    controller.addDialog(convo)

    await bot.beginDialog(`cheese`)

非常感谢任何帮助!

标签: javascriptexpressslackbotkit

解决方案


结果发现我的自定义存储提供程序中的某些东西正在干扰。我还没有深入了解它,但是当我注释掉我的存储提供程序时,我能够得到对话回调。

例如

const controller: Botkit = new Botkit({
    adapter: getSlackAdapter()

    // TODO: This is causing conversation call backs to NOT fire, let's revisit this later. We may not actually need this.
    //storage: services.storageService
})

推荐阅读