【问题标题】:Botkit Slack Bot not listening to new js files (hosted on azure)Botkit Slack Bot 不听新的 js 文件(托管在 azure 上)
【发布时间】:2018-02-16 16:09:03
【问题描述】:

我们在 azure 上托管了一个 botkit 机器人,遵循他们的指南并从这里克隆到 repo:https://github.com/howdyai/botkit-starter-slack

然后,我尝试在技能文件夹中添加一个新的 js 文件,如下所示:

var Botkit = require('botkit');

var controller = Botkit.slackbot({});


controller.hears(['help'], 'direct_message,direct_mention,mention', (bot, message) => {
    bot.reply(message, {
        text: `You can ask me things like:
        "Today's agenda"
        "Create event"`
    });
});


controller.hears(['create event', 'new event'], 'direct_message,direct_mention,mention', (bot, message) => {

    let subject,
        start,
        duration,
        description,
        location,
        invitees,
        whatid,
        whoid;

    let askSubject = (response, convo) => {

        convo.ask("What is the subject of the event?", (response, convo) => {
            subject = response.text;
            askStart(response, convo);
            convo.next();
        });

    }

    let askStart = (response, convo) => {

        convo.ask("When would you like this event to start?", (response, convo) => {
            start = response.text;
            askDuration(response, convo);
            convo.next();
        });

    }

    let askDuration = (response, convo) => {

        convo.ask("How long will this event be?", (response, convo) => {
            duration = response.text;
            askDescription(response, convo);
            convo.next();
        });

    }

    let askDescription = (response, convo) => {

        convo.ask("Enter a description if you'd like.", (response, convo) => {
            description = response.text;
            askLocation(response, convo);
            convo.next();
        });

    }

    let askLocation = (response, convo) => {

        convo.ask("Enter a locatoin if you'd like.", (response, convo) => {
            location = response.text;
            askInvitees(response, convo);
            convo.next();
        });

    }

    let askInvitees = (response, convo) => {

        convo.ask("Enter a comma seperated list of invitees if you'd like.", (response, convo) => {
            invitees = response.text;
            askWhatId(response, convo);
            convo.next();
        });

    }

    let askWhatId = (response, convo) => {

        convo.ask("Add anything to the Related To field?", (response, convo) => {
            whatid = response.text;
            askWhoId(response, convo);
            convo.next();
        });

    }

    let askWhoId = (response, convo) => {

        convo.ask("Add anyone to the Name field?", (response, convo) => {
            whoid = response.text;
            /*salesforce.createContact({firstName: firstName, lastName: lastName, title: title, phone: phone})
                .then(contact => {
                    bot.reply(message, {
                        text: "I created the contact:",
                        attachments: formatter.formatContact(contact)
                    });
                    convo.next();
                })
                .catch(error => {
                    bot.reply(message, error);
                    convo.next();
                });*/
        });

    }

    bot.reply(message, "OK, I can help you with that!");
    bot.startConversation(message, askSubject);

});

机器人与我们的松弛通道正确通信,我们可以键入基本的、已包含的命令并获得响应。但是,当我键入“新事件”以尝试访问我刚刚制作的这个新脚本时,什么也没有发生。

我没有找到很好的文档来说明如何在 azure 上本地托管 botkit 机器人时添加新技能脚本,以便 slack 机器人拾取它们......我什至尝试过包装以上所有内容(减去 var Botkit 和var controller line) 在 module.exports = function(controller) 中,但仍然没有响应。

谁能提供一些指导,告诉我如何在技能文件夹中的新 js 文件中进行自定义对话,并让我已经连接的 slack 机器人实际监听它?

【问题讨论】:

    标签: javascript azure slack botkit


    【解决方案1】:

    您的技能模块实际上应该从主 bot.js 文件接收控制器作为参数 -- 它应该看起来像

    module.exports = function(controller) {
    
    // your skill code here
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-05
      • 1970-01-01
      • 2017-05-24
      • 2020-05-13
      • 2017-09-20
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      相关资源
      最近更新 更多