from flask import Flask
from flask import request
import requests
import json
import re
import settings
LINEBOT_API_EVENT ='https://trialbot-api.line.me/v1/events'
LINE_HEADERS = {
'Content-type': 'application/json; charset=UTF-8',
'X-Line-ChannelID':settings.CHANNEL_ID,
'X-Line-ChannelSecret':settings.CHANNEL_SECRET,
'X-Line-Trusted-User-With-ACL':settings.MID
}
def post_event(to, content):
msg = {
'to': [to],
'toChannel': 1383378250,
'eventType': "138311608800106203",
'content': content
}
r = requests.post(LINEBOT_API_EVENT, headers = LINE_HEADERS, data = json.dumps(msg))
def post_text(to, text):
content = {
'contentType': 1,
'toType': 1,
'text': text,
}
post_event(to, content)
app = Flask(__name__)
@app.route("/callback", methods=['POST'])
def callback():
messages = request.json['result']
#Echolalia for the time being
post_text(message['content']['from'], message['content']['text'])
return ''
if __name__ == "__main__":
app.run(host = '0.0.0.0', port = 8080, threaded = True, debug = True)
Like this.
The registration of LINE bot is as follows
Since the callback URL must be "__https (SSL compatible) __", it may be better to operate it on Heroku etc. I reissued the certificate that my home server is https, and managed to finish the server settings and developed it.
The bot that I developed for morphological analysis looks like the video below. I haven't even started it recently.
Morphological analyzer bot demo
Recommended Posts