Skip to content

Instantly share code, notes, and snippets.

@tcrowe tcrowe/telegram-bot.js
Last active Nov 17, 2018

What would you like to do?
start up a new telegram bot using nodejs
# the basic echo bot
+ Pops up the docs in the browser
+ npm docs node-telegram-bot-api
+ Install the bot module
+ npm install node-telegram-bot-api
+ Dump in this code into a JS file like ./index.js
+ Send a message to @botfather and get a token
+ Set the token below
+ Run it!
+ node index.js
+ Add your bot as an admin on your chat room
+ :shipit:
const TelegramBot = require("node-telegram-bot-api")
// ⚠️set your code here you got from @botfather
const botToken = "bbbbbbbbbb"
const botOpts = {polling: true}
const bot = new TelegramBot(botToken, botOpts)
bot.on("message", msg => {
const {message_id, date, chat, text} = msg
let chatId
if (chat !== undefined) {
chatId =
console.log("chatId", chatId)
console.log("message_id", message_id)
console.log("date", date)
console.log("text", text)
// echo
bot.sendMessage(chatId, text);
bot.on("error", err => {
console.error("bot error", err)

This comment has been minimized.

Copy link
Owner Author

tcrowe commented Nov 17, 2018

Ping me back here if you :shipit: 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.