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 🙏

© 2026 – Pkg Stats / Ryan Hefner

wit-messenger-bot

v1.0.3

Published

messenger/wit.ai client

Readme

wit-messenger-bot

A class for using wit.ai with messenger platform + a conversation session setup with realm.

Installation

npm install wit-messenger-bot

What it does

This module makes use of the wrapper class at https://github.com/remixz/messenger-bot and integrates additional NLP functionality and actions from wit.ai. It comes with a default built-in "send" action for wit.ai you can use at your will.

It also has a simple persistent sessions setup to store & query conversation context by facebook id using the Realm SDK for Node, but you need not touch on this layer. You can use the code provided to jump straight to the logic for your facebook messenger chatbot.

Functions

let bot = new WitMessengerBot(fbOptions, witOptions, botSessionsDelegate)

Returns an instance of the WitMessengerBot class. This creates a wit instance & initializes your sessions setup.

fbOptions - Object

  • token - String: Your Page Access Token, found in your App settings. Required.
  • verify - String: A verification token for the first-time setup of your webhook. Optional, but will be required by Facebook when you first set up your webhook.
  • app_secret - String: Your App Secret token used for message integrity check. If specified, every POST request will be tested for spoofing. Optional.

witOptions - Object

The Wit constructor takes the following parameters:

  • accessToken - the access token of your Wit instance
  • actions - the object with your actions
  • logger - (optional) the object handling the logging.
  • apiVersion - (optional) the API version to use instead of the recommended one

The actions object has action names as properties, and action functions as values. Action implementations must return Promises (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) An implementation for the special action send is provided by default, if you don't provide your own in the actions object.


botSessionsDelegate - Object

A delegate to handle conversation context. To be an optional argument in the next versions, all you need is a BotSessionsDelegate instance, to compose the additional functionality.

This module class is a subclass of "Bot", so head over there to see all extended functionality that you may call on the WitMessengerBot class as well.

bot.runActions(sessionId, text, context, cb)

A higher-level method to the Wit converse API. runActions resets the last turn on new messages and errors.

Takes the following parameters:

  • sessionId - a unique identifier describing the user session
  • message - the text received from the user
  • context - the object representing the session state
  • cb - call back on completion

Returns a promise. You may handle promise rejections from your defined actions or chain other functionalty here by .thening your runActions call.

Context Functions

bot.findOrCreateSession(fbid)

bot.fbIdForSession(sessionId)

bot.writeSession(sessionId, sessionData)

bot.deleteSession(sessionId)

Wit.ai does its story magic by having a uniques session-id per ongoing conversation with its own context. The user in our session setup has 3 properties: facebookId, sessionId & sessionData (context). If you don't have complex stories, and your reply in each scenario depends on the latest message only, you may not need to use this at all. This is done on disk persistently and efficiently sans any api calls.

Example

#TODO