Skip to content

Instantly share code, notes, and snippets.

@k4ml
Last active July 12, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4ml/da3c411a3c37f3ef35c6a61e88a4c60f to your computer and use it in GitHub Desktop.
Save k4ml/da3c411a3c37f3ef35c6a61e88a4c60f to your computer and use it in GitHub Desktop.
module['exports'] = function chat (hook) {
var TelegramBot = require('node-telegram-bot-api');
var token = hook.env['TG_TOKEN'];
// Setup polling way
var bot = new TelegramBot(token);
bot.setWebHook('https://hook.io/k4ml/infomy')
// Matches /echo [whatever]
bot.onText(/\/echo (.+)/, function (msg, match) {
var fromId = msg.from.id;
var resp = match[1];
bot.sendMessage(fromId, resp);
});
// Any kind of message
bot.on('message', function (msg) {
var chatId = msg.chat.id;
// photo can be: a file path, a stream or a Telegram file_id
var photo = 'cats.png';
bot.sendPhoto(chatId, photo, {caption: 'Lovely kittens'});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment