Skip to content

Commit

Permalink
return if no message
Browse files Browse the repository at this point in the history
  • Loading branch information
madanalogy committed Nov 13, 2023
1 parent cf54552 commit 939b11d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ def webhook(request):


async def process(request):
try:
BOT_TOKEN = os.getenv("BOT_TOKEN")
bot = telegram.Bot(token=BOT_TOKEN)
update = telegram.Update.de_json(request.get_json(force=True), bot)
print(f"Received update: {update}")
chat_id = update.message.chat.id
response = get_response(chat_id, update.message.text)
await bot.sendMessage(chat_id=chat_id, text=response)
except:
print(f"Error occured: {request}")
BOT_TOKEN = os.getenv("BOT_TOKEN")
bot = telegram.Bot(token=BOT_TOKEN)
update = telegram.Update.de_json(request.get_json(force=True), bot)
print(f"Received update: {update}")
if not update or not update.message or not update.message.chat or not update.message.chat.id:
return
chat_id = update.message.chat.id
response = get_response(chat_id, update.message.text)
await bot.sendMessage(chat_id=chat_id, text=response)


def get_response(chat_id, text):
Expand Down

0 comments on commit 939b11d

Please sign in to comment.