1.0.5 • Published 7 years ago

@dirbalak/coach-the-bot v1.0.5

Weekly downloads
2
License
ISC
Repository
-
Last release
7 years ago

Node.js SDK for CoachTheBot

This plugin allows you to integrate your chatbot with CoachTheBot server.

This plugin is for demo purposes. Please contact dirbalak@gmail.com for more information.

About

CoachTheBot can help your bot answer questions it cannot answer alone. Whenever you want your bot to use CoachTheBot, send the question and the coach will try to answer it by itself (using its AI engine) or ask for help from you or any person you invite (Currently, you will have to use Cisco Spark to communicate with the coach)

You can see a sample chatbot that uses CoachTheBot here

Installation

  • Install Node.js
  • Install coach-the-bot SDK with npm:
npm install @dirbalak/coach-the-bot

Usage

  • First, you will have to add the coach to Spark. To do that, add a person using the plus button, type coach.the.bot@sparkbot.io and hit enter. The coach will give you a secret key.

  • Let's take a simple chatbot implemented using Microsoft's botbuilder framework

var restify = require('restify');
var builder = require('botbuilder');

var MICROSOFT_APP_PASSWORD = process.env.MICROSOFT_APP_PASSWORD;
var MICROSOFT_APP_ID = process.env.MICROSOFT_APP_ID;

var server = restify.createServer();
server.use(require('restify-plugins').bodyParser());

server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url);
});

var connector = new builder.ChatConnector({
    appId: MICROSOFT_APP_ID,
    appPassword: MICROSOFT_APP_PASSWORD
});

server.post('/api/messages', connector.listen());

var bot = new builder.UniversalBot(connector, function (session) {
  session.send("You said:"+session.message.text);
});
  • Call coach-the-bot with the secret key the coach gave you and with your chatbot server url:
var thecoach = require('@dirbalak/coach-the-bot')({
	coach_secret_key:'<secret key>',
	chatbot_endpoint:'<your chatbot url>/api/coach'
});
// endpoint CoachTheBot server will send back the results
server.post('/api/coach', (req, res) => {
	thecoach.trigger(req.body);
});

The CoachTheBot server will need an endpoint to send back the result.

  • Now let's make sure all requests to your chatbot are sent to CoachTheBot
var bot = new builder.UniversalBot(connector, function (session) {
  thecoach.process(session).then(function(response) {
    if (response.code < 0) {
      console.error("The coach returned an error: "+response.error);
    }
    if (response.message) session.send(response.message);
    else session.send("I am sorry but I cannot answer you right now...");
  }, function(error) {
    session.send("Something is not working: "+error);
  });
});
  • And here is the complete code with coach-the-bot integrated:
var restify = require('restify');
var builder = require('botbuilder');

var MICROSOFT_APP_PASSWORD = process.env.MICROSOFT_APP_PASSWORD;
var MICROSOFT_APP_ID = process.env.MICROSOFT_APP_ID;

var server = restify.createServer();
server.use(require('restify-plugins').bodyParser());

server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url);
});

var connector = new builder.ChatConnector({
    appId: MICROSOFT_APP_ID,
    appPassword: MICROSOFT_APP_PASSWORD
});

server.post('/api/messages', connector.listen());

var thecoach = require('@dirbalak/coach-the-bot')({
	coach_secret_key:'<secret key>',
	chatbot_endpoint:'<your chatbot url>/api/coach'
});
server.post('/api/coach', (req, res) => {
	thecoach.trigger(req.body);
});

var bot = new builder.UniversalBot(connector, function (session) {
  thecoach.process(session).then(function(response) {
    if (response.code < 0) {
      console.error("The coach returned an error: "+response.error);
    }
    if (response.message) session.send(response.message);
    else session.send("I am sorry but I cannot answer you right now...");
  }, function(error) {
    session.send("Something is not working: "+error);
  });
});

Testing

  • Make sure you are available on Spark and ask your chatbot a question. If the coach will need your help, it will ask for it through Spark.
1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago