Skip to content

Instantly share code, notes, and snippets.

@studio3104
Created April 11, 2016 11:12
Show Gist options
  • Save studio3104/3fdb97eeaaf72cd2438bf3a22e31f7f8 to your computer and use it in GitHub Desktop.
Save studio3104/3fdb97eeaaf72cd2438bf3a22e31f7f8 to your computer and use it in GitHub Desktop.
LINE BOT 試した
# -*- 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