Botkit Slack Bot not listening to new js files (hosted on azure)

157 views Asked by At

We hosted a botkit bot on azure, following their guidelines and cloning in the repo from here: https://github.com/howdyai/botkit-starter-slack

Then, I tried adding a new js file to the skills folder that looks like:

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);

});

The bot correctly communicates with our slack channel and we can type the basic, already included commands and get response. However, when I type 'new event' to try to access this new script I just made, nothing happens.

I am not finding very good documentation on how to add new skill scripts when locally hosting a botkit bot on azure so that the slack bot picks them up... I have even tried wrapping all the above (minus the var Botkit and var controller line) in a module.exports = function(controller) and still got no response.

Can anyone offer some guidance on how I can make a custom conversation in a new js file in the skills folder and have my already hooked up slack bot actually listen for it?

1

There are 1 answers

0
Ben Brown On

Your skill module should actually receive the controller from the main bot.js file as a parameter -- it should look like

module.exports = function(controller) {

// your skill code here

}