node-tamtam-botapi
v0.3.0
Published
TamTam Bot API
Downloads
12
Maintainers
Readme
Node.js TamTam Bot API
Module to interact with official TamTam Bot API.
Install
npm install --save node-tamtam-botapi
Usage
const TamTamBot = require('node-tamtam-botapi');
const express = require('express');
const bodyParser = require('body-parser');
const appName = process.env.HEROKU_APP_NAME || 'HEROKU_APP_NAME';
const path = process.env.HEROKU_APP_PATH || 'HEROKU_APP_PATH';
const config = {
token: process.env.TOKEN,
host: process.env.HOST,
version: process.env.API_VERSION
};
const bot = new TamTamBot(config);
const app = express();
const PORT = process.env.PORT || 3000;
app.use(bodyParser.json());
const subscribeBody = {
url: `https://${appName}.herokuapp.com/${path}`
};
//Subscribes bot to receive updates via WebHook
bot.subscribe(subscribeBody);
// We are receiving updates at the route below!
app.post(`/${path}`, (req, res) => {
console.log('Request body: ', req.body);
bot.webhookUpdateTypeHandler(req.body);
res.send();
});
// Start Express Server
app.listen(PORT, () => {
console.log(`Express server is listening on ${PORT}`);
});
const message = {
text: 'Hello! this is a test message'
};
bot.on('message_created', update => {
bot.sendMessage(undefined, update.message.recipient.chat_id, message);
});
License
The MIT License (MIT)
Copyright © 2020 vershininivan