Skip to content
Max Stepanov edited this page Jun 28, 2015 · 1 revision

Simple Echo Bot can be written as easy as the following:

var telegram = require('telegram-bot-api');
var api = new telegram({
	token: '<YOUR TOKEN HERE>',
	updates: {
		enabled: true,
		get_interval: 1000
	}
});

api.on('message', function(message)
{
	var chat_id = message.chat.id;

	api.sendMessage({
		chat_id: message.chat.id,
		text: message.text ? message.text : 'This message doesn\'t contain text :('
	}, function(err, message)
	{
		console.log(err);
		console.log(message);
	});
});

Please note, that message.text is optional, as message may be photo or video object. It may be good idea to check object type and react accordingly.

Clone this wiki locally