Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chatbottle-api-nodejs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatbottle-api-nodejs

ChatBottle API client for Node.js

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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/

Keywords

FAQs

Package last updated on 19 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc