Skip to content

Instantly share code, notes, and snippets.

@jirojo2
Created August 6, 2015 16:33
Show Gist options
  • Save jirojo2/f9809ff53d16b7ad2f8d to your computer and use it in GitHub Desktop.
Save jirojo2/f9809ff53d16b7ad2f8d to your computer and use it in GitHub Desktop.
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