Reputation: 105
Using node-telegram-bot-api on my VPS, I'm trying to get message from a telegram channel.
Here is the code:
var TelegramBot = require ( 'node-telegram-bot-api');
var token = '1793xxxxxxxxxxxxxxxxxxxxx';
var __dirname ='/etc/nginx/ssl'
var options = {
webHook: {
port: 443,
key: __dirname+'/key.pem',
cert: __dirname+'/crt.pem'
}
};
var bot = new TelegramBot(token, options);
bot.setWebHook('1.3.4.5:443/bot1793xxxxxxxxxxxxxxxxxxxxx', __dirname+'/crt.pem');
bot.on ( 'message', function (msg) {
var chatId = msg.chat.id;
console.log (msg);
bot.sendMessage (chatId, "Hello!", {caption: "I'm a bot!"});
});
When I get this link the browser:
https://telegram.me/MyExampleBot?start=abcd
I expect the bot to receive a message from the channel containing abcd
when user clicks on start
button, but I receive nothing in the bot's console.
The problem occured when I added bot.setWebHook
to the code. Without that, I could receive a message whenever user typed something in the channel.
My code is following the the example here so I really have no idea what is wrong with it. Really appreciate your hints.
Upvotes: 1
Views: 2440
Reputation: 51
I had the same problem. Telegram didn't send anything to my bot...
Because of incorrect certificate. Generate your cert according to this: https://core.telegram.org/bots/self-signed
just replace "YOURDOMAIN.EXAMPLE" with valid for you value. I used just my IP, after that it works.
Additionaly you can see debug info from node-telegram-bot-api to understand what happening:
npm install debug
DEBUG=node-telegram-bot-api node bot.js
It will produce debug output for you.
Hope it helps.
Upvotes: 3