-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.py
40 lines (28 loc) · 1.02 KB
/
handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import os
import sys
import random
from quote_list import quote_list
here = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(here, "./vendored"))
import requests
TOKEN = os.environ['TELEGRAM_TOKEN']
BASE_URL = "https://api.telegram.org/bot{}".format(TOKEN)
def hello(event, context):
try:
data = json.loads(event["body"])
message = str(data["message"]["text"])
chat_id = data["message"]["chat"]["id"]
response = "Hey! Use the /motivate command to get some inspiration!"
if "/motivate" in message:
quote = random.choice(quote_list)
response = '"%s" - %s' % (quote['quote'], quote['author'])
if "/status" in message:
response = "Motivating people since June 13th 2018!"
data = {"text": response.encode("utf8"), "chat_id": chat_id}
url = BASE_URL + "/sendMessage"
requests.post(url, data)
print(response)
except Exception as e:
print(e)
return {"statusCode": 200}