0

我们在 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 控制器线) 在 module.exports = function(controller) 中,但仍然没有响应。

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

4

1 回答 1

0

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

module.exports = function(controller) {

// your skill code here

}
于 2017-09-07T21:51:38.790 回答