Last active
July 12, 2016 15:31
-
-
Save k4ml/da3c411a3c37f3ef35c6a61e88a4c60f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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