Skip to content

Commit 0a2f09f

Browse files
committed
bot update
1 parent 5018afa commit 0a2f09f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

main.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ def telegram_bot(request):
2323
level=logging.INFO
2424
)
2525

26-
bot = telegram.Bot(token=os.getenv('TOKEN'))
26+
# check the header for the secret token
27+
secret_token = request.headers.get('X-Telegram-Bot-Api-Secret-Token')
28+
if secret_token != os.getenv('WEBHOOK_TOKEN'):
29+
logging.error("Invalid secret token")
30+
return "Forbidden", 403
31+
32+
bot = telegram.Bot(token=os.getenv('API_TOKEN'))
2733

2834
if request and request.method == "POST":
2935
try:
3036
update = telegram.Update.de_json(request.get_json(force=True), bot)
3137
command, args = parse_instructions(update)
3238

3339
execute_bot_command(command, args, bot, update)
40+
return "OK", 200
3441
except Exception as e:
3542
logging.error(f"Error processing update: {e}")
43+
return "Internal Server Error", 500
44+
45+
return "Invalid request", 400
3646

3747
# Used to test the bot on commandline by: python main.py /command [args]
3848
if __name__ == '__main__':

0 commit comments

Comments
 (0)