### Setup and Run Rich Menu Example Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/rich-menu/README.md Instructions for setting up the LINE channel access token, installing dependencies, and running the Python application for rich menu integration. ```bash $ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN $ pip install -r requirements.txt $ python app.py ``` -------------------------------- ### Environment Setup and Dependencies Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/fastapi-echo/README.md Set your LINE channel credentials as environment variables and install the required Python packages. ```bash $ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET $ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN $ pip install -r requirements.txt ``` -------------------------------- ### Environment Setup and Installation Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/aiohttp-echo/README.md Set the LINE_CHANNEL_SECRET and LINE_CHANNEL_ACCESS_TOKEN environment variables. Install the required dependencies using pip. ```bash export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN pip install -r requirements.txt ``` -------------------------------- ### Setup and Run Echo Bot Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/simple-server-echo/README.md Set environment variables for LINE channel credentials, install dependencies, and run the Python application. ```bash $ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET $ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN $ pip install -r requirements.txt $ python app.py ``` -------------------------------- ### Environment Setup and Running the Bot Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/flask-kitchensink/README.md Set LINE channel credentials as environment variables, install dependencies, and run the Flask application. ```bash export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN ``` ```bash pip install -r requirements.txt ``` ```bash python app.py ``` -------------------------------- ### Setup Rich Menu for User Source: https://context7.com/line/line-bot-sdk-python/llms.txt This function guides through the process of creating a rich menu, uploading its background image, and linking it to a specific user. Rich menus provide persistent custom menus in the chat screen. ```APIDOC ## setup_rich_menu_for_user ### Description Sets up a custom rich menu for a specific user. This involves creating the rich menu definition, uploading its image, and linking it to the user ID. Rich menus offer a persistent, interactive menu at the bottom of the chat screen. ### Parameters - **user_id** (str) - Required - The ID of the user to link the rich menu to. - **image_path** (str) - Required - The file path to the rich menu's background image. ### Code Example ```python import os from linebot.v3.messaging import ( Configuration, ApiClient, MessagingApi, MessagingApiBlob, RichMenuRequest, RichMenuArea, RichMenuBounds, RichMenuSize, URIAction, ApiException ) # Assuming configuration is already set up # configuration = Configuration(access_token=os.environ['LINE_CHANNEL_ACCESS_TOKEN']) def setup_rich_menu_for_user(user_id: str, image_path: str): with ApiClient(configuration) as api_client: api = MessagingApi(api_client) blob_api = MessagingApiBlob(api_client) # 1. Create the rich menu definition rich_menu = RichMenuRequest( size=RichMenuSize(width=2500, height=843), selected=True, name='Main Menu', chat_bar_text='Menu', areas=[ RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=1250, height=843), action=URIAction(label='Website', uri='https://example.com') ), RichMenuArea( bounds=RichMenuBounds(x=1250, y=0, width=1250, height=843), action=URIAction(label='Support', uri='https://example.com/support') ), ] ) response = api.create_rich_menu(rich_menu) rich_menu_id = response.rich_menu_id print('Created rich menu:', rich_menu_id) # 2. Upload the background image with open(image_path, 'rb') as f: blob_api.set_rich_menu_image( rich_menu_id=rich_menu_id, body=f.read() ) # 3. Link to a specific user api.link_rich_menu_id_to_user(user_id=user_id, rich_menu_id=rich_menu_id) print(f'Rich menu linked to user {user_id}') # 4. Or set as the default for all users # api.set_default_rich_menu(rich_menu_id=rich_menu_id) ``` ``` -------------------------------- ### Install Dependencies Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/flask-echo/README.md Install the necessary Python packages using pip. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install LINE Bot SDK for Python Source: https://context7.com/line/line-bot-sdk-python/llms.txt Install the SDK using pip. Ensure you have Python 3.10 or higher. ```bash pip install line-bot-sdk ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/line/line-bot-sdk-python/blob/master/CONTRIBUTING.md Installs all necessary dependencies for development and testing using pip. ```bash pip install -r requirements-dev.txt ``` -------------------------------- ### Get List of Rich Menu Aliases using Python SDK Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md This example demonstrates how to retrieve a list of all available rich menu aliases using the LINE Messaging API SDK. It requires Bearer authentication to be set up. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.rich_menu_alias_list_response import RichMenuAliasListResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) ``` -------------------------------- ### Get List of Attached Modules Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/module/docs/LineModule.md Retrieves a list of basic information about bots with attached module channels. Supports pagination with 'start' and 'limit' parameters. Requires Bearer token authentication. ```python import time import os import linebot.v3.module from linebot.v3.module.models.get_modules_response import GetModulesResponse from linebot.v3.module.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.module.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.module.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.module.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.module.LineModule(api_client) start = 'start_example' # str | Value of the continuation token found in the next property of the JSON object returned in the response. If you can't get all basic information about the bots in one request, include this parameter to get the remaining array. (optional) limit = 100 # int | Specify the maximum number of bots that you get basic information from. The default value is 100. Max value: 100 (optional) (default to 100) try: api_response = api_instance.get_modules(start=start, limit=limit) print("The response of LineModule->get_modules:\n") pprint(api_response) except Exception as e: print("Exception when calling LineModule->get_modules: %s\n" % e) ``` -------------------------------- ### Run WebhookParser Sample Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/aiohttp-echo/README.md Execute the main application file to start the echo bot. ```bash python app.py ``` -------------------------------- ### get_modules Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/module/docs/LineModule.md Gets a list of basic information about the bots of multiple LINE Official Accounts that have attached module channels. Supports pagination with start and limit parameters. ```APIDOC ## GET /v3/bot/module/list ### Description Gets a list of basic information about the bots of multiple LINE Official Accounts that have attached module channels. ### Method GET ### Endpoint /v3/bot/module/list ### Parameters #### Query Parameters - **start** (str) - Optional - Value of the continuation token found in the next property of the JSON object returned in the response. If you can't get all basic information about the bots in one request, include this parameter to get the remaining array. - **limit** (int) - Optional - Specify the maximum number of bots that you get basic information from. The default value is 100. Max value: 100 ### Response #### Success Response (200) - **GetModulesResponse** - Details of the response model can be found in [GetModulesResponse](GetModulesResponse.md) ### Authorization Bearer Token ``` -------------------------------- ### Test Webhook Endpoint API Example Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Provides an example for testing the webhook endpoint using the LINE Messaging API. This requires Bearer token authentication. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.test_webhook_endpoint_request import TestWebhookEndpointRequest from linebot.v3.messaging.models.test_webhook_endpoint_response import TestWebhookEndpointResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) ``` -------------------------------- ### Get Membership List Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of all available membership plans associated with the bot. ```APIDOC ## GET /v3/messaging/membership/list ### Description Retrieves a list of all available membership plans associated with the bot. ### Method GET ### Endpoint /v3/messaging/membership/list ### Parameters This endpoint does not require any parameters. ### Request Example ```python import linebot.v3.messaging import os configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) with linebot.v3.messaging.ApiClient(configuration) as api_client: api_instance = linebot.v3.messaging.MessagingApi(api_client) try: api_response = api_instance.get_membership_list() print(api_response) except Exception as e: print(e) ``` ### Response #### Success Response (200) - **MembershipListResponse** (object) - Details about the response object can be found in the [MembershipListResponse](MembershipListResponse.md) documentation. #### Response Example ```json { "memberships": [ { "id": "12345", "name": "Premium Plan", "price": 500, "currency": "JPY" } ] } ``` ### Error Handling - **404**: Unable to get information about the memberships. ``` -------------------------------- ### Get Rich Menu List Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of all rich menus created for the bot. ```APIDOC ## GET /v2/bot/richmenu/list ### Description Retrieves a list of all rich menus created for the bot. ### Method GET ### Endpoint /v2/bot/richmenu/list ### Response #### Success Response (200) - **richmenus** (array) - A list of rich menu objects. #### Response Example { "richmenus": [ { "richMenuId": "abc123def456", "size": {"width": 2500, "height": 1686}, "selected": true, "name": "Example Rich Menu", "chatBarText": "Tap to open" } ] } ``` -------------------------------- ### Get Number of Sent Push Messages Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves the number of push messages sent on a specific date. This example demonstrates Bearer token authentication setup. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.number_of_messages_response import NumberOfMessagesResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Optional: Defining the host if not using the default configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # Configuring Bearer authorization with the access token configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # The rest of the code for calling the API would follow here, similar to other examples. ``` -------------------------------- ### Get Joined Membership Users - Python Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of user IDs who have joined a specific membership. Supports pagination with start and limit parameters. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.get_joined_membership_users_response import GetJoinedMembershipUsersResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. ``` -------------------------------- ### Run FastAPI Application Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/fastapi-echo/README.md Start the FastAPI development server to run the echo bot sample. ```bash $ uvicorn main:app --reload ``` -------------------------------- ### Get Followers List Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Fetches a list of users who have added your LINE Official Account as a friend. Supports pagination using 'start' and 'limit' parameters. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.get_followers_response import GetFollowersResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) with linebot.v3.messaging.ApiClient(configuration) as api_client: api_instance = linebot.v3.messaging.MessagingApi(api_client) start = 'start_example' limit = 300 try: api_response = api_instance.get_followers(start=start, limit=limit) print("The response of MessagingApi->get_followers:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->get_followers: %s\n" % e) ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/flask-echo/README.md Before running the bot, set your LINE channel secret and access token as environment variables. ```bash export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN ``` -------------------------------- ### Get Aggregation Unit Name List Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of aggregation units with optional limit and start parameters. Use this to paginate through available aggregation units. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.messaging.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.messaging.MessagingApi(api_client) limit = 'limit_example' # str | The maximum number of aggregation units you can get per request. (optional) start = 'start_example' # str | Value of the continuation token found in the next property of the JSON object returned in the response. If you can't get all the aggregation units in one request, include this parameter to get the remaining array. (optional) try: api_response = api_instance.get_aggregation_unit_name_list(limit=limit, start=start) print("The response of MessagingApi->get_aggregation_unit_name_list:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->get_aggregation_unit_name_list: %s\n" % e) ``` -------------------------------- ### Get Group Member IDs (Python) Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of user IDs for members within a group. Supports pagination using the 'start' parameter for large groups. ```python import linebot.v3.messaging from linebot.v3.messaging.models.members_ids_response import MembersIdsResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) ``` -------------------------------- ### Get Room Member IDs using Python SDK Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of user IDs for members within a specified room. Supports pagination using the 'start' parameter. Bearer authentication is required. ```python import linebot.v3.messaging from linebot.v3.messaging.models.members_ids_response import MembersIdsResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) ``` -------------------------------- ### Show Loading Animation API Example Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Demonstrates how to display a loading animation in one-on-one chats using the LINE Messaging API. Ensure Bearer token authentication is configured. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.show_loading_animation_request import ShowLoadingAnimationRequest from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.messaging.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.messaging.MessagingApi(api_client) show_loading_animation_request = linebot.v3.messaging.ShowLoadingAnimationRequest() # ShowLoadingAnimationRequest | try: api_response = api_instance.show_loading_animation(show_loading_animation_request) print("The response of MessagingApi->show_loading_animation:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->show_loading_animation: %s\n" % e) ``` -------------------------------- ### Initialize API Client and Configuration for Bearer Token Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/audience/docs/ManageAudience.md Sets up the API client configuration using a Bearer token for authentication. This is a prerequisite for making authenticated API calls. ```python configuration = linebot.v3.audience.Configuration( host = "https://api.line.me" ) configuration = linebot.v3.audience.Configuration( access_token = os.environ["BEARER_TOKEN"] ) ``` -------------------------------- ### Get Joined Membership Users (Python) Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of user IDs who have joined a specific membership plan. Supports pagination with `start` and `limit` parameters. Ensure the `BEARER_TOKEN` environment variable is set for authentication. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.rest import ApiException from pprint import pprint # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.messaging.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.messaging.MessagingApi(api_client) membership_id = 56 # int | Membership plan ID. start = 'start_example' # str | A continuation token to get next remaining membership user IDs. Returned only when there are remaining user IDs that weren't returned in the userIds property in the previous request. The continuation token expires in 24 hours (86,400 seconds). (optional) limit = 300 # int | The max number of items to return for this API call. The value is set to 300 by default, but the max acceptable value is 1000. (optional) (default to 300) try: api_response = api_instance.get_joined_membership_users(membership_id, start=start, limit=limit) print("The response of MessagingApi->get_joined_membership_users:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->get_joined_membership_users: %s\n" % e) ``` -------------------------------- ### Setup Rich Menu for a User Source: https://context7.com/line/line-bot-sdk-python/llms.txt This function creates a rich menu, uploads its background image, and links it to a specific user. It requires the user ID and the path to the image file. The rich menu definition includes size, selection state, name, chat bar text, and interactive areas with actions. ```python import os from linebot.v3.messaging import ( Configuration, ApiClient, MessagingApi, MessagingApiBlob, RichMenuRequest, RichMenuArea, RichMenuBounds, RichMenuSize, URIAction, ApiException ) configuration = Configuration(access_token=os.environ['LINE_CHANNEL_ACCESS_TOKEN']) def setup_rich_menu_for_user(user_id: str, image_path: str): with ApiClient(configuration) as api_client: api = MessagingApi(api_client) blob_api = MessagingApiBlob(api_client) # 1. Create the rich menu definition rich_menu = RichMenuRequest( size=RichMenuSize(width=2500, height=843), selected=True, name='Main Menu', chat_bar_text='Menu', areas=[ RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=1250, height=843), action=URIAction(label='Website', uri='https://example.com') ), RichMenuArea( bounds=RichMenuBounds(x=1250, y=0, width=1250, height=843), action=URIAction(label='Support', uri='https://example.com/support') ), ] ) response = api.create_rich_menu(rich_menu) rich_menu_id = response.rich_menu_id print('Created rich menu:', rich_menu_id) # 2. Upload the background image with open(image_path, 'rb') as f: blob_api.set_rich_menu_image( rich_menu_id=rich_menu_id, body=f.read() ) # 3. Link to a specific user api.link_rich_menu_id_to_user(user_id=user_id, rich_menu_id=rich_menu_id) print(f'Rich menu linked to user {user_id}') # 4. Or set as the default for all users # api.set_default_rich_menu(rich_menu_id=rich_menu_id) ``` -------------------------------- ### Get Aggregation Unit Name List using Messaging API Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Retrieves a list of unit names used this month. This function supports optional limit and start parameters for pagination and requires Bearer authentication. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.get_aggregation_unit_name_list_response import GetAggregationUnitNameListResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) ``` -------------------------------- ### Run Echo Bot with WebhookHandler Source: https://github.com/line/line-bot-sdk-python/blob/master/examples/flask-echo/README.md Execute the application file to start the echo bot using the WebhookHandler for more structured event processing. ```bash python app_with_handler.py ``` -------------------------------- ### Attach Module using Basic Authentication Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/moduleattach/docs/LineModuleAttach.md Demonstrates how to attach a module using basic authentication. Ensure your LINE Developers Console credentials and redirect URIs are correctly configured. This snippet shows how to set up the API client, define parameters, and make the attach_module call. ```python import time import os import linebot.v3.moduleattach from linebot.v3.moduleattach.models.attach_module_response import AttachModuleResponse from linebot.v3.moduleattach.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://manager.line.biz # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.moduleattach.Configuration( host = "https://manager.line.biz" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure HTTP basic authorization: basicAuth configuration = linebot.v3.moduleattach.Configuration( username = os.environ["USERNAME"], password = os.environ["PASSWORD"] ) # Enter a context with an instance of the API client with linebot.v3.moduleattach.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.moduleattach.LineModuleAttach(api_client) grant_type = 'grant_type_example' # str | authorization_code code = 'code_example' # str | Authorization code received from the LINE Platform. redirect_uri = 'redirect_uri_example' # str | Specify the redirect_uri specified in the URL for authentication and authorization. code_verifier = 'code_verifier_example' # str | Specify when using PKCE (Proof Key for Code Exchange) defined in the OAuth 2.0 extension specification as a countermeasure against authorization code interception attacks. (optional) client_id = 'client_id_example' # str | Instead of using Authorization header, you can use this parameter to specify the channel ID of the module channel. You can find the channel ID of the module channel in the LINE Developers Console. (optional) client_secret = 'client_secret_example' # str | Instead of using Authorization header, you can use this parameter to specify the channel secret of the module channel. You can find the channel secret of the module channel in the LINE Developers Console. (optional) region = 'region_example' # str | If you specified a value for region in the URL for authentication and authorization, specify the same value. (optional) basic_search_id = 'basic_search_id_example' # str | If you specified a value for basic_search_id in the URL for authentication and authorization, specify the same value. (optional) scope = 'scope_example' # str | If you specified a value for scope in the URL for authentication and authorization, specify the same value. (optional) brand_type = 'brand_type_example' # str | If you specified a value for brand_type in the URL for authentication and authorization, specify the same value. (optional) try: api_response = api_instance.attach_module(grant_type, code, redirect_uri, code_verifier=code_verifier, client_id=client_id, client_secret=client_secret, region=region, basic_search_id=basic_search_id, scope=scope, brand_type=brand_type) print("The response of LineModuleAttach->attach_module:\n") pprint(api_response) except Exception as e: print("Exception when calling LineModuleAttach->attach_module: %s\n" % e) ``` -------------------------------- ### Create Coupon using Bearer Authentication Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Shows how to create a new coupon using the MessagingApi. This example uses Bearer token authentication and requires the BEARER_TOKEN environment variable to be set. The CouponCreateRequest object can be customized with coupon details. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.coupon_create_request import CouponCreateRequest from linebot.v3.messaging.models.coupon_create_response import CouponCreateResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.messaging.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.messaging.MessagingApi(api_client) coupon_create_request = linebot.v3.messaging.CouponCreateRequest() # CouponCreateRequest | (optional) try: api_response = api_instance.create_coupon(coupon_create_request=coupon_create_request) print("The response of MessagingApi->create_coupon:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->create_coupon: %s\n" % e) ``` -------------------------------- ### Get Message Quota Consumption using Bearer Token Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md This example demonstrates how to retrieve the current month's message consumption count using Bearer token authentication. Ensure the BEARER_TOKEN environment variable is set. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.quota_consumption_response import QuotaConsumptionResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint ``` -------------------------------- ### Get Membership List (Python) Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Fetches a list of all available membership plans. This endpoint requires Bearer token authentication. The `BEARER_TOKEN` environment variable must be configured. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.membership_list_response import MembershipListResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.messaging.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.messaging.MessagingApi(api_client) try: api_response = api_instance.get_membership_list() print("The response of MessagingApi->get_membership_list:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->get_membership_list: %s\n" % e) ``` -------------------------------- ### Get Statistics Per Unit - Python Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/insight/docs/Insight.md Fetches per-unit statistics for push and multicast messages. Requires Bearer authentication and an initialized ApiClient. Specify the custom aggregation unit name, start date, and end date (within 30 days). Dates must be in yyyyMMdd format (UTC+9). ```python import time import os import linebot.v3.insight from linebot.v3.insight.models.get_statistics_per_unit_response import GetStatisticsPerUnitResponse from linebot.v3.insight.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.insight.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.insight.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.insight.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.insight.Insight(api_client) custom_aggregation_unit = 'Promotion_a' # str | Name of aggregation unit specified when sending the message. Case-sensitive. For example, `Promotion_a` and `Promotion_A` are regarded as different unit names. var_from = '20210301' # str | Start date of aggregation period. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9 to = '20210331' # str | End date of aggregation period. The end date can be specified for up to 30 days later. For example, if the start date is 20210301, the latest end date is 20210331. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9 try: api_response = api_instance.get_statistics_per_unit(custom_aggregation_unit, var_from, to) print("The response of Insight->get_statistics_per_unit:\n") pprint(api_response) except ApiException as e: print("Exception when calling Insight->get_statistics_per_unit: %s\n" % e) ``` -------------------------------- ### Create LIFF App using Python SDK Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/liff/docs/Liff.md Use this snippet to create a new LIFF app for your LINE channel. Ensure you have your Bearer token configured in your environment variables. ```python import time import os import linebot.v3.liff from linebot.v3.liff.models.add_liff_app_request import AddLiffAppRequest from linebot.v3.liff.models.add_liff_app_response import AddLiffAppResponse from linebot.v3.liff.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.liff.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.liff.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.liff.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.liff.Liff(api_client) add_liff_app_request = linebot.v3.liff.AddLiffAppRequest() # AddLiffAppRequest | try: # Create LIFF app api_response = api_instance.add_liff_app(add_liff_app_request) print("The response of Liff->add_liff_app:\n") pprint(api_response) except Exception as e: print("Exception when calling Liff->add_liff_app: %s\n" % e) ``` -------------------------------- ### Basic Flask Webhook Server for LINE Bot Source: https://github.com/line/line-bot-sdk-python/blob/master/README.rst Sets up a Flask application to receive and handle LINE webhook events. Requires channel access token and secret for configuration. ```python from flask import Flask, request, abort from linebot.v3 import ( WebhookHandler ) from linebot.v3.exceptions import ( InvalidSignatureError ) from linebot.v3.messaging import ( Configuration, ApiClient, MessagingApi, ReplyMessageRequest, TextMessage ) from linebot.v3.webhooks import ( MessageEvent, TextMessageContent ) app = Flask(__name__) configuration = Configuration(access_token='YOUR_CHANNEL_ACCESS_TOKEN') handler = WebhookHandler('YOUR_CHANNEL_SECRET') @app.route("/callback", methods=['POST']) def callback(): # get X-Line-Signature header value signature = request.headers['X-Line-Signature'] # get request body as text body = request.get_data(as_text=True) app.logger.info("Request body: " + body) # handle webhook body try: handler.handle(body, signature) except InvalidSignatureError: app.logger.info("Invalid signature. Please check your channel access token/channel secret.") abort(400) return 'OK' @handler.add(MessageEvent, message=TextMessageContent) def handle_message(event): with ApiClient(configuration) as api_client: line_bot_api = MessagingApi(api_client) line_bot_api.reply_message_with_http_info( ReplyMessageRequest( reply_token=event.reply_token, messages=[TextMessage(text=event.message.text)] ) ) if __name__ == "__main__": app.run() ``` -------------------------------- ### Create Rich Menu using Bearer Authentication Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Example of creating a rich menu using the MessagingApi with Bearer token authentication. Ensure the BEARER_TOKEN environment variable is configured. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.rich_menu_id_response import RichMenuIdResponse from linebot.v3.messaging.models.rich_menu_request import RichMenuRequest from linebot.v3.messaging.rest import ApiException from pprint import pprint ``` -------------------------------- ### Get Narrowcast Progress Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Gets the status of a narrowcast message using its request ID. ```APIDOC ## GET /v3/bot/message/narrowcast/progress/{request_id} ### Description Gets the status of a narrowcast message using its request ID. ### Method GET ### Endpoint /v3/bot/message/narrowcast/progress/{request_id} ### Parameters #### Path Parameters - **request_id** (str) - Required - The narrowcast message's request ID. Each Messaging API request has a request ID. ### Request Example ```python import linebot.v3.messaging from linebot.v3.messaging.rest import ApiException from pprint import pprint configuration = linebot.v3.messaging.Configuration( access_token = 'YOUR_ACCESS_TOKEN' ) with linebot.v3.messaging.ApiClient(configuration) as api_client: api_instance = linebot.v3.messaging.MessagingApi(api_client) request_id = 'example_request_id' try: api_response = api_instance.get_narrowcast_progress(request_id) pprint(api_response) except ApiException as e: print("Exception when calling MessagingApi->get_narrowcast_progress: %s\n" % e) ``` ### Response #### Success Response (200) - **data** (NarrowcastProgressResponse) - OK #### Response Example ```json { "status": "SUCCEEDED", "success": 100, "failure": 0 } ``` ``` -------------------------------- ### Initialize WebhookParser Source: https://github.com/line/line-bot-sdk-python/blob/master/README.rst Instantiates a WebhookParser with a channel secret. The `skip_signature_verification` option can be provided to disable signature checks. ```python parser = linebot.v3.WebhookParser('YOUR_CHANNEL_SECRET') ``` ```python parser = linebot.v3.WebhookParser( 'YOUR_CHANNEL_SECRET', skip_signature_verification=lambda: False ) ``` -------------------------------- ### Get Number of Sent Broadcast Messages Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Get the number of broadcast messages sent on a specific date. ```APIDOC ## GET /v3/bot/message/broadcast/completion ### Description Get the number of broadcast messages sent on a specific date. ### Method GET ### Endpoint /v3/bot/message/broadcast/completion ### Parameters #### Query Parameters - **date** (str) - Required - The date for which to retrieve the message count. Format: YYYYMMDD ### Request Example ```python import linebot.v3.messaging from linebot.v3.messaging.rest import ApiException from pprint import pprint configuration = linebot.v3.messaging.Configuration( access_token = 'YOUR_ACCESS_TOKEN' ) with linebot.v3.messaging.ApiClient(configuration) as api_client: api_instance = linebot.v3.messaging.MessagingApi(api_client) date = '20230101' try: api_response = api_instance.get_number_of_sent_broadcast_messages(date) pprint(api_response) except ApiException as e: print("Exception when calling MessagingApi->get_number_of_sent_broadcast_messages: %s\n" % e) ``` ### Response #### Success Response (200) - **data** (NumberOfMessagesResponse) - OK #### Response Example ```json { "status": "SUCCEEDED", "success": 10000 } ``` ``` -------------------------------- ### Check README Syntax Source: https://github.com/line/line-bot-sdk-python/blob/master/CONTRIBUTING.md Renders the README.rst file to check for syntax errors before committing documentation changes. ```bash python -m readme_renderer README.rst ``` -------------------------------- ### Create Rich Menu - Python Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Use this snippet to create a new rich menu. Ensure your authentication token is set in the environment variable BEARER_TOKEN. The host can be configured if not using the default. ```python import linebot.v3.messaging from linebot.v3.messaging.rest import ApiException from pprint import pprint import os configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) with linebot.v3.messaging.ApiClient(configuration) as api_client: api_instance = linebot.v3.messaging.MessagingApi(api_client) rich_menu_request = linebot.v3.messaging.RichMenuRequest() try: api_response = api_instance.create_rich_menu(rich_menu_request) print("The response of MessagingApi->create_rich_menu:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->create_rich_menu: %s\n" % e) ``` -------------------------------- ### Get Aggregation Unit Name List Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApi.md Gets the name list of units used this month. This is useful for analyzing usage patterns. ```APIDOC ## GET /v2/bot/management/aggregation/unit/name ### Description Get name list of units used this month. ### Method GET ### Endpoint /v2/bot/management/aggregation/unit/name ### Parameters #### Query Parameters - **limit** (int) - Optional - The maximum number of unit names to return. - **start** (str) - Optional - The cursor for the next page of results. ### Request Example ```python import os import linebot.v3.messaging from linebot.v3.messaging.models.get_aggregation_unit_name_list_response import GetAggregationUnitNameListResponse configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) with linebot.v3.messaging.ApiClient(configuration) as api_client: api_instance = linebot.v3.messaging.MessagingApi(api_client) try: api_response = api_instance.get_aggregation_unit_name_list() pprint(api_response) except Exception as e: print("Exception when calling MessagingApi->get_aggregation_unit_name_list: %s\n" % e) ``` ### Response #### Success Response (200) - **items** (list[str]) - A list of unit names. - **next** (str) - A cursor for the next page of results. If null, there are no more pages. #### Response Example ```json { "items": [ "unit_name_1", "unit_name_2" ], "next": "cursor_for_next_page" } ``` ``` -------------------------------- ### Get Message Content Transcoding Status Source: https://github.com/line/line-bot-sdk-python/blob/master/linebot/v3/messaging/docs/MessagingApiBlob.md Verify the preparation status of a video or audio for getting. Requires Bearer authentication and the message ID. ```python import time import os import linebot.v3.messaging from linebot.v3.messaging.models.get_message_content_transcoding_response import GetMessageContentTranscodingResponse from linebot.v3.messaging.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://api.line.me # See configuration.py for a list of all supported configuration parameters. configuration = linebot.v3.messaging.Configuration( host = "https://api.line.me" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure Bearer authorization: Bearer configuration = linebot.v3.messaging.Configuration( access_token = os.environ["BEARER_TOKEN"] ) # Enter a context with an instance of the API client with linebot.v3.messaging.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = linebot.v3.messaging.MessagingApiBlob(api_client) message_id = 'message_id_example' # str | Message ID of video or audio try: api_response = api_instance.get_message_content_transcoding_by_message_id(message_id) print("The response of MessagingApiBlob->get_message_content_transcoding_by_message_id:\n") pprint(api_response) except Exception as e: print("Exception when calling MessagingApiBlob->get_message_content_transcoding_by_message_id: %s\n" % e) ```