Humanise Middleware for Botmaster
This middleware allows you to easily connect an external bot to the Humanise.AI platform. It does so by sending every incoming and outgoing update (for now, only those that contains text) to the humanise platform.
It is written as a wrapped middleware (see here) for more on botmaster middleware.
Incoming updates
Incoming updates would come from a certain platform (i.e. FB messenger) and this middleware would just forward the update to the humanise platform.
Outgoing Updates
Because we want to be able to leverage the humanise platform, we want to be able to both supervise and pause the bot we have written. To do that, instead of sending outgoing updates straight back to the platform, we send it to humanise. We then setup a local endpoint humanise then calls back in order to let us know if/when to send an update object. Humanise can also use this endpoint to send human agent updates straight to a wanted platform. Read more about this in the following 2 sections (Usage and Examples)
As this library uses async/await please use Node.JS 8 or greater
Usage
Once you have received your ApiKey
and botUserId
from humanise, you will need to setup a project. Here is a minimal example of such a setup. This example uses express. But using any other webserver should work (our Watson Conversation example uses koa)
const express = const bodyParser = const Botmaster = const MessengerBot = // for this exampleconst makeHumaniseWare = // 1) create http server from express app object that will be used laterconst PORT = 3000const app = ;const server = app; // 2) create botmaster object and mount middlewareconst HUMANISE_API_KEY = 'Your_HUMANISE_API_KEY'// this url will be created by humanise and displayed in the UI upon creation of a custom channelconst HUMANISE_INCOMING_WEBHOOK_URL='YOUR_HUMANISE_INCOMING_WEBHOOK_URL' const botmaster = server // enter your messenger credentials. You can also use another bot class if// your bot supports other platforms. Have a look at the `botmaster-messenger` project for more info on that: https://github.com/botmasterai/botmaster-messengerbotmaster // simple incoming middleware that replies randomly from a set of deterministic repliesbotmaster // after adding all your other middleware and wrapped middleware (a potential logging wrapped middleware can still come after) const humaniseWare = botmaster // 3) make sure your express web-server has a /humanise endpoint it can// receive requests from humanise on. // just bodyParser stuffapp// parse application/jsonapp app
Examples
For an example that actually does something useful, have a look at the Facebook Messenger example.
API
Table of Contents
makeHumaniseWare
Make botmaster middleware
Parameters
$0
Object$0.apiKey
$0.botUserId
$0.logger
$0.getEscalationFromUpdate
ApiKey
$0.apiKey Humanise.AI API KeybotUserId
$0.apiKey Humanise.API Bot ID to register updates as.Logger
$0.logger? optional logger with .verbose, .debug, .error, .info, .warning methodsgetEscalationFromUpdate
$0.getEscalationFromUpdate? optional async function that takes a botmaster update and returns 'lowSentiment', 'handoff', 'lowConfidence' or null. Use this param to dynamically set whether you want to escalade a conversation based on a certain user input message. Sentiment of the user's message is a good example of how to use this.