简体   繁体   中英

Telegram bot webhook and amazon lambda

I've tried to create my first telegram bot hosting the code as an amazon lambda instance, i suppose i should return something to the webhook 'cause it keep saying "Wrong response from the webhook: 502 Bad Gateway".

Here is part of my code:

 def msgSend(text, chat_id): url = URL + "sendMessage?text={}&chat_id={}".format(text, chat_id) response = requests.get(url) content = response.content.decode("utf8") return content def handle(msg): sender = msg['from']['username'] id_gruppo = msg['chat']['id'] if sender == NAME: testo = msg['text'] usernames = [x.replace('@','') for x in rx.findall(text)] map(foo, usernames) msgSend(confirm_mess, id_group) return def main(event, context): response = ast.literal_eval(event['body']) handle(response['message']) return { 'something': 'something' }

Actually the process works fine enough, the messages are received by my lambda and everything works like a charm, except for one thing, the confirmation message is sent over and over endlessly and the webhooks never marks the messages as read.

here is the response of getWebHookInfo: {"ok":true,"result":{"url":"https://t2rt9guj3h.execute-api.us-west-2.amazonaws.com/prod/instabot","has_custom_certificate":false,"pending_update_count":19,"last_error_date":1489331750,"last_error_message":"Wrong response from the webhook: 502 Bad Gateway","max_connections":40}}

According to the bot helper the wh requires a 2XX code response...

Any idea about that?

According to the bot helper the wh requires a 2XX code response...

This is true. Your last statement should be

return {
    statusCode: 200
}

If you don't return a successful response code, Telegram won't know what to do with it, which is why you see the HTTP 502 Bad Gateway . I was hitting this for awhile also :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM