Skip to main content

linebot-sdk-python wrapper.

Project description

pylinebot

linebot-sdk-python wrapper.

Install

pip install pylinebot

Import

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):
    reply_token = event.reply_token

    message = event.message
    message_type = message.type

    if message_type == 'text':
        message_text = message.text
        bot.send_text_message(reply_token, 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)

Send Message

  • text
bot.send_text_message(reply_token, text)
  • image
bot.send_image_message(reply_token, 'https://xxx.xxxx/xxxx.jpg')
  • video
video_data = {
    'content_url': 'https://xxx.xxxx/xxxx.mp4',
    'preview_url': 'https://xxx.xxxx/xxxx.jpg'
}
bot.send_video_message(reply_token, video_data)
  • audio
audio_data = {
    'content_url': 'https://xxx.xxxx/xxxx.mp3',
    'duration': 1000
}
bot.send_audio_message(reply_token, audio_data)
  • location
location_data = {
    'title': 'title',
    'address': 'adress_name',
    'latitude': 0,
    'longitude': 0
}
bot.send_location_message(reply_token, location_data)
  • sticker
sticker_data = {
    'package_id': 1,
    'sticker_id': 1
}
bot.send_sticker_message(reply_token, sticker_data)
  • flex
flex_data = {
    'flex': flex_content,
    'alt_text': 'Flex Message'
}
bot.send_flex_message(reply_token, flex_data)

replay, push, other

Default send_type='reply'

send_type

  • reply
  • push
  • broadcast
  • narrowcast
  • multicast
bot.send_text_message(to, text, send_type='push')

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.send_text_message(reply_token, 'text', quick_reply=quick_reply)

Send multiple messages

The max count of messages that can be sent at one time is 5.

# 2 text message
bot.send_text_message(reply_token, 'text', 'text')
# 5 text message
bot.send_text_message(reply_token, 'text', 'text', 'text', 'text', 'text')
# Error
bot.send_text_message(reply_token, 'text', 'text', 'text', 'text', 'text', 'text')

Send various messages at once.

message_list = [
    bot.create_text_message('いろんなめっせーじ'),
    bot.create_text_message('いちどにおくれるよ'),
    bot.create_image_message('https://xxx.xxxx/xxxx.jpg'),
    bot.create_video_message('https://xxx.xxxx/xxxx.mp4', 'https://xxx.xxxx/xxxx.jpg')
]
bot.send_message(reply_token, message_list)

Save message content

Save image, video, and audio data sent by users.

bot.save_content_from_message_id(message_id, file_name)

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.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

pylinebot-1.0.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file pylinebot-1.0.1.tar.gz.

File metadata

  • Download URL: pylinebot-1.0.1.tar.gz
  • Upload date:
  • Size: 5.7 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

Hashes for pylinebot-1.0.1.tar.gz
Algorithm Hash digest
SHA256 25f999ce20decaa26d0fe171e97cf4a9c7d4af9078a14be954595311a6951d7c
MD5 863822d97ee668b657e6070be35dcc12
BLAKE2b-256 f59cf55b4fce2fa766e737da7b66d2309b4320ded85ae2ab40e2071e9027fc77

See more details on using hashes here.

File details

Details for the file pylinebot-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pylinebot-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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

Hashes for pylinebot-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 122ebfb877387d30339fc0db43428393ce81e8d6826eeb4b9a909345400cf2f7
MD5 a4712699853d6eb1e7a9e36ead0a158f
BLAKE2b-256 e0c12e09fe499f717d098a74c7d7f35bafc17f60f1ccb535fb23f375fbffb4ed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page