Skip to content

vershininivan/node-tamtam-botapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published