node.js - Why telegram does not send message to webhook? -
using node-telegram-bot-api on vps, i'm trying message telegram channel.
here 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 bot!"}); });
when link browser:
https://telegram.me/myexamplebot?start=abcd
i expect bot receive message channel containing abcd
when user clicks on start
button, receive nothing in bot's console. problem occured when added bot.setwebhook
code. without that, receive message whenever user typed in channel.
my code following the example here have no idea wrong it. appreciate hints.
i had same problem. telegram didn't send bot...
because of incorrect certificate. generate cert according this: https://core.telegram.org/bots/self-signed
just replace "yourdomain.example" valid value. used ip, after works.
additionaly can see debug info node-telegram-bot-api understand happening:
npm install debug
debug=node-telegram-bot-api node bot.js
it produce debug output you.
hope helps.
Comments
Post a Comment