npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

botmaster-watson-conversation-ware

v1.1.2

Published

Botmaster middleware for Watson Conversation

Downloads

15

Readme

Botmaster Watson Conversation Ware

Build Status Coverage Status npm-version license

This incoming middleware will make the following available in the middleware being called after it:

  1. update.watsonUpdate: the response Watson Conversation came with based on the text the bot received
  2. 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.
  3. 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 conversation object 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.

Install

yarn add botmaster-watson-conversation-ware

or with npm

npm install --save botmaster-watson-conversation-ware

Note

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 useWrapped.

API

WatsonConversationWare

Using this will create a botmaster 3 valid incoming middleware object that can be added by simply doing: botmaster.use (See example below)

Parameters

  • settings object $0.settings just a valid watsonConversationSettings object that can be passed to watson-developer-cloud
  • workspaceId string $0.workspaceId The workspace Id you want to connect to
  • options

Examples

const Botmaster = require('botmaster');
// Using this socket.io bot class for the sake of the example
const SocketioBot = require('botmaster-socket.io');
// might want to use this in conjunction with your own store in production
// as SessionWare uses the non-production ready MemoryStore by default
const SessionWare = require('botmaster-session-ware');
const WatsonConversationWare = require('botmaster-watson-conversation-ware');

const botmaster = new Botmaster();
botmaster.addBot(new SocketioBot({
  id: 'botId',
  server: botmaster.server,
}));

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 available
    version_date: '2017-02-03', // latest version-date as of this writing
  },
  workspaceId: <the_workspace_id_to_communicate_with> // As provided by Watson Conversation
}

// declaring middleware
const watsonConversationWare = WatsonConversationWare(watsonConversationWareOptions);
botmaster.use(watsonConversationWare);

botmaster.use({
  type: 'incoming',
  name: 'my-awesome-middleware',
  controller: (bot, update) => {
    console.log(update.watsonUpdate);
    console.log(update.session.watsonContext);
    console.log(update.watson);

    // watsonUpdate.output.text is an array as watson can reply with a few
    // messages one after another
    return bot.sendTextCascadeTo(update.watsonUpdate.output.text, update.sender.id);
  }
})

// This will make our context persist throughout different messages from the
// same user
const { incomingSessionWare, outgoingSessionWare } = SessionWare();
botmaster.useWrapped(incomingSessionWare, outgoingSessionWare);

Returns object valid botmaster 3.0 incoming middleware object