Created
July 29, 2015 19:17
-
-
Save lardissone/0ea9212be8b6f7c207cd 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
var request = require('request'); | |
var token = 'your:token-here', | |
baseUrl = 'https://api.telegram.org/bot' + token + '/'; | |
module.exports = function(context, cb) { | |
var command = context.data.message.text; | |
var chat = context.data.message.chat.id; | |
// intercept command /hello | |
if (command.lastIndexOf('/hello', 0) === 0) { | |
// response message | |
sendMessage(chat, 'world!'); | |
// not required but... | |
cb(null, {status: 'ok'}); | |
} | |
}; | |
var sendMessage = function(chatId, message) { | |
request.post( | |
baseUrl + 'sendMessage', | |
{ | |
form: { | |
'chat_id': chatId, | |
'text': message | |
} | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment