Forums

problem in setting webhook on server

i am trying to run telegram bot via webhook. My python and flask version are 3.5. telebot library my code is:

from flask import Flask
import flask
import telebot

import requests
import time

app = Flask(__name__)

API_TOKEN = '***'

bot = telebot.TeleBot(API_TOKEN)

this is for get my ip :

res=requests.get('http://ipinfo.io/ip')
s=str(res.text)
s=s.split('\n')[0]

WEBHOOK_SSL_CERT = '/home/w/webhook_cert.pem'
WEBHOOK_SSL_PRIV = '/home/w//webhook_pkey.pem'


bot.set_webhook(url="https://myacc.pythonanywhere.com", certificate=open('/home/adr/webhook_pkey.pem'))

WEBHOOK_HOST =s
#WEBHOOK_HOST = 'https://myacc.pythonanywhere.com/'
WEBHOOK_PORT = 443
WEBHOOK_LISTEN = '0.0.0.0'

WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
#updates = bot.get_updates()

Process webhook calls

@app.route(WEBHOOK_URL_PATH, methods=['POST'])
def webhook():
    if flask.request.headers.get('content-type') == 'application/json':
        json_string = flask.request.get_data().decode('utf-8')
        update = telebot.types.Update.de_json(json_string)
        bot.process_new_updates([update])
        return 'Hello bot'
    else:
        flask.abort(403)

it's not worked and i got no error in log. is there any problem with libary and server or something else ?

what is the error that you are getting?