Runs the Telegram webhook.
(event, context)
| 38 | |
| 39 | |
| 40 | def 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 | |
| 67 | def set_webhook(event, context): |
nothing calls this directly
no test coverage detected