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-chat-api-buttons

v1.1.2

Published

An extension for facebook-chat-api, which provides slightly better UX for your chat bot by adding buttons.

Downloads

17

Readme

Travis NPM

An extension for facebook-chat-api, which provides slightly better UX for your chat bot by adding buttons.

The Problem

Current use of facebook chat bots, works by sending a text command. Unfortunately it's not enough intuitive. The workaround are buttons, which help with some UX problems.

How it works

After sending an url, facebook gets informations about website by searching meta tags. These meta tags are a way to express what a given website is about. This is called prefetching. For example, if you send an url to website, which looks like this:

<!DOCTYPE html>
<html>
  <head>
    <meta property="title" content="Your title" />
    <meta property="description" content="Your description" />
  </head>
  <body></body>
</html>

You will get this card. As you see, it has title and description. Chat Buttons handles these meta informations which goes to facebook and handles if button has been clicked.

Installing

NOTE: To use buttons, you will need to have a public server.

To install Chat Buttons, run in terminal:

$ npm install fb-chat-api-buttons

Quick start

const express = require("express");
const login = require("facebook-chat-api");
const { ChatButtons } = require("fb-chat-api-buttons");

let botCredentials = { email: "email", password: "password" };

const app = new express();
const buttons = new ChatButtons({
  app: app,
  endpoint: "http://www.example.com:3000/callback"
});

login(botCredentials, (err, api) => {
  buttons.setApi(api);

  api.listen((err, message) => {
    if (message.body === "test") {
      buttons.send(
        {
          id: "hello-there",
          title: "I'm a button",
          description: "Click to get a message.",
          onClick: (btn, threadID) => {
            api.sendMessage({ body: "Hello there!" }, threadID);
          }
        },
        message.threadID
      );
    }
  });
});

app.listen(3000, () => {
  console.log("Listening on 3000!");
});

Documentation

Class ChatButtons

new ChatButtons(options: IOptions)

Example:

const app = new express();
const buttons = new ChatButtons({
  app: app,
  endpoint: "http://www.example.com:3000/callback"
});

ChatButtons.setApi

Arguments:

  • api: any

Example:

login(botCredentials, (err, api) => {
  buttons.setApi(api);
});

ChatButtons.send

Arguments:

  • btn: IButton
  • threadID: string

Example:

buttons.send(
  {
    id: "btn-id",
    title: "Title",
    description: "Description",
    onClick: (btn, id) => {
      api.sendMessage({ body: "Hello world!" }, id);
    }
  },
  threadID
);

IOptions

interface {
  app: Application; // Express application
  path?: string;
  endpoint: string;
  api?: any;
}

IButton

interface {
  id?: string;
  metadata?: any;
  title: string;
  description?: string;
  image?: string;
  onClick?: IButtonCallback;
}