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

fb-local-chat-bot

v0.1.42

Published

A ES6 Node client for Messenger Bot designed for easy local testing

Downloads

4

Readme

fb-local-chat-bot

Testing your Messenger Bot apps is a pain in the ass - you need to setup ngrok to tunnel to your server (what happens when multiple people work on it?) and writing unit tests are not intuitive.

fb-local-chat-bot is

  • a standard library that handles the boilerplate logic to connect with FB APIs
  • a local web client to debug the app (see screenshot)
  • a set of intuitive APIs for unit testing on messenger bot

Demo

Install

npm install fb-local-chat-bot

Code Snippet

Initialize

// app.js
// if useMessenger is false, the plugin will not make graphAPI calls to facebook
// if useLocalChat is true, the plugin will initialize the local chat view.
Bot.init(
  config.FBChatToken || '',
  'SETUP_PLAY_GO_THIS_IS_RIGHT',
  false, // useMessenger
  config.useFBChatLocalTest || false,
);

Bot.on('text', async (event: object) => {
  // do something
});

Bot.on('attachments', async (event: object) => {
  // do something
});

Bot.on('postback', async (event: object) => {
  // do something
});

app.use('/webhook', Bot.router());
// go to http://localhost:5000/webhook/localChat/ for local chat debugging

Send APIs

// generic send API
Bot.send(userID, messageData);

// send text
Bot.sendText(userID, "Yo what's up how you doin");

// send image
Bot.sendImage(userID, imageURL);

// send buttons
Bot.sendButtons(
  userID,
  'Some text',
  [
    Bot.createPostbackButton(
      'button 1',
      'BUTTON_TYPE_1',
    ),
    Bot.createPostbackButton(
      'button 2',
      'BUTTON_TYPE_2',
    ),
  ]
);
// Other APIs (see src/index.js for detail)
// Bot.sendVideo
// Bot.sendFile
// Bot.sendAudio
// Bot.sendGenericTemplate
// Bot.sendListTemplate
// Bot.sendQuickReplyWithAttachment
// Bot.sendQuickReplyWithText

Testing APIs

// example using mocha
describe('Basic server test', function() {
  this.timeout(1000);
  var server;
  var userID = 'testUser';
  beforeEach(mochaAsync(async () => {
    server = await makeServer(true /* silent */);
  }));

  afterEach(function (done) {
    Bot.clearLocalChatMessages();
    Bot.removeAllListeners();
    server.close(done);
  });

  it('Test help', mochaAsync(async () => {
    await ResponseHandler.handleText(userID, "help");

    let messages = Bot.getLocalChatMessagesForUser(userID);
    expect(messages.length).to.equal(2);
  }));
});

History

  • 0.1.4
    • Add persistent menu support
    • Add sender action
  • 0.1.3
    • Add general template hscroll
  • 0.1.0
    • Add useMessenger param
    • Add QuickReply, ListTemplate, GenericTemplate and various buttons
    • Add profile fetching API