linebot package

linebot.api module

linebot.api module.

class linebot.api.LineBotApi(channel_access_token, endpoint='https://api.line.me', data_endpoint='https://api-data.line.me', timeout=5, http_client=<class 'linebot.http_client.RequestsHttpClient'>)[source]

Bases: object

LineBotApi provides interface for LINE messaging API.

DEFAULT_API_ENDPOINT = 'https://api.line.me'
DEFAULT_API_DATA_ENDPOINT = 'https://api-data.line.me'
__init__(channel_access_token, endpoint='https://api.line.me', data_endpoint='https://api-data.line.me', timeout=5, http_client=<class 'linebot.http_client.RequestsHttpClient'>)[source]

__init__ method.

Parameters
reply_message(reply_token, messages, notification_disabled=False, timeout=None)[source]

Call reply message API.

https://developers.line.biz/en/reference/messaging-api/#send-reply-message

Respond to events from users, groups, and rooms.

Webhooks are used to notify you when an event occurs. For events that you can respond to, a replyToken is issued for replying to messages.

Because the replyToken becomes invalid after a certain period of time, responses should be sent as soon as a message is received.

Reply tokens can only be used once.

Parameters
  • reply_token (str) – replyToken received via webhook

  • messages (T <= linebot.models.send_messages.SendMessage | list[T <= linebot.models.send_messages.SendMessage]) – Messages. Max: 5

  • notification_disabled (bool) – (optional) True to disable push notification when the message is sent. The default value is False.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

push_message(to, messages, retry_key=None, notification_disabled=False, custom_aggregation_units=None, timeout=None)[source]

Call push message API.

https://developers.line.biz/en/reference/messaging-api/#send-push-message

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

Parameters
  • to (str) – ID of the receiver

  • messages (T <= linebot.models.send_messages.SendMessage | list[T <= linebot.models.send_messages.SendMessage]) – Messages. Max: 5

  • retry_key – (optional) Arbitrarily generated UUID in hexadecimal notation.

  • notification_disabled (bool) – (optional) True to disable push notification when the message is sent. The default value is False.

  • custom_aggregation_units (str | list[str]) – (optional) Name of aggregation unit. Case-sensitive. Max unit: 1 Max aggregation unit name length: 30 characters Supported character types: Half-width alphanumeric characters and underscore

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

multicast(to, messages, retry_key=None, notification_disabled=False, custom_aggregation_units=None, timeout=None)[source]

Call multicast API.

https://developers.line.biz/en/reference/messaging-api/#send-multicast-message

Sends push messages to multiple users at any time. Messages cannot be sent to groups or rooms.

Parameters
  • to (list[str]) – IDs of the receivers Max: 150 users

  • messages (T <= linebot.models.send_messages.SendMessage | list[T <= linebot.models.send_messages.SendMessage]) – Messages. Max: 5

  • retry_key – (optional) Arbitrarily generated UUID in hexadecimal notation.

  • notification_disabled (bool) – (optional) True to disable push notification when the message is sent. The default value is False.

  • custom_aggregation_units (str | list[str]) – (optional) Name of aggregation unit. Case-sensitive. Max unit: 1 Max aggregation unit name length: 30 characters Supported character types: Half-width alphanumeric characters and underscore

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

broadcast(messages, retry_key=None, notification_disabled=False, timeout=None)[source]

Call broadcast API.

https://developers.line.biz/en/reference/messaging-api/#send-broadcast-message

Sends push messages to multiple users at any time.

Parameters
  • messages (T <= linebot.models.send_messages.SendMessage | list[T <= linebot.models.send_messages.SendMessage]) – Messages. Max: 5

  • retry_key – (optional) Arbitrarily generated UUID in hexadecimal notation.

  • notification_disabled (bool) – (optional) True to disable push notification when the message is sent. The default value is False.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.BroadcastResponse

narrowcast(messages, retry_key=None, recipient=None, filter=None, limit=None, notification_disabled=False, timeout=None)[source]

Call narrowcast API.

https://developers.line.biz/en/reference/messaging-api/#send-narrowcast-message

Sends push messages to multiple users at any time. Messages cannot be sent to groups or rooms.

Parameters
Return type

linebot.models.responses.NarrowcastResponse

get_progress_status_narrowcast(request_id, timeout=None)[source]

Get progress status of narrowcast messages sent.

https://developers.line.biz/en/reference/messaging-api/#get-narrowcast-progress-status

Gets the number of messages sent with the /bot/message/progress/narrowcast endpoint.

Parameters
  • request_id (str) – request ID of narrowcast.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MessageDeliveryBroadcastResponse

get_message_delivery_broadcast(date, timeout=None)[source]

Get number of sent broadcast messages.

https://developers.line.biz/en/reference/messaging-api/#get-number-of-broadcast-messages

Gets the number of messages sent with the /bot/message/broadcast endpoint.

Parameters
  • date (str) – Date the messages were sent. The format is yyyyMMdd (Timezone is UTC+9).

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MessageDeliveryBroadcastResponse

get_message_delivery_reply(date, timeout=None)[source]

Get number of sent reply messages.

https://developers.line.biz/en/reference/messaging-api/#get-number-of-reply-messages

Gets the number of messages sent with the /bot/message/reply endpoint.

Parameters
  • date (str) – Date the messages were sent. The format is yyyyMMdd (Timezone is UTC+9).

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MessageDeliveryReplyResponse

get_message_delivery_push(date, timeout=None)[source]

Get number of sent push messages.

https://developers.line.biz/en/reference/messaging-api/#get-number-of-push-messages

Gets the number of messages sent with the /bot/message/push endpoint.

Parameters
  • date (str) – Date the messages were sent. The format is yyyyMMdd (Timezone is UTC+9).

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MessageDeliveryPushResponse

get_message_delivery_multicast(date, timeout=None)[source]

Get number of sent multicast messages.

https://developers.line.biz/en/reference/messaging-api/#get-number-of-multicast-messages

Gets the number of messages sent with the /bot/message/multicast endpoint.

Parameters
  • date (str) – Date the messages were sent. The format is yyyyMMdd (Timezone is UTC+9).

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MessageDeliveryMulticastResponse

get_profile(user_id, timeout=None)[source]

Call get profile API.

https://developers.line.biz/en/reference/messaging-api/#get-profile

Get user profile information.

Parameters
  • user_id (str) – User ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Profile

Returns

Profile instance

get_group_summary(group_id, timeout=None)[source]

Call get group summary API.

https://developers.line.biz/en/reference/messaging-api/#get-group-summary

Gets the group ID, group name, and group icon URL of a group where the LINE Official Account is a member.

Parameters
  • group_id (str) – Group ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Group

Returns

Profile instance

get_group_members_count(group_id, timeout=None)[source]

Call get members in group count API.

https://developers.line.biz/en/reference/messaging-api/#get-members-group-count

Gets the count of members in a group.

Parameters
  • group_id (str) – Group ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Group

Returns

Profile instance

get_room_members_count(room_id, timeout=None)[source]

Call get members in room count API.

https://developers.line.biz/en/reference/messaging-api/#get-members-room-count

Gets the count of members in a room.

Parameters
  • room_id (str) – Room ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Group

Returns

Profile instance

get_group_member_profile(group_id, user_id, timeout=None)[source]

Call get group member profile API.

https://developers.line.biz/en/reference/messaging-api/#get-group-member-profile

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.

Parameters
  • group_id (str) – Group ID

  • user_id (str) – User ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Profile

Returns

Profile instance

get_room_member_profile(room_id, user_id, timeout=None)[source]

Call get room member profile API.

https://developers.line.biz/en/reference/messaging-api/#get-room-member-profile

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.

Parameters
  • room_id (str) – Room ID

  • user_id (str) – User ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Profile

Returns

Profile instance

get_group_member_ids(group_id, start=None, timeout=None)[source]

Call get group member IDs API.

https://developers.line.biz/en/reference/messaging-api/#get-group-member-ids

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.

Parameters
  • group_id (str) – Group ID

  • start (str) – continuationToken

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MemberIds

Returns

MemberIds instance

get_room_member_ids(room_id, start=None, timeout=None)[source]

Call get room member IDs API.

https://developers.line.biz/en/reference/messaging-api/#get-room-member-ids

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.

Parameters
  • room_id (str) – Room ID

  • start (str) – continuationToken

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MemberIds

Returns

MemberIds instance

get_message_content(message_id, timeout=None)[source]

Call get content API.

https://developers.line.biz/en/reference/messaging-api/#get-content

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

Parameters
  • message_id (str) – Message ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Content

Returns

Content instance

leave_group(group_id, timeout=None)[source]

Call leave group API.

https://developers.line.biz/en/reference/messaging-api/#leave-group

Leave a group.

Parameters
  • group_id (str) – Group ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

leave_room(room_id, timeout=None)[source]

Call leave room API.

https://developers.line.biz/en/reference/messaging-api/#leave-room

Leave a room.

Parameters
  • room_id (str) – Room ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_rich_menu(rich_menu_id, timeout=None)[source]

Call get rich menu API.

https://developers.line.biz/en/reference/messaging-api/#get-rich-menu

Parameters
  • rich_menu_id (str) – ID of the rich menu

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.RichMenuResponse

Returns

RichMenuResponse instance

get_rich_menu_alias(rich_menu_alias_id=None, timeout=None)[source]

Call get rich menu alias API.

https://developers.line.biz/en/reference/messaging-api/#get-rich-menu-alias-by-id

Parameters
  • rich_menu_alias_id (str) – ID of an uploaded rich menu alias.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.RichMenuAliasResponse

Returns

RichMenuAliasResponse instance

get_rich_menu_alias_list(timeout=None)[source]

Call get rich menu alias list API.

https://developers.line.biz/en/reference/messaging-api/#update-rich-menu-alias

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.RichMenuAliasListResponse

Returns

RichMenuAliasListResponse instance

validate_rich_menu_object(rich_menu, timeout=None)[source]

Call validate rich menu object API.

https://developers.line.biz/ja/reference/messaging-api/#validate-rich-menu-object

Parameters
  • rich_menu (T <= linebot.models.rich_menu.RichMenu) – Inquired to validate a rich menu object.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

create_rich_menu(rich_menu, timeout=None)[source]

Call create rich menu API.

https://developers.line.biz/en/reference/messaging-api/#create-rich-menu

Parameters
  • rich_menu (T <= linebot.models.rich_menu.RichMenu) – Inquired to create a rich menu object.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

str

Returns

rich menu id

create_rich_menu_alias(rich_menu_alias, timeout=None)[source]

Call create rich menu alias API.

https://developers.line.biz/en/reference/messaging-api/#create-rich-menu-alias

Parameters
  • rich_menu_alias (T <= linebot.models.rich_menu.RichMenuAlias) – Inquired to create a rich menu alias object.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

str

Returns

rich menu id

update_rich_menu_alias(rich_menu_alias_id, rich_menu_alias, timeout=None)[source]

Call update rich menu alias API.

https://developers.line.biz/en/reference/messaging-api/#update-rich-menu-alias

Parameters
  • rich_menu_alias_id (str) – ID of an uploaded rich menu alias.

  • rich_menu_alias (T <= linebot.models.rich_menu.RichMenuAlias) – Inquired to create a rich menu alias object.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

str

Returns

rich menu id

delete_rich_menu(rich_menu_id, timeout=None)[source]

Call delete rich menu API.

https://developers.line.biz/en/reference/messaging-api/#delete-rich-menu

Parameters
  • rich_menu_id (str) – ID of an uploaded rich menu

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

delete_rich_menu_alias(rich_menu_alias_id, timeout=None)[source]

Call delete rich menu alias API.

https://developers.line.biz/en/reference/messaging-api/#delete-rich-menu-alias

Parameters
  • rich_menu_alias_id (str) – ID of an uploaded rich menu alias.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_rich_menu_id_of_user(user_id, timeout=None)[source]

Call get rich menu ID of user API.

https://developers.line.biz/en/reference/messaging-api/#get-rich-menu-id-of-user

Parameters
  • user_id (str) – IDs of the user

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

str

Returns

rich menu id

Call link rich menu to user API.

https://developers.line.biz/en/reference/messaging-api/#link-rich-menu-to-user

Parameters
  • user_id (str) – ID of the user

  • rich_menu_id (str) – ID of an uploaded rich menu

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Links a rich menu to multiple users.

https://developers.line.biz/en/reference/messaging-api/#link-rich-menu-to-users

Parameters
  • user_ids (list[str]) – user IDs Max: 150 users

  • rich_menu_id (str) – ID of an uploaded rich menu

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Call unlink rich menu from user API.

https://developers.line.biz/en/reference/messaging-api#unlink-rich-menu-from-user

Parameters
  • user_id (str) – ID of the user

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Unlinks rich menus from multiple users.

https://developers.line.biz/en/reference/messaging-api/#unlink-rich-menu-from-users

Parameters
  • user_ids (list[str]) – user IDs Max: 150 users

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_rich_menu_image(rich_menu_id, timeout=None)[source]

Call download rich menu image API.

https://developers.line.biz/en/reference/messaging-api#download-rich-menu-image

Parameters
  • rich_menu_id (str) – ID of the rich menu with the image to be downloaded

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.Content

Returns

Content instance

set_rich_menu_image(rich_menu_id, content_type, content, timeout=None)[source]

Call upload rich menu image API.

https://developers.line.me/en/docs/messaging-api/reference/#upload-rich-menu-image

Uploads and attaches an image to a rich menu.

Parameters
  • rich_menu_id (str) – IDs of the richmenu

  • content_type (str) – image/jpeg or image/png

  • content – image content as bytes, or file-like object

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_rich_menu_list(timeout=None)[source]

Call get rich menu list API.

https://developers.line.me/en/docs/messaging-api/reference/#get-rich-menu-list

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

list(T <= linebot.models.responses.RichMenuResponse)

Returns

list[RichMenuResponse] instance

set_default_rich_menu(rich_menu_id, timeout=None)[source]

Set the default rich menu.

https://developers.line.biz/en/reference/messaging-api/#set-default-rich-menu

Parameters
  • rich_menu_id (str) – ID of an uploaded rich menu

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_default_rich_menu(timeout=None)[source]

Get the ID of the default rich menu set with the Messaging API.

https://developers.line.biz/en/reference/messaging-api/#get-default-rich-menu-id

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

cancel_default_rich_menu(timeout=None)[source]

Cancel the default rich menu set with the Messaging API.

https://developers.line.biz/en/reference/messaging-api/#cancel-default-rich-menu

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_message_quota(timeout=None)[source]

Call Get the target limit for additional messages.

https://developers.line.biz/en/reference/messaging-api/#get-quota

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MessageQuotaResponse

Returns

MessageQuotaResponse instance

get_message_quota_consumption(timeout=None)[source]

Get number of messages sent this month.

https://developers.line.biz/en/reference/messaging-api/#get-consumption

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.MessageQuotaConsumptionResponse

Returns

MessageQuotaConsumptionResponse instance

Issues a link token used for the account link feature.

https://developers.line.biz/en/reference/messaging-api/#issue-link-token

Parameters
  • user_id (str) – User ID for the LINE account to be linked

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.IssueLinkTokenResponse

Returns

IssueLinkTokenResponse instance

issue_channel_token(client_id, client_secret, grant_type='client_credentials', timeout=None)[source]

Issues a short-lived channel access token.

https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token

Parameters
  • client_id (str) – Channel ID.

  • client_secret (str) – Channel secret.

  • grant_type (str) – client_credentials

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.IssueChannelTokenResponse

Returns

IssueChannelTokenResponse instance

revoke_channel_token(access_token, timeout=None)[source]

Revokes a channel access token.

https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token

Parameters
  • access_token (str) – Channel access token.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_insight_message_delivery(date, timeout=None)[source]

Get the number of messages sent on a specified day.

https://developers.line.biz/en/reference/messaging-api/#get-number-of-delivery-messages

Parameters
  • date (str) – Date for which to retrieve number of sent messages.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.InsightMessageDeliveryResponse

get_insight_followers(date, timeout=None)[source]

Get the number of users who have added the bot on or before a specified date.

https://developers.line.biz/en/reference/messaging-api/#get-number-of-followers

Parameters
  • date (str) – Date for which to retrieve the number of followers.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.InsightFollowersResponse

get_insight_demographic(timeout=None)[source]

Retrieve the demographic attributes for a bot’s friends.

https://developers.line.biz/en/reference/messaging-api/#get-demographic

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.InsightDemographicResponse

get_insight_message_event(request_id, timeout=None)[source]

Return statistics about how users interact with broadcast messages.

https://developers.line.biz/en/reference/messaging-api/#get-message-event

Parameters
  • request_id (str) – Request ID of broadcast message.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.InsightMessageEventResponse

get_bot_info(timeout=None)[source]

Get a bot’s basic information.

https://developers.line.biz/en/reference/messaging-api/#get-bot-info

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.BotInfo

create_audience_group(audience_group_name, audiences=None, is_ifa=False, timeout=None)[source]

Create an audience group.

https://developers.line.biz/en/reference/messaging-api/#create-upload-audience-group

Parameters
  • audience_group_name (str) – The audience’s name

  • audiences (list) – An array of user IDs or IFAs

  • is_ifa (bool) – true | false

Returns

audience group id

get_audience_group(audience_group_id, timeout=None)[source]

Get the object of audience group.

https://developers.line.biz/en/reference/messaging-api/#get-audience-group

Parameters
  • audience_group_id (str) – The audience ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Returns

AudienceGroup instance

get_audience_group_list(page=1, description=None, status=None, size=20, include_external_public_group=None, create_route=None, timeout=None)[source]

Get data for more than one audience.

https://developers.line.biz/en/reference/messaging-api/#get-audience-groups

Parameters
  • page (int) – The page to return when getting (paginated) results. Must be 1 or higher

  • description (str) – The name of the audience(s) to return

  • status (str) – IN_PROGRESS | READY | FAILED | EXPIRED

  • size (int) – The number of audiences per page. Default: 20, Max: 40

  • include_external_public_group (bool) – true | false

  • create_route (OA_MANAGER | MESSAGING_API) – How the audience was created.

Returns

AudienceGroup instance

delete_audience_group(audience_group_id, timeout=None)[source]

Delete an existing audience.

https://developers.line.biz/en/reference/messaging-api/#delete-audience-group

Parameters
  • audience_group_id (str) – The audience ID

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

rename_audience_group(audience_group_id, description, timeout=None)[source]

Modify the name of an existing audience.

https://developers.line.biz/en/reference/messaging-api/#set-description-audience-group

Parameters
  • audience_group_id (str) – The audience ID

  • description (str) – The new audience’s name

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

add_audiences_to_audience_group(audience_group_id, audiences, upload_description=None, timeout=None)[source]

Add new user IDs or IFAs to an audience for uploading user IDs.

https://developers.line.biz/en/reference/messaging-api/#update-upload-audience-group

Parameters
  • audience_group_id (str) – The audience ID

  • audiences (list) – An array of user IDs or IFAs

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

  • is_ifa (bool) – If this is false (default), recipients are specified by user IDs. If true, recipients must be specified by IFAs.

  • upload_description (str) – The description to register for the job

get_audience_group_authority_level(timeout=None)[source]

Get the authority level of the audience.

https://developers.line.biz/en/reference/messaging-api/#get-authority-level

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Returns

json

change_audience_group_authority_level(authority_level='PUBLIC', timeout=None)[source]

Change the authority level of all audiences created in the same channel.

https://developers.line.biz/en/reference/messaging-api/#change-authority-level

Parameters

authority_level (str) – PUBLIC | PRIVATE.

create_click_audience_group(description, request_id, click_url=None, timeout=None)[source]

Create an audience for click-based retargeting.

https://developers.line.biz/en/reference/messaging-api/#create-click-audience-group

Parameters
  • description (str) – The audience’s name. Audience names must be unique.

  • request_id (str) – The request ID of a message sent in the past 60 days.

  • click_url (str) – The URL clicked by the user.

If empty, users who clicked any URL in the message are added to the list of recipients. :param timeout: (optional) How long to wait for the server

to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Returns

ClickAudienceGroup instance

create_imp_audience_group(description, request_id, timeout=None)[source]

Create an audience for impression-based retargeting.

https://developers.line.biz/en/reference/messaging-api/#create-imp-audience-group

Parameters
  • description (str) – The audience’s name. Audience names must be unique.

  • request_id (str) – The request ID of a message sent in the past 60 days.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Returns

ImpAudienceGroup instance

set_webhook_endpoint(webhook_endpoint, timeout=None)[source]

Set the webhook endpoint URL.

https://developers.line.biz/en/reference/messaging-api/#set-webhook-endpoint-url

Parameters
  • webhook_endpoint (str) – A valid webhook URL to be set.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

dict

Returns

Empty dict.

get_webhook_endpoint(timeout=None)[source]

Get information on a webhook endpoint.

https://developers.line.biz/en/reference/messaging-api/#get-webhook-endpoint-information

Return type

linebot.models.responses.GetWebhookResponse

Returns

Webhook information, including endpoint for webhook URL and active for webhook usage status.

test_webhook_endpoint(webhook_endpoint=None, timeout=None)[source]

Checks if the configured webhook endpoint can receive a test webhook event.

https://developers.line.biz/en/reference/messaging-api/#test-webhook-endpoint

Parameters
  • webhook_endpoint – (optional) Set this parameter to specific the webhook endpoint of the webhook. Default is the webhook endpoint that is already set to the channel.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.TestWebhookResponse

get_followers_ids(limit=300, start=None, timeout=None)[source]

Get a list of users who added your LINE Official Account as a friend.

https://developers.line.biz/en/reference/messaging-api/#get-follower-ids

Parameters
  • limit (int) – The maximum number of user IDs to retrieve in a single request. The default value is 300.

  • start (str) – Get the next array of user IDs.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.UserIds

issue_channel_access_token_v2_1(client_assertion, grant_type='client_credentials', client_assertion_type='urn:ietf:params:oauth:client-assertion-type:jwt-bearer', timeout=None)[source]

Issues a channel access token v2.1.

https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1

Parameters
  • client_assertion (str) – Client assertion.

  • grant_type (str) – client_credentials

  • client_assertion_type (str) – urn:ietf:params:oauth:client-assertion-type:jwt-bearer.

  • timeout – (optional) How long to wait for the server

to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout :type timeout: float | tuple(float, float) :rtype: linebot.models.responses.IssueChannelTokenResponseV2

revoke_channel_access_token_v2_1(client_id, client_secret, access_token, timeout=None)[source]

Revokes a channel access token v2.1.

https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1

Parameters
  • client_id (str) – Client id.

  • client_secret (str) – Channel secret.

  • access_token (str) – Channel access token.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

get_channel_access_tokens_v2_1(client_assertion, client_assertion_type='urn:ietf:params:oauth:client-assertion-type:jwt-bearer', timeout=None)[source]

Get issued channel access tokens v2.1.

https://developers.line.biz/en/reference/messaging-api/#get-issued-channel-access-tokens-v2-1

Parameters
  • client_assertion (str) – Client assertion.

  • client_assertion_type (str) – urn:ietf:params:oauth:client-assertion-type:jwt-bearer.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.ChannelAccessTokens

verify_channel_access_token_v2_1(access_token, timeout=None)[source]

Validate channel access token v2.1.

https://developers.line.biz/en/reference/messaging-api/#verfiy-channel-access-token-v2-1

Parameters
  • access_token (str) – Channel access token.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.VerifyChannelTokenResponseV2

get_channel_token_key_ids_v2_1(client_assertion, client_assertion_type='urn:ietf:params:oauth:client-assertion-type:jwt-bearer', timeout=None)[source]

Get all valid channel access token key IDs v2.1.

https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1

Parameters
  • client_assertion (str) – Client assertion.

  • client_assertion_type (str) – urn:ietf:params:oauth:client-assertion-type:jwt-bearer.

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

linebot.models.responses.VerifyChannelTokenResponseV2

get_statistics_per_unit(custom_aggregation_unit, from_date, to_date, timeout=None)[source]

Return statistics about how users interact with push and multicast messages.

https://developers.line.biz/en/reference/partner-docs/#get-statistics-per-unit

Parameters
  • custom_aggregation_unit (str) – Name of aggregation unit specified when sending the message like push_message(…) and multicast(…).

  • from_date (str) – Start date of aggregation period. The format is yyyyMMdd (Timezone is UTC+9).

  • to_date (str) – End date of aggregation period. The end date can be specified for up to 30 days later. The format is yyyyMMdd (Timezone is UTC+9).

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

py:class

linebot.models.responses.InsightMessageEventOfCustomAggregationUnitResponse

get_number_of_units_used_this_month(timeout=None)[source]

Return the number of aggregation units used this month.

https://developers.line.biz/en/reference/partner-docs/#get-number-of-units-used-this-month

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

py:class

linebot.models.responses.AggregationInfoResponse

get_name_list_of_units_used_this_month(limit=100, start=None, timeout=None)[source]

Return the name list of units used this month for statistics aggregation.

Parameters
  • limit (int) – Maximum number of aggregation units you can get per request. If you don’t specify a value, or if you specify a value greater than or equal to 100, the maximum is 100.

  • start (str) – Get the next array of name list of units

  • timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.http_client.timeout

Return type

py:class

linebot.models.responses.AggregationNameListResponse

linebot.webhook module

linebot.webhook module.

class linebot.webhook.SignatureValidator(channel_secret)[source]

Bases: object

Signature validator.

https://developers.line.biz/en/reference/messaging-api/#signature-validation

__init__(channel_secret)[source]

__init__ method.

Parameters

channel_secret (str) – Channel secret (as text)

validate(body, signature)[source]

Check signature.

Parameters
  • body (str) – Request body (as text)

  • signature (str) – X-Line-Signature value (as text)

Return type

bool

class linebot.webhook.WebhookPayload(events=None, destination=None)[source]

Bases: object

Webhook Payload.

https://developers.line.biz/en/reference/messaging-api/#request-body

__init__(events=None, destination=None)[source]

__init__ method.

Parameters
  • events (list[T <= linebot.models.events.Event]) – Information about the events.

  • destination (str) – User ID of a bot that should receive webhook events.

class linebot.webhook.WebhookParser(channel_secret)[source]

Bases: object

Webhook Parser.

__init__(channel_secret)[source]

__init__ method.

Parameters

channel_secret (str) – Channel secret (as text)

parse(body, signature, as_payload=False)[source]

Parse webhook request body as text.

Parameters
  • body (str) – Webhook request body (as text)

  • signature (str) – X-Line-Signature value (as text)

  • as_payload (bool) – (optional) True to return WebhookPayload object.

Return type

list[T <= linebot.models.events.Event] | linebot.webhook.WebhookPayload

Returns

Events list, or WebhookPayload instance

class linebot.webhook.WebhookHandler(channel_secret)[source]

Bases: object

Webhook Handler.

Please read https://github.com/line/line-bot-sdk-python#webhookhandler

__init__(channel_secret)[source]

__init__ method.

Parameters

channel_secret (str) – Channel secret (as text)

add(event, message=None)[source]

Add handler method.

Parameters
  • event (T <= linebot.models.events.Event class) – Specify a kind of Event which you want to handle

  • message – (optional) If event is MessageEvent, specify kind of Messages which you want to handle

Type

message: T <= linebot.models.messages.Message class

Return type

func

Returns

decorator

default()[source]

Set default handler method.

Return type

func

Returns

decorator

handle(body, signature)[source]

Handle webhook.

Parameters
  • body (str) – Webhook request body (as text)

  • signature (str) – X-Line-Signature value (as text)

linebot.exceptions module

linebot.exceptions module.

exception linebot.exceptions.BaseError(message='-')[source]

Bases: Exception

Base Exception class.

__init__(message='-')[source]

__init__ method.

Parameters

message (str) – Human readable message

exception linebot.exceptions.InvalidSignatureError(message='-')[source]

Bases: BaseError

When Webhook signature does NOT match, this error will be raised.

__init__(message='-')[source]

__init__ method.

Parameters

message (str) – Human readable message

exception linebot.exceptions.LineBotApiError(status_code, headers, request_id=None, accepted_request_id=None, error=None)[source]

Bases: BaseError

When LINE Messaging API response error, this error will be raised.

__init__(status_code, headers, request_id=None, accepted_request_id=None, error=None)[source]

__init__ method.

Parameters
  • status_code (int) – HTTP status code

  • headers (dict[str, str]) – Response headers

  • request_id (str) – (optional) Request ID. A unique ID is generated for each request

  • accepted_request_id (str) – (optional) The same request has already been accepted

  • error (linebot.models.error.Error) – (optional) Error class object.

linebot.http_client module

linebot.http_client module.

class linebot.http_client.HttpClient(timeout=5)[source]

Bases: object

Abstract Base Classes of HttpClient.

DEFAULT_TIMEOUT = 5
__init__(timeout=5)[source]

__init__ method.

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is DEFAULT_TIMEOUT

Return type

T <= HttpResponse

Returns

HttpResponse instance

abstract get(url, headers=None, params=None, stream=False, timeout=None)[source]

GET request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • params (dict) – (optional) Request query parameter

  • stream (bool) – (optional) get content as stream

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

T <= HttpResponse

Returns

HttpResponse instance

abstract post(url, headers=None, data=None, timeout=None)[source]

POST request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • data – (optional) Dictionary, bytes, or file-like object to send in the body

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

T <= HttpResponse

Returns

HttpResponse instance

abstract delete(url, headers=None, data=None, timeout=None)[source]

DELETE request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • data – (optional) Dictionary, bytes, or file-like object to send in the body

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

T <= HttpResponse

Returns

HttpResponse instance

abstract put(url, headers=None, data=None, timeout=None)[source]

PUT request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • data – (optional) Dictionary, bytes, or file-like object to send in the body

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

RequestsHttpResponse

Returns

RequestsHttpResponse instance

class linebot.http_client.RequestsHttpClient(timeout=5)[source]

Bases: HttpClient

HttpClient implemented by requests.

__init__(timeout=5)[source]

__init__ method.

Parameters

timeout (float | tuple(float, float)) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is DEFAULT_TIMEOUT

get(url, headers=None, params=None, stream=False, timeout=None)[source]

GET request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • params (dict) – (optional) Request query parameter

  • stream (bool) – (optional) get content as stream

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

RequestsHttpResponse

Returns

RequestsHttpResponse instance

post(url, headers=None, data=None, timeout=None)[source]

POST request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • data – (optional) Dictionary, bytes, or file-like object to send in the body

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

RequestsHttpResponse

Returns

RequestsHttpResponse instance

delete(url, headers=None, data=None, timeout=None)[source]

DELETE request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • data – (optional) Dictionary, bytes, or file-like object to send in the body

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

RequestsHttpResponse

Returns

RequestsHttpResponse instance

put(url, headers=None, data=None, timeout=None)[source]

PUT request.

Parameters
  • url (str) – Request url

  • headers (dict) – (optional) Request headers

  • data – (optional) Dictionary, bytes, or file-like object to send in the body

  • timeout (float | tuple(float, float)) – (optional), How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) float tuple. Default is self.timeout

Return type

RequestsHttpResponse

Returns

RequestsHttpResponse instance

class linebot.http_client.HttpResponse[source]

Bases: object

HttpResponse.

abstract property status_code

Get status code.

abstract property headers

Get headers.

abstract property text

Get response body as text-decoded.

abstract property content

Get response body as binary.

abstract property json

Get response body as json-decoded.

abstract iter_content(chunk_size=1024, decode_unicode=False)[source]

Get response body as iterator content (stream).

Parameters
  • chunk_size (int) –

  • decode_unicode (bool) –

class linebot.http_client.RequestsHttpResponse(response)[source]

Bases: HttpResponse

HttpResponse implemented by requests lib’s response.

__init__(response)[source]

__init__ method.

Parameters

response – requests lib’s response

property status_code

Get status code.

property headers

Get headers.

:rtype requests.models.CaseInsensitiveDict

property text

Get response body as text-decoded.

property content

Get response body as binary.

property json

Get response body as json-decoded.

iter_content(chunk_size=1024, decode_unicode=False)[source]

Get response body as iterator content (stream).

Parameters
  • chunk_size (int) –

  • decode_unicode (bool) –

Subpackages