Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Framework allowing developers to write bots that are agnostic with respect to the channel used by their users (messenger, telegram etc...)
Botmaster is an opinionated lightweight chatbot framework. Botmaster is platform agnostic, which means that in its current state, developers can have bots running on Facebook Messenger, Twitter DM and Telegram with just one integration.
Its purpose is to minimise the amount of code developers have to write in order to create a 1-on-1 conversational chatbot that works on multiple different platforms. It does so by defining a standard with respect to what format messages take and how 1-on-1 conversations occur.
npm install --save botmaster
// settings stuff
const Botmaster = require('botmaster');
const config = require('./tests/config.js')
const messengerSettings = {
credentials: {
verifyToken: 'YOUR verifyToken',
pageToken: 'YOUR pageToken',
fbAppSecret: 'YOUR fbAppSecret'
},
webhookEndpoint: '/webhook1234', // botmaster will mount this webhook on https://Your_Domain_Name/messenger/webhook1234
};
const twitterSettings = {
consumerKey: 'YOUR consumerKey',
consumerSecret: 'YOUR consumerSecret',
accessToken: 'YOUR accessToken',
accessTokenSecret: 'YOUR accessTokenSecret',
}
}
const botsSettings = [{ messenger: messengerSettings },
{ twitter: twitterSettings }];
const botmasterSettings = {
botsSettings: botsSettings,
// by default botmaster will start an express server that listens on port 3000
// you can pass in a port argument here to change this default setting:
port: 3001
}
const botmaster = new Botmaster(settings);
// actual code
botmaster.on('update', (bot, update) => {
bot.sendMessage({
recipient: {
id: update.sender.id,
},
message: {
text: 'Right back at you!', // yes, this bot doesn't really do anything smart
},
});
});
botmaster.on('error', (bot, err) => {
console.log(err.stack);
console.log('there was an error');
});
As you can see here, the Botmaster constructor takes a botmasterSettings argument. This object is of the following form:
botmasterSettings = {
botsSettings: botsSettings, // see below for a definition of botsSettings
app: app, // optional, an express app object if you are running your own server
port: port, // optional, only used if "app" is not defined. Defaults t0 3000 in that case
sessionStore: sessionStore // optional. Define if you will be dealing with sessions
}
botsSettings look something like what you saw in the quick start example:
const botsSettings = [{ messenger: messengerSettings },
{ twitter: twitterSettings },
{ twitter: otherTwitterSettings }];
I.e. it is an array of single key objects. Where you specify the type as the key of each object and the settings is is the value. Here I show that you can define multiple bots of the same type at once (twitter ones in this example). As you surely guessed, each different platform will expect different credentials. So platform specific settings will differ.
We've seen a messenger settings object looks like:
const messengerSettings = { credentials: { verifyToken: 'YOUR verifyToken', pageToken: 'YOUR pageToken', fbAppSecret: 'YOUR fbAppSecret' }, webhookEndpoint: '/webhook1234' };
If you don't already have these, follow the steps 1-4 on the Facebook Messenger guide: https://developers.facebook.com/docs/messenger-platform/quickstart
In step 2, where you setup your webhook, no need to code anything. Just specify the webhook, enter any secure string you want as a verify token and copy that value in the settings object.
If you are not too sure how webhooks work and/or how to get it to run locally, go to the section about webhooks.
https://core.telegram.org/bots for an intro. https://core.telegram.org/bots/api for all the doc.
We've also seen a twitter settings object looks like:
const twitterSettings = { consumerKey: 'YOUR consumerKey', consumerSecret: 'YOUR consumerSecret', accessToken: 'YOUR accessToken', accessTokenSecret: 'YOUR accessTokenSecret', } }
Twitter setup is slightly more cumbersome than the two other ones. Because in Twitter you have to create an actual account and not a page or a bot, you'll have to do a few more steps.
Setting up the bot account
Setting up the app
Standardization is at the heart of Botmaster. The framework was really created for that purpose. This means that messages coming from any platform have to have the same format.
In order to do that, the Facebook Messenger message format was chosen and adopted. This means that when your botmaster object receives an 'update' event from anywhere (twitter, telegram or Messenger as of this writing), you can be sure that it will be of the same format as a similar message that would come from Messenger.
Typically, it would look something like this for a message with an image attachment. Independant of what platform the message comes from:
{
raw: <platform_specific_raw_update>,
sender: {
id: <id_of_sender>
},
recipient: {
id: <id_of_the_recipent> // will typically be the bot's id
},
timestamp: <unix_miliseconds_timestamp>,
message: {
mid: <message_id>,
seq: <message_sequence_id>,
attachments: [
{
type: 'image',
payload: {
url: 'https://scontent.xx.fbcdn.net/v/.....'
}
}
]
}
};
This allows developers to handle these messages in on place only rather than doing it in multiple ones.
...
...
Simply install localtunnel on local machine
npm install -g localtunnel
Then run the localtunnel with a predetermined subdomain. e.g:
lt -p 3000 -s botmastersubdomain //for example
-l is for the localhost we want to point to. -p is the port and -s is the subdomain we want. In this case, your url will be: http://botmastersubdomain.localtunnel.me.
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:
https://botmastersubdomain.localtunnel.me/messenger/webhook1234/ (localtunnel provides both an http and https url. But messenger requires an https one)
Here's an example on how to do so:
const express = require('express');
const app = express();
const port = 3000;
const Botmaster = require('botmaster');
const telegramSettings = {
credentials: {
authToken: process.env.TELEGRAM_TEST_TOKEN,
},
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 botmasterSettings = {
botsSettings: botsSettings,
app: app,
}
const botmaster = new Botmaster(botmasterSettings);
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}`);
});
Checkout the examples folder for cool examples of how to use botmaster
FAQs
Framework allowing developers to write bots that are agnostic with respect to the channel used by their users (messenger, telegram etc...)
The npm package botmaster receives a total of 103 weekly downloads. As such, botmaster popularity was classified as not popular.
We found that botmaster demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.