-1

I set up an AWS Lambda webhook to a Telegram bot. Regular messages are passed to event properly, but when a user uploads an image only 'text is passed to event. What could be the problem?

Screenshot of the received data.

def hello(event, context):
try:
    data = json.loads(event["body"])
    originalBody = str(data)
    message = str(data["message"]["text"])
    chat_id = data["message"]["chat"]["id"]
    first_name = data["message"]["chat"]["first_name"]
    print(data)

    response = "Please /start, {}".format(first_name)

    if "start" in message:
        response = "Hello {}".format(first_name)

    #data = {"text": response.encode("utf8"), "chat_id": chat_id}
    data = {"text": "heyyyy!", "chat_id": chat_id}
    url = BASE_URL + "/sendMessage"
    requests.post(url, data)
    requests.post(url, originalBody)

except Exception as e:
    print(e)

return {"statusCode": 200}
Anton
  • 3,587
  • 2
  • 12
  • 27
Ray G
  • 1
  • 2
  • Can you provide a [mcve]? As an aside, using `except Exception` like that is a bad idea, see https://stackoverflow.com/questions/54948548/what-is-wrong-with-using-a-bare-except. – AMC Apr 11 '20 at 00:07
  • I solved the problem. Thanks for the link about exceptions! – Ray G Apr 11 '20 at 08:47

1 Answers1

0

Just accessed variables the wrong way. "text" is just the name of the key, it was not found in the event with photo.

Ray G
  • 1
  • 2