mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-09-01 14:55:14 +00:00
First commit
This commit is contained in:
36
examples/polling.js
Normal file
36
examples/polling.js
Normal file
@@ -0,0 +1,36 @@
|
||||
var TelegramBot = require('../src/telegram');
|
||||
var request = require('request');
|
||||
|
||||
var options = {
|
||||
polling: true
|
||||
};
|
||||
|
||||
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
|
||||
|
||||
var bot = new TelegramBot(token, options);
|
||||
bot.getMe().then(function (me) {
|
||||
console.log('Hi my name is %s!', me.username);
|
||||
});
|
||||
bot.on('message', function (msg) {
|
||||
var chatId = msg.chat.id;
|
||||
if (msg.text == '/photo') {
|
||||
// From file
|
||||
var photo = __dirname+'/../test/bot.gif';
|
||||
bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"});
|
||||
}
|
||||
if (msg.text == '/audio') {
|
||||
var url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg';
|
||||
// From HTTP request!
|
||||
var audio = request(url);
|
||||
bot.sendAudio(chatId, audio)
|
||||
.then(function (resp) {
|
||||
// Forward the msg
|
||||
var messageId = resp.message_id;
|
||||
bot.forwardMessage(chatId, chatId, messageId);
|
||||
});
|
||||
}
|
||||
if (msg.text == '/help') {
|
||||
var opts = {reply_to_message_id: msg.message_id};
|
||||
bot.sendMessage(chatId, 'This is only a test :D', opts);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user