mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Minor code style fixes
This commit is contained in:
parent
047777fada
commit
c0ed659f30
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import fastapi
|
import fastapi
|
||||||
|
import uvicorn
|
||||||
import telebot
|
import telebot
|
||||||
|
|
||||||
API_TOKEN = 'TOKEN'
|
API_TOKEN = 'TOKEN'
|
||||||
@ -36,9 +37,11 @@ bot = telebot.TeleBot(API_TOKEN)
|
|||||||
app = fastapi.FastAPI(docs=None, redoc_url=None)
|
app = fastapi.FastAPI(docs=None, redoc_url=None)
|
||||||
|
|
||||||
|
|
||||||
# Process webhook calls
|
|
||||||
@app.post(f'/{API_TOKEN}/')
|
@app.post(f'/{API_TOKEN}/')
|
||||||
def process_webhook(update: dict):
|
def process_webhook(update: dict):
|
||||||
|
"""
|
||||||
|
Process webhook calls
|
||||||
|
"""
|
||||||
if update:
|
if update:
|
||||||
update = telebot.types.Update.de_json(update)
|
update = telebot.types.Update.de_json(update)
|
||||||
bot.process_new_updates([update])
|
bot.process_new_updates([update])
|
||||||
@ -46,18 +49,21 @@ def process_webhook(update: dict):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Handle '/start' and '/help'
|
|
||||||
@bot.message_handler(commands=['help', 'start'])
|
@bot.message_handler(commands=['help', 'start'])
|
||||||
def send_welcome(message):
|
def send_welcome(message):
|
||||||
|
"""
|
||||||
|
Handle '/start' and '/help'
|
||||||
|
"""
|
||||||
bot.reply_to(message,
|
bot.reply_to(message,
|
||||||
("Hi there, I am EchoBot.\n"
|
("Hi there, I am EchoBot.\n"
|
||||||
"I am here to echo your kind words back to you."))
|
"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'])
|
@bot.message_handler(func=lambda message: True, content_types=['text'])
|
||||||
def echo_message(message):
|
def echo_message(message):
|
||||||
|
"""
|
||||||
|
Handle all other messages
|
||||||
|
"""
|
||||||
bot.reply_to(message, message.text)
|
bot.reply_to(message, message.text)
|
||||||
|
|
||||||
|
|
||||||
@ -65,11 +71,12 @@ def echo_message(message):
|
|||||||
bot.remove_webhook()
|
bot.remove_webhook()
|
||||||
|
|
||||||
# Set webhook
|
# Set webhook
|
||||||
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
|
bot.set_webhook(
|
||||||
certificate=open(WEBHOOK_SSL_CERT, 'r'))
|
url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
|
||||||
|
certificate=open(WEBHOOK_SSL_CERT, 'r')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
import uvicorn
|
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
app,
|
app,
|
||||||
host=WEBHOOK_LISTEN,
|
host=WEBHOOK_LISTEN,
|
||||||
|
Loading…
Reference in New Issue
Block a user