From 047777fada22bd5bd611f9766594188951bc3d55 Mon Sep 17 00:00:00 2001 From: "v.korobov" Date: Mon, 8 Aug 2022 23:04:36 +0300 Subject: [PATCH 1/2] Fixed TOKEN visibility in fastapi swagger --- examples/webhook_examples/webhook_fastapi_echo_bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webhook_examples/webhook_fastapi_echo_bot.py b/examples/webhook_examples/webhook_fastapi_echo_bot.py index 433b9a1..7eb97ab 100644 --- a/examples/webhook_examples/webhook_fastapi_echo_bot.py +++ b/examples/webhook_examples/webhook_fastapi_echo_bot.py @@ -33,7 +33,7 @@ telebot.logger.setLevel(logging.INFO) bot = telebot.TeleBot(API_TOKEN) -app = fastapi.FastAPI() +app = fastapi.FastAPI(docs=None, redoc_url=None) # Process webhook calls From c0ed659f3011f1125659bdd7758db8bebc5b6892 Mon Sep 17 00:00:00 2001 From: "v.korobov" Date: Mon, 8 Aug 2022 23:07:04 +0300 Subject: [PATCH 2/2] Minor code style fixes --- .../webhook_fastapi_echo_bot.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/webhook_examples/webhook_fastapi_echo_bot.py b/examples/webhook_examples/webhook_fastapi_echo_bot.py index 7eb97ab..015c356 100644 --- a/examples/webhook_examples/webhook_fastapi_echo_bot.py +++ b/examples/webhook_examples/webhook_fastapi_echo_bot.py @@ -6,6 +6,7 @@ import logging import fastapi +import uvicorn import telebot API_TOKEN = 'TOKEN' @@ -36,9 +37,11 @@ bot = telebot.TeleBot(API_TOKEN) 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]) @@ -46,18 +49,21 @@ def process_webhook(update: dict): 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) @@ -65,11 +71,12 @@ def echo_message(message): 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,