[PYTHON] Asynchronous processing using Linebot in Job queue

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).

Run Linebot using rq

rq preparation

job_queue.py


from rq import Queue
from redis import Redis

def queue(name='low'):
	redis = Redis()
    q = Queue(connection=redis)
	return q

Run using rq

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

Asynchronous processing using Linebot in Job queue
Asynchronous processing using LINE BOT: RQ (Redis Queue) in Python
Queue processing in Python
Asynchronous processing (threading) in python
Celery asynchronous processing in Flask
Using Python mode in Processing
I tried asynchronous processing using asyncio
Job queue implementation example using Tornado coroutines
Asynchronous processing implementation in Django (Celery, Redis)
Asynchronous processing in Python: asyncio reverse lookup reference
LINE-Bot [0] in Python
Model using convolutional neural network in natural language processing
File processing in Python
Multithreaded processing in python
Dictionary-type processing using items ()
Text processing in Python