### Install Dependencies and Start LIFF App Development Server Source: https://developers.line.biz/en/docs/liff/cli-tool-create-liff-app/index.html After initializing the LIFF app, these commands are used to install project dependencies and start the local development server. The app will then be accessible at a local URL. ```bash cd my-app yarn install yarn dev ``` ```bash cd my-app npm install npm run dev ``` -------------------------------- ### LIFF Plugin Install Method Example Source: https://developers.line.biz/en/docs/liff/liff-plugin/index.html Demonstrates the structure of a LIFF plugin's 'install' method. It shows how to define plugin methods and register callbacks for 'before' and 'after' hooks of the 'liff.init()' method. The callbacks must return Promises as they are async hooks. ```javascript class GreetPlugin { constructor() { this.name = "greet"; } install(context) { context.hooks.init.before(this.initBefore); context.hooks.init.after(this.initAfter); return { hello: this.hello, goodbye: this.goodbye, }; } hello() { console.log("Hello, World!"); } goodbye() { console.log("Goodbye, World!"); } initBefore() { console.log("before hook is called"); return Promise.resolve(); } initAfter() { console.log("after hook is called"); return Promise.resolve(); } } liff.use(new GreetPlugin()); liff .init({ liffId: "123456-abcedfg", // Use own liffId }) .then(() => { // ... }); ``` -------------------------------- ### Install Dependencies and Run LIFF App (Yarn) Source: https://developers.line.biz/en/docs/liff/trying-liff-app/index.html Installs the necessary project dependencies using Yarn and then launches the LIFF application in development mode. This process prepares the app for local testing and development, typically starting a local server. ```bash yarn install yarn dev ``` -------------------------------- ### Basic LIFF Plugin Install Method Source: https://developers.line.biz/en/docs/liff/liff-plugin/index.html A minimal example of a LIFF plugin's 'install' method. This serves as a basic template for creating plugins, showing the method signature and a placeholder for functionality. ```javascript class GreetPlugin { constructor() { this.name = "greet"; } install(context, option) {} } ``` -------------------------------- ### Tutorial - Make a Reply Bot (Node.js) Source: https://context7_llms A practical tutorial to build a basic LINE bot using Node.js that can reply to user messages. Ideal for beginners getting started with bot development. ```APIDOC ## Tutorial - Make a Reply Bot (Node.js) ### Description This tutorial provides a step-by-step guide to creating a simple LINE bot using Node.js that automatically replies to incoming messages. It covers setting up a development environment, handling webhooks, and responding to users. ### Prerequisites - Node.js installed - A LINE Developers account and a channel created - Basic knowledge of JavaScript ### Steps 1. **Set up your Node.js project**. 2. **Install necessary packages** (e.g., `express`, `@line/bot-sdk`). 3. **Configure your bot** with channel access token and secret. 4. **Implement a webhook handler** to receive messages. 5. **Write logic to process incoming messages** and formulate replies. 6. **Deploy your bot** to a server. 7. **Verify your webhook URL** in the LINE Developers console. ### Further Resources Refer to the official LINE Messaging API documentation for detailed API reference and examples. ``` -------------------------------- ### Complete Express.js server setup for LINE bot Source: https://developers.line.biz/en/docs/messaging-api/nodejs-sample/index.html This is the complete `index.js` file content, demonstrating a basic Express.js server setup for a LINE bot. It includes necessary middleware for JSON and URL-encoded data, defines routes for health checks and webhooks, and starts the server listener. ```javascript const https = require("https"); const express = require("express"); const app = express(); const PORT = process.env.PORT || 3000; const TOKEN = process.env.LINE_ACCESS_TOKEN; app.use(express.json()); app.use( express.urlencoded({ extended: true, }) ); app.get("/", (req, res) => { res.sendStatus(200); }); app.post("/webhook", function (req, res) { res.send("HTTP POST request sent to the webhook URL!"); }); app.listen(PORT, () => { console.log(`Example app listening at http://localhost:${PORT}`); }); ``` -------------------------------- ### LiffError Example: Plugin Not Installed Source: https://developers.line.biz/en/reference/line-mini-app/index.html This JavaScript code shows an example of a LiffError that occurs when the 'LiffCommonProfilePlugin' is not correctly installed or used before calling the API. ```javascript new Error( "LiffCommonProfilePlugin isn't installed properly. Did you call liff.use(new LiffCommonProfilePlugin()) before using it?" ); ``` -------------------------------- ### Example Response for Get Group Member Count (JSON) Source: https://developers.line.biz/en/reference/messaging-api/index.html An example JSON response for the 'Get number of users in a group chat' endpoint, indicating the 'count' of members in the group. The count excludes the LINE Official Account. ```json { "count": 3 } ``` -------------------------------- ### Tutorial - Create a Digital Business Card with Flex Message Simulator Source: https://context7_llms A tutorial demonstrating how to use the Flex Message Simulator to test and preview Flex Messages, using a digital business card as an example. ```APIDOC ## Tutorial - Create a Digital Business Card with Flex Message Simulator ### Description This tutorial guides you through creating a digital business card using Flex Messages and testing its appearance with the Flex Message Simulator. It's a practical way to learn Flex Message design. ### Objective To design a visually appealing digital business card within a Flex Message that displays contact information, a profile picture, and potentially action buttons (like call or email). ### Steps 1. **Access the Flex Message Simulator**: Go to the [Flex Message Simulator URL](https://developers.line.biz/flex-simulator/). 2. **Start Designing**: Begin by adding a `Bubble` container. 3. **Add Components**: Use `Box`, `Image`, `Text`, and `Button` elements to structure your business card. For example: - A header `Box` for the profile picture. - A body `Box` for name, title, and contact details. - A footer `Box` for action buttons (e.g., "Call", "Website"). 4. **Configure Actions**: Assign appropriate actions to buttons (e.g., `tel:` for call, `URIAction` for website). 5. **Preview and Iterate**: Use the simulator's preview pane to see how your design renders. Adjust layout, spacing, and styling as needed. 6. **Generate JSON**: Once satisfied, copy the generated JSON payload to use in your bot's message sending logic. ### Key Flex Elements Used - `Bubble`, `Box`, `Image`, `Text`, `Button`, `Separator` - `URIAction`, `TelAction` ``` -------------------------------- ### Initialize npm Project with package.json (sh) Source: https://developers.line.biz/en/docs/messaging-api/nodejs-sample/index.html Initializes a new npm project and creates a package.json file with default settings. The '-y' flag skips interactive prompts, applying default configurations. ```sh npm init -y ``` -------------------------------- ### Install mkcert for Local Certificates Source: https://developers.line.biz/en/docs/liff/liff-cli/index.html Install mkcert, a tool for creating valid local SSL/TLS certificates. This is a prerequisite for the `liff-cli serve` command to operate correctly. The example shows installation on macOS using Homebrew. ```bash # For macOS (using Homebrew) $ brew install mkcert ``` -------------------------------- ### Get Membership Plans Request Example (Shell) Source: https://developers.line.biz/en/reference/messaging-api/index.html Example cURL command to retrieve a list of membership plans currently being offered. Requires an Authorization header with a bearer token. ```sh curl -v -X GET https://api.line.me/v2/bot/membership/list \ -H 'Authorization: Bearer {channel access token}' ``` -------------------------------- ### Configure start script in package.json (json) Source: https://developers.line.biz/en/docs/messaging-api/nodejs-sample/index.html Updates the package.json file to include a 'start' script. This script defines the command to run the server, typically 'node index.js', which is used by deployment platforms. ```json { "name": "sample-app", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" } ``` -------------------------------- ### Error Handling: LiffCommonProfilePlugin Not Installed (JavaScript) Source: https://developers.line.biz/en/reference/line-mini-app/index.html Example of a LiffError when the LiffCommonProfilePlugin is not correctly installed or used before other Common Profile API calls. ```javascript new Error("LiffCommonProfilePlugin isn't installed properly. Did you call liff.use(new LiffCommonProfilePlugin()) before using it?"); ``` -------------------------------- ### Get Follower IDs Error Response Example (JSON) Source: https://developers.line.biz/en/reference/messaging-api/index.html Example JSON error response when a non-existent membership ID is provided. This indicates a 404 Not Found error, suggesting the specified membership ID does not exist. ```json // If you specify a membership ID that doesn't exist in the membershipId path parameter (404 Not Found) { "message": "Membership ID is not found" } ``` -------------------------------- ### Initialize and Create Heroku App Source: https://developers.line.biz/en/docs/messaging-api/nodejs-sample/index.html These commands set up a new directory for your application, initialize Git version control, and create a new application on Heroku. Replace '{Name of your app}' with a unique name for your Heroku application. A Heroku URL will be generated upon successful creation. ```sh mkdir sample-app cd sample-app git init heroku create {Name of your app} ``` -------------------------------- ### Initialize and Use Quick-fill LIFF Plugin (JavaScript) Source: https://developers.line.biz/en/docs/line-mini-app/quick-fill/overview/index.html This snippet demonstrates how to enable and use the Quick-fill LIFF plugin within a LINE MINI App. It initializes the LIFF SDK, registers the common profile plugin, and shows how to retrieve and fill common profile data using the provided API methods. Ensure you have the correct LIFF ID and necessary permissions. ```javascript liff.use(new LiffCommonProfilePlugin()); await liff.init({ liffId: "xxx" }); const { data, error } = await liff.$commonProfile.get(); liff.$commonProfile.fill(data); ``` -------------------------------- ### Request Example for Getting Rich Menu Alias Information Source: https://developers.line.biz/en/reference/messaging-api/index.html Demonstrates how to retrieve information for a specific rich menu alias using a curl command. It includes the necessary GET request to the API endpoint and the authorization header. ```shell # Example of when you want to get the information of rich menu alias A curl -v -X GET https://api.line.me/v2/bot/richmenu/alias/richmenu-alias-a \ -H 'Authorization: Bearer {channel access token}' ``` -------------------------------- ### Install and Integrate Quick-fill via npm Source: https://developers.line.biz/en/docs/line-mini-app/quick-fill/overview/index.html To use Quick-fill with the npm package, first install the `@line/liff-common-profile-plugin` package. Then, import both the `liff` SDK and the `LiffCommonProfilePlugin` class into your JavaScript file. Initialize the plugin by passing an instance to `liff.use()`. ```bash $ npm install @line/liff-common-profile-plugin ``` ```javascript import liff from "@line/liff"; import { LiffCommonProfilePlugin } from "@line/liff-common-profile-plugin"; liff.use(new LiffCommonProfilePlugin()); const { data, error } = await liff.$commonProfile.get(); liff.$commonProfile.fill(data); ``` -------------------------------- ### LIFF Plugin Installation Source: https://developers.line.biz/en/docs/liff/liff-plugin/index.html Demonstrates how to create a LIFF plugin and install it using the `liff.use()` method. The `install` method accepts `context` and `option` objects and can expose plugin methods. ```APIDOC ## LIFF Plugin Installation ### Description This section details the `install` method of a LIFF plugin, which is used to set up the plugin's functionality. It receives a `context` object for accessing LIFF features and hooks, and an optional `option` object for customization. The `install` method can also return an object containing methods that will be exposed by the plugin. ### Method `install(context, option)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript class GreetPlugin { constructor() { this.name = "greet"; } install(context, option) { // Plugin setup logic here return { hello: this.hello, goodbye: this.goodbye, }; } hello() { console.log("Hello, World!"); } goodbye() { console.log("Goodbye, World!"); } } liff.use(new GreetPlugin()); ``` ### Response #### Success Response (200) N/A (This is a method definition, not an API endpoint call) #### Response Example N/A ``` -------------------------------- ### Get Multi-person Chat Member IDs Request (Shell) Source: https://developers.line.biz/en/reference/messaging-api/index.html This example shows how to make a GET request to the LINE Messaging API to retrieve user IDs of members in a multi-person chat. It includes authorization and pagination parameters. ```shell curl -v -X GET 'https://api.line.me/v2/bot/room/{roomId}/members/ids?start={continuationToken}' \ -H 'Authorization: Bearer {channel access token}' ``` -------------------------------- ### Get Audience Group Properties Example (JSON) Source: https://developers.line.biz/en/reference/messaging-api/index.html Provides JSON examples demonstrating the structure and content of audience group properties. The examples showcase different types of audiences, including those for uploading user IDs, message clicks, and app events, illustrating how properties vary based on the audience type. ```json { "audienceGroup": { "audienceGroupId": 1234567890123, "createRoute": "OA_MANAGER", "type": "UPLOAD", "description": "audienceGroupName_01", "status": "READY", "audienceCount": 1887, "created": 1608617466, "permission": "READ", "isIfaAudience": false, "expireTimestamp": 1624342266 }, "jobs": [ { "audienceGroupJobId": 12345678, "audienceGroupId": 1234567890123, "description": "audience_list.txt", "type": "DIFF_ADD", "status": "FINISHED", "failedType": null, "audienceCount": 0, "created": 1608617472, "jobStatus": "FINISHED" } ] } // Example of a message click audience { "audienceGroup": { "audienceGroupId": 1234567890987, "createRoute": "OA_MANAGER", "type": "CLICK", "description": "audienceGroupName_02", "status": "IN_PROGRESS", "audienceCount": 8619, "created": 1611114828, "permission": "READ", "isIfaAudience": false, "expireTimestamp": 1626753228, "requestId": "c10c3d86-f565-...", "clickUrl": "https://example.com/" }, "jobs": [] } // Example of an audience used for app events { "audienceGroup": { "audienceGroupId": 2345678909876, "createRoute": "AD_MANAGER", "type": "APP_EVENT", "description": "audienceGroupName_03", "status": "READY", "audienceCount": 8619, "created": 1608619802, "permission": "READ", "activated": 1610068515, "inactiveTimestamp": 1625620516, "isIfaAudience": false }, "jobs": [], "adaccount": { "name": "Ad Account Name" } } ``` -------------------------------- ### Install jwx Command Line Tool Source: https://developers.line.biz/en/docs/messaging-api/generate-json-web-token/index.html Installs the jwx command-line tool by cloning the repository, navigating into the directory, and running the 'make jwx' command. Ensure the installation path is configured for subsequent commands. ```shell $ git clone https://github.com/lestrrat-go/jwx.git $ cd jwx $ make jwx ``` -------------------------------- ### Deploy LINE Login Starter App to Heroku Source: https://developers.line.biz/en/docs/line-login/getting-started/index.html This process involves deploying the line-login-starter application to Heroku. Key configuration steps include providing a unique Heroku app name, setting the Callback URL, Channel ID, and Channel secret, which are obtained from the LINE Developers Console. ```shell $ heroku login $ heroku logs --app {Heroku app name} --tail ``` -------------------------------- ### LINE API Followers Insight Request Example Source: https://developers.line.biz/en/reference/messaging-api/index.html An example of a shell command to fetch follower insights from the LINE API using cURL. It specifies the GET request, the endpoint with a date parameter, and includes the necessary Authorization header with a channel access token. ```shell curl -v -X GET 'https://api.line.me/v2/bot/insight/followers?date=20190418' \ -H 'Authorization: Bearer {channel access token}' ``` -------------------------------- ### LINE Messaging API - Example Response for Message Quota (JSON) Source: https://developers.line.biz/en/reference/messaging-api/index.html An example JSON response from the 'Get message quota' endpoint. It shows the 'type' of quota setting ('limited' in this case) and the 'value', which represents the target limit for sending messages in the current month. ```json { "type": "limited", "value": 1000 } ``` -------------------------------- ### Initializing and Using Pluggable LIFF SDK (JavaScript) Source: https://developers.line.biz/en/docs/liff/release-notes/index.html This JavaScript code illustrates the complete process of using the pluggable LIFF SDK. It involves importing the core `liff` object and specific API modules, registering them using `liff.use()`, initializing the LIFF app with `liff.init()`, and then calling the activated LIFF APIs. ```javascript import liff from "@line/liff/core"; import GetOS from "@line/liff/get-os"; import GetLanguage from "@line/liff/get-language"; liff.use(new GetOS()); liff.use(new GetLanguage()); liff.init({ liffId: "123456-abcedfg", }); liff.getOS(); liff.getLanguage(); ``` -------------------------------- ### Get Unit Names Source: https://developers.line.biz/en/reference/messaging-api/index.html Retrieves a list of unit names assigned to messages for the current month. Supports pagination using limit and start parameters. ```APIDOC ## GET /llmstxt/developers_line_biz_llms_txt ### Description Retrieves a list of unit names assigned to messages for the current month. Supports pagination using limit and start parameters. ### Method GET ### Endpoint /llmstxt/developers_line_biz_llms_txt ### Parameters #### Query Parameters - **limit** (String) - Optional - The maximum number of unit names you can get per request. The default value is `100`. Max value: `100` - **start** (String) - 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 the unit names in a single request, include this parameter to get the remaining array. ### Response #### Success Response (200) - **customAggregationUnits** (Array of strings) - An array of strings indicating the unit names. The array uniquely contains the unit names assigned to messages during this month. - **next** (String) - Optional - A continuation token to get the next array of unit names. Returned only when there are remaining unit names that weren't returned in the `customAggregationUnits` property in the original request. The continuation token expires in 24 hours (86,400 seconds). #### Response Example ```json { "customAggregationUnits": ["promotion_a", "promotion_b"], "next": "jxEWCEEP..." } ``` #### Error Response - **400** - Problem with the request. Consider these reasons: An invalid continuation token is specified. An invalid value is specified for the `limit` property. #### Error Response Example ```json { "message": "Invalid start param" } ``` ``` -------------------------------- ### Issue Access Token and Get ID Token Source: https://developers.line.biz/en/docs/partner-docs/line-profile-plus/index.html Exchange an authorization code for an access token and an ID token. ```APIDOC ## Issue Access Token and Get ID Token ### Description This endpoint is used to exchange an authorization code obtained from the user's login flow for an access token and an ID token. The ID token contains the LINE Profile+ information. ### Method POST ### Endpoint `https://api.line.me/oauth2/v2.1/token` ### Parameters #### Request Body - **grant_type** (string) - Required - Set to `authorization_code`. - **code** (string) - Required - The authorization code received from the redirect URI. - **redirect_uri** (string) - Required - The same redirect URI used in the authorization URL. - **client_id** (string) - Required - Your LINE Login channel ID. - **client_secret** (string) - Required - Your LINE Login channel secret. ### Request Example ```sh curl -v -X POST https://api.line.me/oauth2/v2.1/token \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=authorization_code' \ -d 'code=b5fd32eacc791df' \ --data-urlencode 'redirect_uri=https://example.com/auth?key=value' \ -d 'client_id=12345' \ -d 'client_secret=d6524edacc8742aeedf98f' ``` ### Response #### Success Response (200) - **access_token** (string) - The access token for API calls. - **expires_in** (integer) - The expiration time of the access token in seconds. - **refresh_token** (string) - The refresh token to obtain a new access token. - **scope** (string) - The scopes granted. - **id_token** (string) - The ID token containing LINE Profile+ information (Base64 encoded). #### Response Example ```json { "access_token": "AtS...", "expires_in": 2592000, "refresh_token": "RtS...", "scope": "openid profile real_name gender birthdate phone address", "id_token": "eyJhbGciOiJIUzI1NiJ9..." } ``` ``` -------------------------------- ### Initialize LIFF App with Create LIFF App Source: https://developers.line.biz/en/docs/liff/cli-tool-create-liff-app/index.html This command initializes a new LIFF application using the Create LIFF App CLI tool. It prompts the user for project name, template, language, LIFF ID, and package manager. Options can be passed to skip prompts. ```bash npx @line/create-liff-app ``` ```bash npx @line/create-liff-app -t nextjs --ts ``` -------------------------------- ### Get User Information Request (Shell) Source: https://developers.line.biz/en/reference/line-login/index.html Example of making a GET request to the LINE API to retrieve user information, including user ID, display name, and profile image. Requires an access token with the 'openid' scope. ```sh curl -v -X GET https://api.line.me/oauth2/v2.1/userinfo \ -H 'Authorization: Bearer {access token}' ``` -------------------------------- ### Node.js Tutorial: Build a Reply Bot Source: https://context7_llms A step-by-step tutorial demonstrating how to create a basic LINE bot using Node.js that automatically replies to user messages. This involves setting up a server to receive webhook events and sending back a response. ```javascript const express = require('express'); const line = require('@line/bot-sdk'); const config = { channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN', channelSecret: 'YOUR_CHANNEL_SECRET', }; const client = new line.Client(config); const app = express(); app.post('/webhook', line.middleware(config), (req, res) => { Promise .all(req.body.events.map(handleEvent)) .then((result) => res.json(result)) .catch((err) => { console.error(err); res.status(500).end(); }); }); function handleEvent(event) { if (event.type === 'message' && event.message.type === 'text') { const echo = { type: 'text', text: event.message.text }; return client.replyMessage(event.replyToken, echo); } } app.listen(3000, () => { console.log('Webhook server is listening on port 3000'); }); ``` -------------------------------- ### Verify ID Token and Get Payload Source: https://developers.line.biz/en/docs/partner-docs/line-profile-plus/index.html Verify the ID token and decode its payload to retrieve LINE Profile+ information. ```APIDOC ## Verify ID Token and Get Payload ### Description This endpoint verifies the ID token obtained from the token issuance process and decodes its payload to retrieve the LINE Profile+ information. ### Method POST ### Endpoint `https://api.line.me/oauth2/v2.1/verify` ### Parameters #### Request Body - **id_token** (string) - Required - The Base64 encoded ID token received from the token endpoint. - **client_id** (string) - Required - Your LINE Login channel ID. ### Request Example ```sh curl -v -X POST 'https://api.line.me/oauth2/v2.1/verify' \ -d 'id_token=eyJraWQiOiIxNmUwNGQ0ZTU2NzgzYTc5MmRjYjQ2ODRkOD...' \ -d 'client_id=1234567890' ``` ### Response #### Success Response (200) The response will contain the decoded ID token payload, which includes LINE Profile+ information if the corresponding scopes were granted. Example fields include: - **given_name** (string) - The user's first name. - **family_name** (string) - The user's last name. - **gender** (string) - The user's gender. - **birthdate** (string) - The user's birthdate (YYYY-MM-DD). - **phone_number** (string) - The user's phone number. - **address** (object) - The user's address. - **postal_code** (string) - **region** (string) - **locality** (string) - **street_address** (string) - **country** (string) #### Response Example ```json { "given_name": "LINE", "middle_name": "L", "family_name": "Taro", "gender": "male", "birthdate": "1990-01-01", "phone_number": "+81901111....", "address": { "postal_code": "1028282", "region": "Tokyo", "locality": "Kioicho, Chiyoda-ku", "street_address": "1-3", "country": "JP" } } ``` ``` -------------------------------- ### Initialize and Use Quick-fill Plugin (CDN) Source: https://developers.line.biz/en/docs/line-mini-app/quick-fill/overview/index.html After loading the LIFF SDK and common profile plugin via CDN, initialize the plugin by passing an instance of `LiffCommonProfilePlugin` to `liff.use()`. You can then retrieve common profile data using `liff.$commonProfile.get()` and populate form fields with `liff.$commonProfile.fill(data)`. ```javascript liff.use(new liffCommonProfile.LiffCommonProfilePlugin()); const { data, error } = await liff.$commonProfile.get(); liff.$commonProfile.fill(data); ``` -------------------------------- ### Clone LINE SDK for Unity Repository Source: https://developers.line.biz/en/docs/line-login-sdks/unity-sdk/try-line-login This command-line instruction clones the official LINE SDK for Unity repository from GitHub. Ensure you have Git installed and configured on your system. ```sh $ git clone https://github.com/line/line-sdk-unity.git ``` -------------------------------- ### Install Netlify CLI Source: https://developers.line.biz/en/docs/liff/trying-liff-app/index.html Installs the Netlify Command Line Interface (CLI) globally using npm. This tool is essential for logging into Netlify and deploying websites from your local machine. No specific inputs are required beyond executing the command. ```bash npm install -g netlify-cli ```