Home Articles

Botkit Slack Bot没有收听新的js文件(托管在azure上)

Asked
Viewed 1738 times
0

我们在azure上托管了一个botkit bot,遵循他们的指导方针并从这里回购克隆: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);

});

机器人正确地与我们的松弛通道通信,我们可以键入基本的,已包含的命令并获得响应 . 但是,当我输入'new event'来尝试访问我刚刚创建的这个新脚本时,没有任何反应 .

我没有找到关于如何在Azure上本地托管botkit机器人时添加新技能脚本的非常好的文档,以便松弛机器人拿起它们...我甚至尝试包装以上所有(减去var Botkit和var控制器线) )在module.exports = function(控制器)中仍然没有响应 .

任何人都可以提供一些关于我如何在技能文件夹中的新js文件中进行自定义对话的指导,并且我已经连接松弛的机器人实际上是在听它吗?

1 Answer

  • 0

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

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

Related