It seemed like I could do it quickly, so I decided to use Python to operate Linebot. First, Linebot itself only accepts __data __ and then returns __data __.
So, to put it roughly, it's likely that you'll basically use it to do two things.
This __interpretation method __ and __response format __ determine the functionality / nature of __Bot.
Below, I roughly prepared the Linebot module in Python. How to use / execute it is in README.md, so please refer to it. Linebot module: https://github.com/JFK/linebot
Here, let's operate Linebot using the above module and rq (job queue worker).
job_queue.py
from rq import Queue
from redis import Redis
def queue(name='low'):
redis = Redis()
q = Queue(connection=redis)
return q
from job_queue import queue
from linebot import LINEBot
...
#Parse callback data
bot = LINEBot(<CHANNEL_ID>)
receive = bot.receive_callback(json_body)
to = receive.content('from')
text = 'Hi!'
#When you receive the text
if receive.is_message and receive.content('contentType') == ContentType.TEXT:
#Set to job queue and execute
queue.enqueue(bot.send_text, [to], text)
...
It feels like.
Recommended Posts