MCPcopy Create free account
hub / github.com/serverless/examples / webhook

Function webhook

aws-python-telegram-bot/handler.py:40–64  ·  view source on GitHub ↗

Runs the Telegram webhook.

(event, context)

Source from the content-addressed store, hash-verified

38
39
40def webhook(event, context):
41 """
42 Runs the Telegram webhook.
43 """
44
45 bot = configure_telegram()
46 logger.info('Event: {}'.format(event))
47
48 if event.get('httpMethod') == 'POST' and event.get('body'):
49 logger.info('Message received')
50 update = telegram.Update.de_json(json.loads(event.get('body')), bot)
51 chat_id = update.message.chat.id
52 text = update.message.text
53
54 if text == '/start':
55 text = """Hello, human! I am an echo bot, built with Python and the Serverless Framework.
56 You can take a look at my source code here: https://github.com/jonatasbaldin/serverless-telegram-bot.
57 If you have any issues, please drop a tweet to my creator: https://twitter.com/jonatsbaldin. Happy botting!"""
58
59 bot.sendMessage(chat_id=chat_id, text=text)
60 logger.info('Message sent')
61
62 return OK_RESPONSE
63
64 return ERROR_RESPONSE
65
66
67def set_webhook(event, context):

Callers

nothing calls this directly

Calls 1

configure_telegramFunction · 0.85

Tested by

no test coverage detected