Created
April 11, 2016 11:12
-
-
Save studio3104/3fdb97eeaaf72cd2438bf3a22e31f7f8 to your computer and use it in GitHub Desktop.
LINE BOT 試した
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from flask import Flask, request | |
import json | |
import os | |
import requests | |
app = Flask('__main__') | |
HEADERS = { | |
'Content-Type': 'application/json; charser=UTF-8', | |
'X-Line-ChannelID': os.getenv('CHANNEL_ID'), | |
'X-Line-ChannelSecret': os.getenv('CHANNEL_SECRET'), | |
'X-Line-Trusted-User-With-ACL': os.getenv('CHANNEL_MID'), | |
} | |
@app.route('/callback', methods=['POST']) | |
def callback(): | |
for r in request.get_json().get('result'): | |
data = json.dumps({ | |
'to': [r['content']['from']], | |
'toChannel': 1383378250, | |
'eventType': '138311608800106203', | |
'content': { | |
'contentType': 1, | |
'toType': 1, | |
'text': 'え、「{}」って言った?'.format(r['content']['text'].encode('utf-8')), | |
} | |
}) | |
print data | |
response = requests.post('https://trialbot-api.line.me/v1/events', data=data, headers=HEADERS) | |
print response.status_code | |
print response.content | |
return '', 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment