Skip to content

kakalan123/botimize-sdk-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

botimize - Analytics built to optimize your bots

build status npm version

Setup

  • Create a free account at botimize to get an API key.

  • Install botimize SDK with npm:

    npm install --save botimize

Usage

Initialization

Use API key to create a new botimize object

  • Facebook:

    const botimize = require('botimize')('<YOUR-API-KEY'>, 'facebook');
  • Generic Logging:

    const botimize = require('botimize')('<YOUR-API-KEY'>, 'generic');

Log incoming messages:

  • Facebook

    app.post('/webhook', function (req, res)) {
      botimize.logIncoming(req.body);
      ...
    }
  • Generic

    app.post('/webhook', function (req, res)) {
      const incomingLog = {
        sender: {
          id: 'UNIQUE_USER_ID',
          name: 'USER_SCREEN_NAME'
        },
        content: {
          type: 'CONTENT_TYPE', // 'text', 'image', 'audio', 'video', 'file', 'location'
          text: 'CONTENT_TEXT'
        }
      };
      botimize.logIncoming(incomingLog);
      ...
    }

Log outgoing messages

  • Facebook

    const options = {
      uri: 'https://graph.facebook.com/v2.6/me/messages',
      qs: { access_token: PAGE_ACCESS_TOKEN },
      method: 'POST',
      json: messageData
    };
    request(options, function (error, response, body) {
      botimize.logOutgoing(options);
      ...
    });
  • Generic

      const outgoingLog = {
        receiver: {
          id: 'UNIQUE_USER_ID',
          name: 'USER_SCREEN_NAME'
        },
        content: {
          type: 'CONTENT_TYPE', // 'text', 'image', 'audio', 'video', 'file', 'location'
          text: 'CONTENT_TEXT'
        }
      };
    request(options, function (error, response, body) {
      botimize.logOutgoing(outgoingLog);
      ...
    });

Send notifications via email:

const data = {
  to: '<recipient-email>',
  text: '<text-content-to-be-sent>'
};
botimize.notify(data, 'email');

Send notifications via Slack:

const data = {
  to: '<incoming-webhook-url>',
  text: '<text-content-to-be-sent>'
};
botimize.notify(data, 'slack');

data can have all properties supported by Slack incoming webhook, e.g., channel, username, icon_emoji, attachments, etc.

About

🤖 Node.js SDK for botimize.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%