howdyai / botkit-cms

An open tool for designing, building and managing interactive dialog systems
https://botkit.ai
MIT License
265 stars 92 forks source link

Using botkit-cms component in Botkit App #12

Closed nayanbhagowaty closed 5 years ago

nayanbhagowaty commented 5 years ago

I have created a chatbot with following steps, which is working fine. npm install -g botkit botkit new --platform web npm install --save botkit-cms

Then, I removed the scripts in the skills folder (except _connection_events.js) & created a new script with code

module.exports = function(controller) {
controller.on('message_received', function(bot, message) {
    controller.studio.runTrigger(bot, message.text, message.user, message.channel).catch(function(err) {
           bot.reply(message, {text: 'Sorry, I don\'t understand.'});
        });
      });
};

also, added following code after controller initiation in bot.js

var cms = require('botkit-cms')();
cms.useLocalStudio(controller); 
cms.loadScriptsFromFile(__dirname + '/scripts.json').catch(function(err) {
       console.error('Error loading scripts', err);`
});

and in the root, copied scripts.json from cms with basic reply for 'hello' command (same as in sample_scripts.json).

There's no error, but I'm not getting any response from the bot when I pass 'hello' to chatbot. What wrong I'm doing?

nayanbhagowaty commented 5 years ago

@peterswimm @benbrown .. I found the issue. The "id" field is missing in the scripts.json created in CMS. Could it be taken as bug & update in Botkit-CMS?

benbrown commented 5 years ago

@nayan112 yes! the id field should definitely be included. Ddi you copy the scripts.json file directly from your CMS instance, or did you use the export tool from within the UI?

nayanbhagowaty commented 5 years ago

@benbrown I tried exporting & copying the output within the CMS UI. Both ways, ID is missing.

The next challenge is getting the variable filled with user input & display it for testing purpose. I don't see any documentation or sample code. could you help?

benbrown commented 5 years ago

@nayan112 are you sure you are using the latest version of botkit-cms?

benbrown commented 5 years ago

the id field should definitely be present in the json file created by the CMS. It may be missing from the export.

Regarding variables, you set them in the convo.vars property during a controller.studio.before or other handler.

nayanbhagowaty commented 5 years ago

@benbrown You're right. It's missing from export only, present in script.json in .data folder.

There're few more differences from repo document related to initial run (eg. npm run build didn't work for me). I have documented here to help beginners like me.