Skip to content

Instantly share code, notes, and snippets.

@smd877
Created January 28, 2020 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smd877/ed9a1e6be46a52246024bc72819a627c to your computer and use it in GitHub Desktop.
Save smd877/ed9a1e6be46a52246024bc72819a627c to your computer and use it in GitHub Desktop.
import os
import json
import urllib.request, urllib.parse
URL = 'https://api.line.me/v2/bot/message/push'
def lambda_handler(event, context):
to = event['to'] if 'to' in event.keys() else os.environ['SEND_TO']
token = event['token'] if 'token' in event.keys() else os.environ['CHANNEL_TOKEN']
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
}
body = {
'to': to,
'messages': event['messages']
}
req = urllib.request.Request(URL, data=json.dumps(body).encode("utf-8"),headers=headers,method='POST')
urllib.request.urlopen(req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment