Professional Documents
Culture Documents
By:
Bala Srinyvas R P IV ECE
Bharath N IV ECE
AGENDA?
Hosting Bot.
Quick Recap?
What is a chat-bot?
Ways to link a Chat-bot?
Software’s Needed?
https://telegraf.js.org/#/
Example
const { Telegraf } = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on('sticker', (ctx) => ctx.reply('👍'))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
bot.launch()
BOT TOKEN
To access all functionalities of telegram BOT API.
Eg.123456789:AbCdfGhIJKlmNoQQRsTUVwxyZ
BOT Father
NOTE:
Secure Information
process.env.BOT_TOKEN
MIDDLEWARE
Modify requests and responses.
Eg= ctx,next
Accessing DB-Data
<img src="https://quickchart.io/chart?
c={type:'pie',data:{labels:
['January','February',
'March','April', 'May'], datasets:
[{data:[50,60,70,180,190]}]}}">
SCHEDULING MESSAGES
var schedule = require('node-schedule');
var date = new Date(2020, 07, 12, 5, 30, 0);
var j = schedule.scheduleJob(date, function(){
console.log(‘Gold Price:50,880.00‘);
});
j.cancel();
COVID-19 BOT CREATION
NOTE:
Installing Packages
npm init -y
Create index.js
BOT-Father
Code Explanation
require('dotenv').config()
const Telegraf=require('telegraf')
const Markup=require('telegraf/markup')
const {inlineHandler}=require("./js/inlineHandler.js")
const rp = require('request-promise');
const Extra=require('telegraf/extra')
Part-2
bot.start(ctx=>{
try{
const requestOptions = {
method: 'PUT',
uri: 'https://api.backendless.com/C7C46BF0-D887-EE41-FFCC-C473E8648400/9579C9DB-155C-4D21-A30D-
39190ED05E67/counters/id1/increment/get',
headers: {
'Content-Type': 'application/json'
},
json: true,
};
rp(requestOptions).then(response => {
console.log('API call response:', response);
}).catch((err) => {
console.log('API call error:', err.message);
});
}catch(e)
{}
ctx.reply(`Hello ${ctx.from.first_name} , Welcome to the fastest COVID-19 Tracker Bot . For more details \nRefer /help`)
})
Part 3
bot.help(ctx=>
{
ctx.reply('Here is the complete walk-through about the Bot.\
<b><u>\n\nCommands:</u></b>\n\n\
/start\nWelcome to the Bot !!!\n\n\
/total\nDisplays the live count of COVID-19 cases in India.\n\n\
/statewise\nList of COVID cases of all states in India.\n\n\
/country\nShows the COVID cases in the specified country.\n\n\
/state\nList of COVID cases in particular state.\n\n\
/district\nCount of identified Cases in specific district.\n\n\
/help\nView all available Commands.\n\n\
/about\nInformation about the bot',Extra.HTML())
}
)
Part 4
bot.command('country',ctx=>ctx.reply('Enter the Country name for which the count is
needed :'))
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/abcd/TEST.git
git push -u origin master
COVID-19 GITHUB LINK
https://github.com/balasrinyvasrp/COVIDbot.git
BOT_TOKEN=10002:balarpXXXX47695
For Any Further Queries ,Please Feel free to Contact Us!!!