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

botmaster

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

botmaster - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

25

lib/bot_types/messenger_bot.js

@@ -38,2 +38,3 @@ 'use strict';

});
// this.app.use(bodyParser.json());
this.app.use(bodyParser.json({ verify: this.__verifyRequestSignature }));

@@ -51,6 +52,11 @@ this.app.use(bodyParser.urlencoded({ extended: true }));

this.app.post(this.webhookEndpoint, (req, res) => {
const entries = req.body.entry;
this.__emitUpdatesFromEntries(entries);
res.sendStatus(200);
if (req[req.fbAppSecret] !== false) {
const entries = req.body.entry;
this.__emitUpdatesFromEntries(entries);
res.sendStatus(200);
} else {
// these are actual errors. But returning a 200 nontheless
// just in case errors come from messenger somehow
res.status(200).json(res.body);
}
});

@@ -70,5 +76,7 @@ }

const signature = req.headers['x-hub-signature'];
if (!signature) {
res.status(400).send('Error, signature missing from request');
req[req.fbAppSecret] = false;
res.body = {
error: 'Error, wrong signature',
};
} else {

@@ -82,3 +90,6 @@ const signatureHash = signature.split('=')[1];

if (signatureHash !== expectedHash) {
res.status(400).send('Error, wrong signature');
req[req.fbAppSecret] = false;
res.body = {
error: 'Error, wrong signature',
};
}

@@ -85,0 +96,0 @@ }

{
"name": "botmaster",
"version": "0.1.0",
"version": "0.1.1",
"description": "Framework allowing developers to write bots that are agnostic with respect to the channel used by their users (messenger, telegram etc...)",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -6,17 +6,81 @@ Bot framework

## Then just:
## hot so use botmaster
```js
const botmaster = new Botmaster(botsSettings, app);
```bash
npm install
npm start
botmaster.on('update', (bot, update) => {
bot.sendMessage({
recipient: {
id: update.sender.id,
},
message: {
text: 'Well right back at you!',
},
});
});
```
As you can see here, the Botmaster constructor takes two arguments, botsSettings and app. Here is a full example with the arguments set for a simple bot
## how to use (speaking with both a telegram and a messenger bot)
```js
const express = require('express');
const app = express();
const port = 3000;
const Botmaster = require('botmaster');
const telegramSettings = {
credentials: {
authToken: process.env.TELEGRAM_TEST_TOKEN,
},
// !! botmaster will mount your webhooks on /<botType>/webhookEndpoint.
// so in this case, it will mount it on: /telegram/webhook1234.
// If using localtunnel as specified below the whole path will be:
// https://botmastersubdomain.localtunnel.me/telegram/webhook1234/
webhookEndpoint: '/webhook1234/',
};
const messengerSettings = {
credentials: {
verifyToken: process.env.MESSENGER_VERIFY_TOKEN,
pageToken: process.env.MESSENGER_PAGE_TOKEN,
fbAppSecret: process.env.FACEBOOK_APP_SECRET,
},
webhookEndpoint: '/webhook1234/',
};
const botsSettings = [{ telegram: telegramSettings },
{ messenger: messengerSettings }];
const botmaster = new Botmaster(botsSettings, app);
botmaster.on('update', (bot, update) => {
bot.sendMessage({
recipient: {
id: update.sender.id,
},
message: {
text: 'Well right back at you!',
},
});
});
console.log(`Loading App`);
// start server on the specified port and binding host
app.listen(port, '0.0.0.0', () => {
// print a message when the server starts listening
console.log(`Running App on port: ${port}`);
});
```
See the examples folder for examples on how to use botmaster
## You will need to set up the a bot on telegram. See this page:
https://core.telegram.org/bots for an intro;
https://core.telegram.org/bots/api for all the doc.
Then edit your telegramKey in api_integrations/telegram_api_integration.
## For the facebook Messenger bot, follow this guide to set up the bot:
https://developers.facebook.com/docs/messenger-platform/quickstart
Then edit the verifyToken and pageToken in api_integrations/facebook_messenger_api_integration.

@@ -41,5 +105,5 @@

So if you specified messenger's webhook endpoint to, say, /messenger/webhook1234/, you will have to
set up the webhook for your demo app at:
So if you specified messenger's webhook endpoint to, say, /messenger/webhook1234/, you will have to set up the webhook for your demo app at:
http://botmastersubdomain.localtunnel.me/messenger/webhook1234/
https://botmastersubdomain.localtunnel.me/messenger/webhook1234/
(localtunnel provides both an http and https url. But messenger requires an https one)

@@ -227,3 +227,6 @@ 'use strict'

request(options);
request(options)
.then(function(body) {
console.log(body);
})
});

@@ -230,0 +233,0 @@

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