File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff 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]
3848if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments