-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
35 lines (28 loc) · 823 Bytes
/
Copy pathlambda_function.py
File metadata and controls
35 lines (28 loc) · 823 Bytes
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
from __future__ import print_function
import requests
import json
import os
import logging
print('Loading function')
# ref https://devdocs.line.me/ja/#reply-message
REQUEST_URL = 'https://api.line.me/v2/bot/message/reply'
REQUEST_HEADERS = {
'Authorization': 'Bearer ' + os.environ['ACCESS_TOKEN'],
'Content-type': 'application/json'
}
def lambda_handler(event, context):
print(event)
print(context)
body = json.loads(event['body'])
for event in body['events']:
reply_token = event['replyToken']
message = event['message']
body = {
"replyToken": reply_token,
"messages" : [{
"type" : "text",
"text" : message['text']
}]
}
response = requests.post(REQUEST_URL, headers=REQUEST_HEADERS, data=json.dumps(body))
print(response)