Giter Site home page Giter Site logo

bobuhiro11 / line-bot-sdk-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from line/line-bot-sdk-python

0.0 1.0 0.0 194 KB

SDK of the LINE Messaging API for Python.

Home Page: https://pypi.python.org/pypi/line-bot-sdk

License: Apache License 2.0

Python 100.00%

line-bot-sdk-python's Introduction

line-bot-sdk-python

Build Status PyPI version Documentation Status

SDK of the LINE Messaging API for Python.

About the LINE Messaging API

See the official API documentation for more information.

English: https://devdocs.line.me/en/

Japanese: https://devdocs.line.me/ja/

Install

$ pip install line-bot-sdk

Synopsis

Usage:

API

LineBotApi

__init__(self, channel_access_token, endpoint='https://api.line.me', timeout=5, http_client=RequestsHttpClient)

Create a new LineBotApi instance.

You can override the timeout value for each method.

reply_message(self, reply_token, messages, timeout=None)

Respond to events from users, groups, and rooms. You can get a reply_token from a webhook event object.

https://devdocs.line.me/en/#reply-message

push_message(self, to, messages, timeout=None)

Send messages to users, groups, and rooms at any time.

https://devdocs.line.me/en/#push-message

multicast(self, to, messages, timeout=None)

Send messages to multiple users at any time.

https://devdocs.line.me/en/#multicast

get_profile(self, user_id, timeout=None)

Get user profile information.

https://devdocs.line.me/en/#bot-api-get-profile

get_group_member_profile(self, group_id, user_id, timeout=None)

Gets the user profile of a member of a group that the bot is in. This can be the user ID of a user who has not added the bot as a friend or has blocked the bot.

https://devdocs.line.me/en/#get-group-room-member-profile

get_room_member_profile(self, room_id, user_id, timeout=None)

Gets the user profile of a member of a room that the bot is in. This can be the user ID of a user who has not added the bot as a friend or has blocked the bot.

https://devdocs.line.me/en/#get-group-room-member-profile

get_group_member_ids(self, group_id, start=None, timeout=None)

Gets the user IDs of the members of a group that the bot is in. This includes the user IDs of users who have not added the bot as a friend or has blocked the bot.

https://devdocs.line.me/en/#get-group-room-member-ids

get_room_member_ids(self, room_id, start=None, timeout=None)

Gets the user IDs of the members of a room that the bot is in. This includes the user IDs of users who have not added the bot as a friend or has blocked the bot.

https://devdocs.line.me/en/#get-group-room-member-ids

get_message_content(self, message_id, timeout=None)

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

https://devdocs.line.me/en/#get-content

leave_group(self, group_id, timeout=None)

Leave a group.

https://devdocs.line.me/en/#leave

leave_room(self, room_id, timeout=None)

Leave a room.

https://devdocs.line.me/en/#leave

※ Error handling

If the LINE API server returns an error, LineBotApi raises LineBotApiError.

https://devdocs.line.me/en/#error-response

Send message object

https://devdocs.line.me/en/#send-message-object

These following classes are found in the linebot.models package.

TextSendMessage

ImageSendMessage

VideoSendMessage

AudioSendMessage

LocationSendMessage

StickerSendMessage

ImagemapSendMessage

TemplateSendMessage - ButtonsTemplate

TemplateSendMessage - ConfirmTemplate

TemplateSendMessage - CarouselTemplate

TemplateSendMessage - ImageCarouselTemplate

Webhook

WebhookParser

※ You can use WebhookParser or WebhookHandler

__init__(self, channel_secret)

parse(self, body, signature)

Parses the webhook body and builds an event object list. If the signature does NOT match, InvalidSignatureError is raised.

WebhookHandler

※ You can use WebhookParser or WebhookHandler

__init__(self, channel_secret)

handle(self, body, signature)

Handles webhooks. If the signature does NOT match, InvalidSignatureError is raised.

Add handler method

You can add a handler method by using the add decorator.

add(self, event, message=None)

When the event is an instance of MessageEvent and event.message is an instance of TextMessage, this handler method is called.

Set default handler method

You can set the default handler method by using the default decorator.

default(self)

If there is no handler for an event, this default handler method is called.

Webhook event object

https://devdocs.line.me/en/#webhooks

The following classes are found in the linebot.models package.

Event

  • MessageEvent
  • FollowEvent
    • type
    • timestamp
    • source: Source
    • reply_token
  • UnfollowEvent
    • type
    • timestamp
    • source: Source
  • JoinEvent
    • type
    • timestamp
    • source: Source
    • reply_token
  • LeaveEvent
    • type
    • timestamp
    • source: Source
  • PostbackEvent
    • type
    • timestamp
    • source: Source
    • reply_token
    • postback: Postback
      • data
      • params: dict
  • BeaconEvent
    • type
    • timestamp
    • source: Source
    • reply_token
    • beacon: Beacon
      • type
      • hwid
      • device_message

Source

  • SourceUser
    • type
    • user_id
  • SourceGroup
    • type
    • group_id
    • user_id
  • SourceRoom
    • type
    • room_id
    • user_id

Message

  • TextMessage
    • type
    • id
    • text
  • ImageMessage
    • type
    • id
  • VideoMessage
    • type
    • id
  • AudioMessage
    • type
    • id
  • LocationMessage
    • type
    • id
    • title
    • address
    • latitude
    • longitude
  • StickerMessage
    • type
    • id
    • package_id
    • sticker_id
  • FileMessage
    • type
    • id
    • file_size
    • file_name

Hints

Examples

Sample echo-bot using wsgiref.simple_server

Sample echo-bot using Flask

Sample bot using Flask

API documentation

$ cd docs
$ make html
$ open build/html/index.html

OR Documentation Status

Requirements

  • Python >= 2.7 or >= 3.3

For SDK developers

First install for development.

$ pip install -r requirements-dev.txt

Run tests

Test by using tox. We test against the following versions.

  • 2.7
  • 3.3
  • 3.4
  • 3.5
  • 3.6

To run all tests and to run flake8 against all versions, use:

tox

To run all tests against version 2.7, use:

$ tox -e py27

To run a test against version 2.7 and against a specific file, use:

$ tox -e py27 -- tests/test_webhook.py

And more... TBD

line-bot-sdk-python's People

Contributors

be-hase avatar c-bata avatar charsyam avatar guitarsucks avatar krrrr38 avatar moznion avatar naari3 avatar nnsnodnb avatar okdtsk avatar satetsu888 avatar turfaa avatar xsfishxs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.