node-tamtam-botapi

0.3.0 • Public • Published

Node.js TamTam Bot API

Bot API Build Status FOSSA Status codecov NPM version NPM download

TamTam channel

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

Dependencies (6)

Dev Dependencies (4)

Package Sidebar

Install

npm i node-tamtam-botapi

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

48.3 kB

Total Files

9

Last publish

Collaborators

  • vershininivan