This incoming middleware will make the following available in the middleware being called after it:
update.watsonUpdate: the response Watson Conversation came with based on the text the bot received
update.session.watsonContext: this is simply the watson context, which is also available at
update.watsonUpdate.context. However, here, it is leveraging sessionWare and will be persisted that way. For normal use, you shouldn't worry with this.
update.watsonConversation: Simply exposing the watson conversation object that has been used to get the response from watson. It can be used . This is the
conversationobject as seen here: https://www.ibm.com/watson/developercloud/conversation/api/v1/?node#apiexplorer. You'll only want to use this if you wish to make calls to, say, another workspace, or want to retrieve something else than simply the response from Watson (e.g. list of intents etc...). Powerful bots will probably make use of this in order to continually train watson for example.
yarn add botmaster-watson-conversation-ware
or with npm
npm install --save botmaster-watson-conversation-ware
This middleware can only be used in conjunction with botmaster-session-ware:
https://github.com/botmasterai/botmaster-session-ware. As the context from
botmaster needs to be persisted across different user messages.
See how sessionWare is added at the end of the example using
Using this will create a botmaster 3 valid incoming middleware object
that can be added by simply doing:
botmaster.use (See example below)
settingsobject $0.settings just a valid watsonConversationSettings object that can be passed to watson-developer-cloud
workspaceIdstring $0.workspaceId The workspace Id you want to connect to
const Botmaster = ;// Using this socket.io bot class for the sake of the exampleconst SocketioBot = ;// might want to use this in conjunction with your own store in production// as SessionWare uses the non-production ready MemoryStore by defaultconst SessionWare = ;const WatsonConversationWare = ;const botmaster = ;botmaster;const watsonConversationWareOptions =settings:username: <username_as_provided_by_bluemix>password: <password_as_provided_by_bluemix>version: 'v1' // as of this writing (01 Apr 2017), only v1 is availableversion_date: '2017-02-03' // latest version-date as of this writingworkspaceId: <the_workspace_id_to_communicate_with> // As provided by Watson Conversation// declaring middlewareconst watsonConversationWare = ;botmaster;botmaster// This will make our context persist throughout different messages from the// same userconst incomingSessionWare outgoingSessionWare = ;botmaster;
Returns object valid botmaster 3.0 incoming middleware object