Skip to content

Commit

Permalink
Minor code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kvaleryi committed Aug 8, 2022
1 parent 047777f commit c0ed659
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions examples/webhook_examples/webhook_fastapi_echo_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import fastapi
import uvicorn
import telebot

API_TOKEN = 'TOKEN'
Expand Down Expand Up @@ -36,40 +37,46 @@
app = fastapi.FastAPI(docs=None, redoc_url=None)


# Process webhook calls
@app.post(f'/{API_TOKEN}/')
def process_webhook(update: dict):
"""
Process webhook calls
"""
if update:
update = telebot.types.Update.de_json(update)
bot.process_new_updates([update])
else:
return



# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
"""
Handle '/start' and '/help'
"""
bot.reply_to(message,
("Hi there, I am EchoBot.\n"
"I am here to echo your kind words back to you."))


# Handle all other messages
@bot.message_handler(func=lambda message: True, content_types=['text'])
def echo_message(message):
"""
Handle all other messages
"""
bot.reply_to(message, message.text)


# Remove webhook, it fails sometimes the set if there is a previous webhook
bot.remove_webhook()

# Set webhook
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
certificate=open(WEBHOOK_SSL_CERT, 'r'))
bot.set_webhook(
url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
certificate=open(WEBHOOK_SSL_CERT, 'r')
)


import uvicorn
uvicorn.run(
app,
host=WEBHOOK_LISTEN,
Expand Down

0 comments on commit c0ed659

Please sign in to comment.