linebot-sdk-python wrapper.
Project description
pylinebot
linebot-sdk-python wrapper.
Install
pip install pylinebot
Import, Instance
from pylinebot import LINE, Tracer
bot = LINE(
channel_access_token='XXXXXXXXXXXXXXXXXXX',
channel_secret='XXXXXXXXX'
)
Example (Echo-bot)
from flask import Flask, request
from pylinebot import LINE, Tracer
def receive_message(bot, event):
message = event.message
message_type = message.type
if message_type == 'text':
bot.reply_text_message(message.text)
DEBUG = True
app = Flask(__name__)
bot = LINE(
channel_access_token='XXXXXXXXXXXXXXXXXXX',
channel_secret='XXXXXXXXX'
)
tracer = Tracer(bot, debug=DEBUG)
tracer.add_event('message', receive_message)
@app.route("/", methods=['POST'])
def hello():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
tracer.trace(body, signature)
return 'OK'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000, debug=DEBUG)
Reply Message
- text
text = 'test'
bot.reply_text_message(text)
- image
img_url = 'https://xxx.xxxx/xxxx.jpg'
bot.reply_image_message(img_url)
- video
video_data = {
'content_url': 'https://xxx.xxxx/xxxx.mp4',
'preview_url': 'https://xxx.xxxx/xxxx.jpg'
}
bot.reply_video_message(video_data)
- audio
audio_data = {
'content_url': 'https://xxx.xxxx/xxxx.mp3',
'duration': 1000
}
bot.reply_audio_message(audio_data)
- location
location_data = {
'title': 'title',
'address': 'adress_name',
'latitude': 0,
'longitude': 0
}
bot.reply_location_message(location_data)
- sticker
sticker_data = {
'package_id': 1,
'sticker_id': 1
}
bot.reply_sticker_message(sticker_data)
- flex
flex_data = {
'flex': flex_content,
'alt_text': 'Flex Message'
}
bot.reply_flex_message(flex_data)
Quick reply
action_list = [
{
'type': 'message',
'label': 'aaaa',
'text': 'これ送信'
},
{
'type': 'camera',
'label': 'かめら',
},
{
'type': 'cameraRoll',
'label': 'かめらろーる',
},
{
'type': 'location',
'label': 'ろけーしょん',
},
{
'type': 'postback',
'label': 'ぽすとばっく',
'data': 'test_postback'
},
{
'type': 'datetimepicker',
'label': 'でーとぴっく',
'data': 'test_datepick',
'mode': 'date',
'initial': '2020-05-15',
'max': '2020-05-31',
'min': '2020-05-01'
}
]
bot.set_quick_reply(action_list)
bot.reply_text_message('quick_reply')
Send multiple messages
The max count of messages that can be sent at one time is 5.
# 2 text message
bot.reply_text_message('text', 'text')
# 5 text message
bot.reply_text_message('text', 'text', 'text', 'text', 'text')
# Error
bot.reply_text_message('text', 'text', 'text', 'text', 'text', 'text')
Send various messages at once.
messages = [
bot.create_text_message('いろんなめっせーじ'),
bot.create_text_message('いちどにおくれるよ'),
bot.create_image_message(img_data),
bot.create_video_message(video_data)
]
bot.reply_message(messages)
Save message content
Save image, video, and audio data sent by users.
bot.save_content_from_message_id(message_id, file_name)
Push message
bot.push_message(to, messages)
Broadcast
bot.broadcast(messages)
Narrowcast
bot.narrowcast(messages)
Multicast
bot.multicast(to, messages)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pylinebot-1.0.3.tar.gz
(5.8 kB
view details)
Built Distribution
pylinebot-1.0.3-py3-none-any.whl
(11.0 kB
view details)
File details
Details for the file pylinebot-1.0.3.tar.gz
.
File metadata
- Download URL: pylinebot-1.0.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6a907b156b22fb30221b1ba12ee726dd315156ab920a1bfb84ac0ddfd1d7113 |
|
MD5 | 3f8f552eba1472b8dfdd9a4e31dcba01 |
|
BLAKE2b-256 | f658f0f3797d996d0a418b828e25f5de1705540aac98d944f12b03c42c2a6b73 |
File details
Details for the file pylinebot-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: pylinebot-1.0.3-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62d7e8ad8818848b4e98e0c5099beb610cb727550cfd649849eb8d69684cf10c |
|
MD5 | 959fbe7c83e10c26b8dff5035aef4d37 |
|
BLAKE2b-256 | 1acc0baf9b0f1a56be5ca8be89b280f4f10e2fdaa8c41fbd9db3034e3f6a0407 |