Skip to content

Instantly share code, notes, and snippets.

@lardissone
Created July 29, 2015 19:17
Show Gist options
  • Save lardissone/0ea9212be8b6f7c207cd to your computer and use it in GitHub Desktop.
Save lardissone/0ea9212be8b6f7c207cd to your computer and use it in GitHub Desktop.
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