[PYTHON] Make a morphological analysis bot loosely with LINE + Flask

Source code

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

BOT API Trial Account

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.

Finally

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

Make a morphological analysis bot loosely with LINE + Flask
Make a LINE WORKS bot with Amazon Lex
Python beginners decided to make a LINE bot with Flask (Flask rough commentary)
Make a LINE BOT (chat)
[Super easy] Let's make a LINE BOT with Python.
How to make a Cisco Webex Teams BOT with Flask
Make a LINE bot with GoogleAppEngine / py. Simple naked version
Make a rare gacha simulator with Flask
Let's make a Twitter Bot with Python!
How to make an artificial intelligence LINE bot with Flask + LINE Messaging API
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
I made a stamp substitute bot with line
Make a Twitter trend bot with heroku + Python
Create a LINE BOT with Minette for Python
Make a simple pixel art generator with Flask
I made a LINE Bot with Serverless Framework!
I made a Mattermost bot with Python (+ Flask)
Make LINE BOT (Echolalia)
[AWS] I made a reminder BOT with LINE WORKS
Make a parrot return LINE Bot on AWS Cloud9
I made a LINE BOT with Python and Heroku
[For play] Let's make Yubaba a LINE Bot (Python)
Hanashi who became a read through BOT when trying to make a morphological analysis BOT using the popular LINE BOT API
Make a fortune with Python
Japanese morphological analysis with Python
[PowerShell] Morphological analysis with SudachiPy
Make a fire with kdeplot
I made a LINE BOT that returns parrots with Go
Create a machine learning app with ABEJA Platform + LINE Bot
Until I return something with a line bot in Django!
Let's make a LINE bot using various services [ngrok edition]
[AWS] I made a reminder BOT with LINE WORKS (implementation)
Create a bot that only returns the result of morphological analysis with MeCab on Discord
[LINE login] Verify state with Flask
[Python] Make your own LINE bot
Let's make a GUI with python.
Make a sound with Jupyter notebook
Creating a Flask server with Docker
How to make a slack bot
Let's make a breakout with wxPython
Let's make a WEB application for phone book with flask Part 2
Text mining with Python ① Morphological analysis
Creating a simple app with flask
Make a recommender system with python
[LINE Messaging API] Create a BOT that connects with someone with Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
Let's make a WEB application for phone book with flask Part 3
Make Flask a Cloud Native application
Make a filter with a django template
[LINE bot] I'm a ranger! Part 2
I played with Mecab (morphological analysis)!
Let's make a graph with python! !!
Let's make a WEB application for phone book with flask Part 4
Let's make a supercomputer with xCAT
Make a model iterator with PySide
Make a nice graph with plotly
Create a LINE Bot in Django
Let's make a shiritori game with Python
Make a video player with PySimpleGUI + OpenCV
Display Disney's waiting time with LINE bot
Creating a LINE bot ~ Creating, deploying, and launching ~