Skip to content

Instantly share code, notes, and snippets.

@tad-iizuka
Created June 12, 2017 04:43
Show Gist options
  • Save tad-iizuka/c60e7878fea9fcf42a4cc688facca942 to your computer and use it in GitHub Desktop.
Save tad-iizuka/c60e7878fea9fcf42a4cc688facca942 to your computer and use it in GitHub Desktop.
import requests
import json
import os
HEADER = {
'Content-type': 'application/json',
'Authorization': 'Bearer ' + 'Channel Access Token'
}
def lambda_handler(event, context):
body = json.loads(event['body'])
for event in body['events']:
payload = {
'replyToken': event['replyToken'],
'messages': []
}
if event['message']['type'] == 'text':
payload['messages'].append({
'type': 'text',
'text': event['message']['text']
})
elif event['message']['type'] == 'sticker':
payload['messages'].append({
'type': 'sticker',
'stickerId': event['message']['stickerId'],
'packageId': event['message']['packageId']
})
if len(payload['messages']) > 0:
response = requests.post('https://api.line.me/v2/bot/message/reply',
headers=HEADER,
data=json.dumps(payload))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment