Skip to content

Instantly share code, notes, and snippets.

@jirojo2 jirojo2/bot.js
Created Aug 6, 2015

Embed
What would you like to do?
Telegram Bot: testing echo! Node.js
var telegram = require('telegram-bot-api');
var util = require('util');
function Bot(token) {
this.id = null;
this.name = null;
this.username = null;
var self = this;
var api = this.api = new telegram({
token: token,
updates: {
enabled: true,
get_interval: 1000
}
});
api.getMe(function(err, data)
{
if (err) {
throw util.format("ERROR initializing bot: %s", err);
}
console.log("Initialized bot %s [%d] @%s", data.first_name, data.id, data.username);
});
api.on('message', function handleMessage(msg) {
// echo
api.sendMessage({
chat_id: msg.chat.id,
text: msg.text ? util.format("@%s %s", msg.from.username || '', msg.text) : "meh"
}, function handleMessageCallback(err, generatedMessage) {
if (err) {
console.log("ERROR handling message: %j %j", err, msg);
}
})
});
}
var bot = new Bot('<token>');
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.