Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Missing documentation for adding calls to CMS to starter kits #17

Open
benbrown opened this issue Feb 25, 2019 · 0 comments
Open

Missing documentation for adding calls to CMS to starter kits #17

benbrown opened this issue Feb 25, 2019 · 0 comments

Comments

@benbrown
Copy link
Contributor

We should add documentation about making calls to controller.studio.runTrigger.

The following code should be added to the bot.js file, in addition to configuring the controller with the studio_command_url parameter:

// This captures and evaluates any message sent to the bot as a DM
// or sent to the bot in the form "@bot message" and passes it to
// Botkit Studio to evaluate for trigger words and patterns.
// If a trigger is matched, the conversation will automatically fire!
// You can tie into the execution of the script using the functions
// controller.studio.before, controller.studio.after and controller.studio.validate
if (process.env.studio_token) {
    controller.on('message_received', function(bot, message) {
        controller.studio.runTrigger(bot, message.text, message.user, message.channel, message).then(function(convo) {
            if (!convo) {
              // web bot requires a response of some kind!
              bot.reply(message,'OK');

                // no trigger was matched
                // If you want your bot to respond to every message,
                // define a 'fallback' script in Botkit Studio
                // and uncomment the line below.
                // controller.studio.run(bot, 'fallback', message.user, message.channel, message);
            } else {
                // set variables here that are needed for EVERY script
                // use controller.studio.before('script') to set variables specific to a script
                convo.setVar('current_time', new Date());
                convo.setVar('bot', controller.studio_identity);
            }
        }).catch(function(err) {
            bot.reply(message, 'I experienced an error with a request to Botkit Studio: ' + err);
            debug('Botkit Studio: ', err);
        });
    });
} else {

    console.log('~~~~~~~~~~');
    console.log('NOTE: Botkit Studio functionality has not been enabled');
    console.log('To enable, pass in a studio_token parameter with a token from https://studio.botkit.ai/');
}```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant