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

ms-directline-client-node

v1.1.1

Published

Slim HTTP polling MS Directline v3 Client

Readme

ms-directline-client-node

MS Directline v3 Node.js API implementation

Official Microsoft API reference

Introduction

This is a work in progress simple MS Directline V3 API REST/WS Client.

Please note, it just provides a simple wrapper to the MS API, any error will simply be wrapped with an internal error code and forwarded to the error event listener or thrown if possible. FOr more information please see the index.js file.

Events

const EVENTS = {
  ERROR: 'error', // error event
  ACTIVITIES: 'activities', // receive activities
  WS_CLOSED: 'wsClosed' // handle socket closed
};

// exposed via
Conversation.EVENTS;

Config

const defaultConfig = {
  polling: false, // disable polling per default
  autoReconnect: true // reconnect ws connection on default
};

Error codes

const ERROR_CODES = {
  wsParsingFailed: 'ws-parsing-failed', // parsing of data received via ws failed
  wsError: 'ws-error', // general ws connection error
  wsReconnectErr: 'reconnect-error', // recreating a new ws stream and reconnecting failed
  pollingError: 'polling-error', // failed polling via HTTP GET
  refreshError: 'token-refresh-error', // failed to refresh token
  creationFailed: 'creationFailed' // failed to create object, mostly because conversation call failed
};

// exposed via
Conversation.ERROR_CODES;

Example

require('dotenv').config({ path: `${__dirname}/../.env` });
const Conversation = require('./index');

const delay = ms => {
  return new Promise(resolve => setTimeout(resolve, ms));
};
(async () => {
  try {
    const conversation = await Conversation.start({
      userId: 'test',
      msDirectLineEndpoint: process.env.MS_DIRECTLINE_DOMAIN,
      msDirectLineSecret: process.env.MS_DIRECTLINE_SECRET
    });

    // handle error
    conversation.on('error', console.log);

    await conversation.sendMessage('hi');
    await delay(5000);

    // await response and get activities, usually it takes around 300/500 ms
    // https://docs.microsoft.com/de-de/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-receive-activities?view=azure-bot-service-4.0#timing-considerations
    conversation.getForeignActivities().forEach(activity => {
      if (activity.from.id !== conversation.getUserId()) {
        console.log('found bot response', JSON.stringify(activity));
      }
    });

    // or bind on the activities event and receive them in arrays
    conversation.on(Conversation.EVENTS.ACTIVITIES, activities => {
      // get only foreign ones, note that you can also get them here via the get getForeignActivities method,
      // however it possible that the storage in the conversation already has newer activities stored because of the background polling

      console.log('event activities', activities);
      console.log(
        'conversation cache activities',
        conversation.getActivities()
      );
    });
    await conversation.sendMessage('escalate');
    await delay(2000);
    await conversation.sendMessage('hi');
    await conversation.endConversation(false);
    await delay(1000);
    await conversation.cleanup();
  } catch (err) {
    console.log(err);
  }
})();

Todos

  • add full test coverage
  • add api documentation in README.MD