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

时间:2017-09-07 20:20:19

标签: javascript azure slack botkit

我们在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);

});

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

我没有找到关于如何在天蓝色本地托管botkit机器人时添加新技能脚本的非常好的文档,以便松弛机器人选择它们...我甚至尝试包装所有上述内容(减去var Botkit和mod.exports = function(controller)中的var controller line)仍然没有响应。

任何人都可以提供一些关于我如何在技能文件夹中的新js文件中进行自定义对话的指导,并让我已经联系起来的slack bot实际上是在听吗?

1 个答案:

答案 0 :(得分:0)

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

module.exports = function(controller) {

// your skill code here

}
相关问题