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

chatbottle-api-nodejs

v2.0.0

Published

ChatBottle API client for Node.js

Downloads

7

Readme

ChatBottle API for Node.js

ChatBottle is an engagement platform for your chatbots. ChatBottle allows to send personalized notifications to segmented groups of users.

The following platforms are currently supported via the npm package:

Setup Bot

Create a free account at https://chatbottle.co/ and get a ChatBottle token.

chatbottle is available via NPM.

npm install --save chatbottle-api-nodejs

Include chatbottle and create instance for each platform (if you have mor than one).

const chatbottleMessenger = require('./chatbottle')(process.env.CHATBOTTLE_API_TOKEN_MESSENGER, { platform: 'messenger' });
const chatbottleLine = require('./chatbottle')(process.env.CHATBOTTLE_API_TOKEN_LINE, { platform: 'line' });
...

You can enable debugging in the second parameter config if you have problems.

//@param config object {
//    platform => messenger, telegram,
//    debug => see every outgoing data,
//    debugRequest => to set the request-promise library to debug
//  }
const chatbottleMessenger = require('./chatbottle')(process.env.CHATBOTTLE_API_TOKEN_MESSENGER, { platform: 'messenger', debug: true, debugRequest: true });

Then log whenever your webhook is called.

Logging

Messenger

Facebook Messenger is directly supported to send the req.body directly to chatbottle if you enable the following events for your webhook:

https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-echo https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-delivered https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-received https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-read

app.post(webHookPath, function (req, res) {
    chatbottleMessenger.log(req.body);
    const messagingEvents = req.body.entry[0].messaging;
    if (messagingEvents.length && messagingEvents[0].message && messagingEvents[0].message.text) {
        const event = req.body.entry[0].messaging[0];
        const sender = event.sender.id;
        const text = event.message.text;
        const requestData = {
            url: 'https://graph.facebook.com/v2.6/me/messages',
            qs: { access_token: process.env.FACEBOOK_PAGE_TOKEN },
            method: 'POST',
            json: {
                recipient: { id: sender },
                message: {
                    text: 'ECHO: ' + text
                }
            }
        };
        request(requestData);
    }
    res.sendStatus(200);
});

Generic (Kik, Viber, Line, ...)

For generic bot platforms you have hook in every receiving and sending message.

// incoming
// lets say the incoming message is `event` (for Line Bot)
chatbottleLine.log({
    id: event.message ? event.message.id : event.timestamp,
    text: event.message.text,
    userId: event.source.userId,
    direction: 'In',
});

// outgoing
// you can listen on every outgoing request with monkey-patching (see below) ;)
chatbottleLine.log({
    id: new Date().getTime(),
    text: message, // if you have rich content, you can build your message on your own and JSON.stringify() it
    userId: to,
    direction: 'Out',
});

Monkey-patching: Track outgoing HTTP(s) requests in NodeJS by @phips28

https://chatbotsmagazine.com/track-outgoing-http-s-requests-in-nodejs-48608553f03c#.mz675gyuf

That is it!

For a complete example see: facebook-example.js

Register on ChatBottle: https://chatbottle.co/