I'm developing a telegram bot with the help of this API, and I tried to implement it with webhook method, first I tried my bot with getUpdated method and it works like a charm, but when I updated it to webhook, it doesn't seem to work.
I implemented webhook with flask, exactly following this example, except for the ssl certificate and IP, because I have an https domain, so instead of using IP and self signed certificate, I used my domain.
Then I tested my webhook with postman and sent requests with the data I got from api.telegram.org, and again it worked, but when I send a message to my bot in Telegram application, I get no message in the server, seems like telegram does not send the message as it is supposed to.
EDIT: Here I put my code for more clarification
WEBHOOK_HOST = 'mywebsite.com'
WEBHOOK_PORT = '8443'
WEBHOOK_LISTEN = '0.0.0.0'
WEBHOOK_SSL_CERT = "/etc/letsencrypt/live/mywebsite.com/cert.pem"
WEBHOOK_PRIV_CERT = "/etc/letsencrypt/live/mywebsite.com/privkey.pem"
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (TOKEN.get_token())
router = flask.Flask(__name__)
@router.route('/', methods=['GET', 'HEAD'])
def index():
return 'OK'
@router.route(WEBHOOK_URL_PATH, methods=['POST'])
def webhook():
if flask.request.headers.get('content-type') == 'application/json':
json_string = flask.request.json
print json_string["message"]["text"] # here I should get the text of message
return ''
else:
flask.abort(403)
bot.remove_webhook()
time.sleep(3)
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,certificate=open(WEBHOOK_SSL_CERT, 'r'))
router.run(host=WEBHOOK_LISTEN, port=int(WEBHOOK_PORT), ssl_context=(WEBHOOK_SSL_CERT, WEBHOOK_PRIV_CERT), debug=True)