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

dialog-api

v0.0.17

Published

A node.js client for the Dialog API.

Readme

Dialog Node

A node.js client for the Dialog API.

Dependency Status NPM Version

Examples

Installation

Install using npm.

npm install dialog-api --save

Usage

This library needs to be configured with your API token which is available in your personal account, and a bot ID.

var Dialog = require('dialog-api');
var dialog = new Dialog(request.env('DIALOG_API_TOKEN'), request.env('DIALOG_BOT_ID'));

Tracking messages

Generic

See docs.dialoganalytics.com/reference/track

var payload = {
  message: {
    platform: "messenger",
    provider: "dialog-node",
    mtype: "text",
    sent_at: 1484948110.458,
    nlp: {
      intents: [
        {
          name: 'rocket.launch',
          confidence: 0.98
        }
      ]
    },
    properties: {
      "text": "Launch some space rockets"
    }
  },
  conversation: {
    distinct_id: "0a4b6c44-55e0-4381-a678-34f02b2620d7"
  },
  creator: {
    distinct_id: "d5ae3f5f-1645-40c3-a38a-02382cd0ee49",
    type: "interlocutor",
    username: "@elon",
    first_name: "Elon",
    last_name: "Musk",
    email: "[email protected]",
    gender: "male",
    locale: "US",
    phone: "1234567890",
    profile_picture: "http://spacex.com/elon.jpg",
    timezone: -5
  }
};

dialog.track(payload);

Botpress

Example: Botpress bot with botpress-dialog

See botpress-dialog

Twilio Programmable Chat (IP Messaging) with Botkit

Example: Twilio Programmable Chat bot built with Botkit

var Dialog = require('dialog-api/lib/botkit/twilioipm');

controller.middleware.receive.use(dialog.incomingMiddleware);
controller.middleware.send.use(dialog.outgoingMiddleware);

Messenger with Botkit

Example: Messenger bot built with Botkit

var Dialog = require('dialog-api/lib/botkit/messenger');

controller.middleware.receive.use(dialog.incomingMiddleware);
controller.middleware.send.use(dialog.outgoingMiddleware);

Facebook Messenger with expressjs/express

Example: Messenger bot built with expressjs/express

var Dialog = require('dialog-api/lib/messenger');

var app = express();

// ...
app.post('/webhook', function(req, res) {
  dialog.incoming(req.body);

  var messagingEvents = req.body.entry[0].messaging;

  if (messagingEvents.length && messagingEvents[0].message) {
    var event = req.body.entry[0].messaging[0];

    var payload = {
      recipient: {
        id: event.sender.id
      },
      message: { text: 'Hey human!' }
    };

    var options = {
      url: 'https://graph.facebook.com/v2.6/me/messages',
      qs: { access_token: process.env.FACEBOOK_PAGE_ACCESS_TOKEN },
      method: 'POST',
      json: payload
    };

    request(options, function(error, response, body) {
      dialog.outgoing(payload, body);
    });
  }
})

Kik with @kikinteractive/kik

Example: Kik bot built with @kikinteractive/kik

var Dialog = require('dialog-api/lib/kik')

// ...
bot.use(function(message, next) {
  dialog.incomingMiddleware(message, next)
})

bot.outgoing(function(message, next) {
  dialog.outgoingMiddleware(message, next)
})

Events

Send events to Dialog to keep track of your custom logic. Optionally pass an Interlocutor's distinct id to tie the event to one of your bot's interlocutors. See docs.dialoganalytics.com/reference/event#create

dialog.event('subscribed', 'interlocutorDistinctId', { custom: 'value' })

Clicks

Record clicks by interlocutors inside a conversation using a trackable link. For every links that needs to be tracked, generate a trackable URL by passing the interlocutor's distinct Id (provided by the platform or provider) and the url to the link method. See docs.dialoganalytics.com/reference/click-tracking

dialog.link('http://example.com', interlocutorDistinctId)
// https://api.dialoganalytics.com/v1/b/7928374/clicks/?id=123456&url=http%3A%2F%2Fexample.com

Attach

Modify the current track payload about to be sent to Dialog's API with this helper method.

For example, you can specify a message name:

dialog.attach('welcome')
dialog.attach({ message: { name: 'welcome' }}) // equivalent

This will modify the track payload:

{
  message: {
    name: "welcome",
    ...
  },
  conversation: { ... },
  creator: { ... }
}

Messages

Retrieve a message

See docs.dialoganalytics.com/reference/message#retrieve

dialog.retrieveMessage(conversationId, messageId)

List all messages

List all messages in a conversation. See docs.dialoganalytics.com/reference/message#list

dialog.listMessages(conversationId)

Conversations

Retrieve a conversation

See docs.dialoganalytics.com/reference/conversation#retrieve

dialog.retrieveConversation(conversationId)

List all conversations

See docs.dialoganalytics.com/reference/conversation#list

dialog.listConversations()

Interlocutors

List all interlocutors

See docs.dialoganalytics.com/reference/interlocutor#list

dialog.listInterlocutors()

Retrieve an interlocutor

See docs.dialoganalytics.com/reference/interlocutor#retrieve

dialog.retrieveInterlocutor(interlocutorId)

Update an interlocutor

See docs.dialoganalytics.com/reference/interlocutor#update

dialog.updateInterlocutor(interlocutorId, params)

Creating an interlocutor

To create an interlocutor, use the track endpoint. An interlocutor must initially be created in association with a conversation. See docs.dialoganalytics.com/reference/track

Documentation

See the API docs.