# Add a LINE Official Account as a friend when logged in (bot link)

You can display an option to add the LINE Official Account as a friend when a user logs in to your app. This is called the bot link feature. Specify the LINE Official Account to be added as a friend on the LINE Developers Console.

Consent screen

If the user enables Add friend on the above consent screen when logging in, the LINE Official Account will be added as a friend. For more information on creating bots, see Messaging API.

# Displaying the option to add your LINE Official Account as a friend

To display the option to add your LINE Official Account as a friend on the consent screen, configure the settings as below.

  1. Link a LINE Official Account with your channel
  2. Redirect users to the LINE Login authorization URL with the bot_prompt query parameter

Link a LINE Official Account with your LINE Login channel on the LINE Developers Console.

To link a LINE Official Account to your LINE Login channel, you must satisfy these requirements:

  • The Messaging API channel linked to the LINE Official Account belongs to the same provider as your LINE Login channel.

  • You are an administrator of the LINE Login channel and the LINE Official Account.

    You can check the Admin role for the channel on the LINE Developers Console. You can check the Admin role for the LINE Official Account on LINE Official Account Manager.

  1. Log in to the LINE Developers Console and click the provider that contains the channel for LINE Login.

  2. Open your LINE Login channel settings.

  3. On the Basic settings tab, under Linked OA, click Edit.

  4. Select the LINE Official Account you want users to add and click Update.

    You can select a LINE Official Account for which you have an administrator role.

    You can link only one LINE Official Account to a LINE Login channel.

# Redirect users to the LINE Login authorization URL with the bot_prompt query parameter

Redirect users to the LINE Login authorization URL with the bot_prompt query parameter as shown below.

https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id={CHANNEL_ID}&redirect_uri={CALLBACK_URL}&state={STATE}&bot_prompt={BOT_PROMPT}&scope={SCOPE_LIST}

These options are displayed depending on the bot_prompt query parameter.

Value Description
normal Display the option to add a LINE Official Account as a friend in the consent screen.
aggressive Opens a new screen to add the LINE Official Account as a friend after the consent screen.

Screen to be displayed

Tip

For more information on query parameters other than bot_prompt, see Making an authorization request.

The option to add a LINE Official Account as a friend is displayed as follows according to the relationship between the user and the LINE Official Account.

Friend relationship when consent screen is displayed Options shown to the user
Not a friend Displays the option to add a LINE Official Account as a friend. The LINE Official Account is added as a friend if the user selects the option and continues.
Blocked Displays the option to unblock the LINE Official Account. The LINE Official Account is unblocked if the user selects the option and continues.
Added as friend Shows that the user has added the LINE Official Account as a friend. No option is displayed to add the LINE Official Account as a friend.

# Getting the friendship status of the user and the LINE Official Account

You can get the friendship status of the user and the LINE Official Account using these methods.

# Use the friendship_status_changed query parameter

If the bot_prompt query parameter is specified when making an authorization request, the friendship_status_changed query parameter is returned in the callback URL after the user is authenticated and authorized.

This is an example response with the friendship_status_changed query parameter in the callback URL.

HTTP/1.1 302 Found
Location : https://client.example.org/cb?code={CODE}&state={STATE}&friendship_status_changed={FRIENDSHIP_STATUS_CHANGED}

The friendship_status_changed query parameter can take the following values. For more information on the callback URL, see Receiving the authorization code.

Value Description
true The friendship status of the user and the LINE Official Account changed during login. This occurs in one of these situations:
  • User added the LINE Official Account as a friend
  • User unblocked the LINE Official Account
false The friendship status of the user and the LINE Official Account didn't change during login. This occurs in one of these situations:
  • User already added the LINE Official Account as a friend
  • User didn't add the LINE Official Account as a friend
  • User didn't unblock the LINE Official Account
Note

friendship_status_changed query parameter isn't included if the consent screen with the option to add your LINE Official Account as a friend isn't displayed to the user.

# Use the Social API to get friendship status

Send a GET request to the https://api.line.me/friendship/v1/status endpoint after the user has logged in to your app and an access token has been returned.

curl -X GET https://api.line.me/friendship/v1/status \
-H 'Authorization: Bearer {access token}'

The friendFlag property is returned if the API call is successful. The value is true if the user has added the LINE Official Account as a friend and hasn't blocked the LINE Official Account. Otherwise, the value is false.

For more information, see Get friendship status in the Social API reference.