# Sending service messages

Service message is a feature of LINE MINI App that enables you to notify the user in response to or in confirmation of a particular user action. For example, a service message can be used to send users confirmation notifications of reservations for restaurants and accommodations.

Conditions to sending service messages

You are allowed to send service messages only as a confirmation or response to a user action. Advertisements and event notifications are prohibited, including information on discounts, shopping rewards, new products, discount coupons or promotions. For more information about the service message conditions, see Conditions for service messages.

Service messages sent from LINE MINI Apps are displayed in the LINE "Service Messages" talkroom, regardless of the type of LINE MINI App.

In order to start sending service messages, add a service message template to the LINE MINI App channel and call the Service Message API from the server.

# Adding service message templates

From the templates provided by LINE, select a template to use with the Service Message API and add it to the LINE MINI App channel. You can configure up to 20 service message templates per LINE MINI App channel.

Note

We are now providing formatted templates by category in the Service Message Catalog (opens new window). To a certain degree, you may still customize the templates so that they better fit your service needs. However, please be mindful of the character limit when entering parameter values.

You must pass a review

In order to use the service message template added to the LINE MINI App channel with the Service Message API, you must pass a review by LINE.

  1. From the LINE Developers Console, select the LINE MINI App channel to which you want to add a template and click the [Service message template] tab.
Note
  1. You can proceed with preparing the official template while developing your channel.
  • During this time, you can:
    • Add a new template
    • See the list of all templates
    • View template detail
    • Edit the use case of a template
    • Delete a template
    • Send a test message available in the simulator
  1. When review is in progress, some limitations apply to the use of the official template.
  • During this time, you can still:
    • See the list of all templates
    • Send a test message available in simulator
    • View template detail
  • However, at this stage, you CANNOT:
    • Add a new template
    • Edit the use case of a template
    • Delete a template
  1. Once the channel is published, you can use the official template on the published channel (same condition apply as the preparation stage in #1).

Please note that while your channel is under review, you cannot add a new template. You can only send test messages available in the simulator until your channel passes review. The review process, however, does not affect existing templates (both official and custom templates) that have successfully been added in the past.

  1. Click [Add].

  2. Configure the following settings:

    Item Description
    Select template Select a template to use with the Service Message API.
    Template detail The details of the selected template will be displayed. When executing the API for sending service messages, specify the string ({template name}_{BCP 47 language tag}) displayed in [Template Name] as templateName.
    Preview A preview of the test message will be displayed. When you click [Send] from [Send test message], the test message will be sent to the LINE account logged into the LINE Developers Console.
    Send test message Enter the JSON object that specifies the template variable-value pair. [Preview] will be updated with your entry.
    • [Copy]: Copy the JSON object to clipboard.
    • [Reset]: Discard edits to JSON object.
    • [Send]: Send the test message to the LINE account logged into the LINE Developers Console.
    Use Case Enter the exact use case for the template.
    Note

    If you use templates in a manner that deviates from the explanation you entered in [Use Case], we may prevent you from using the templates.

  3. Click [Add].

    The status of the review will be displayed in [Published status] of the added template.

    Published status Description
    DEVELOPING Developing (Review not yet requested). Submit for review.
    PUBLISHING Passed review. Able to use Service Message template with API for sending service messages.

    Please continue in order to submit for review.

  4. Click the [Workflow] tab, enter [Comment to reviewers], and click [Request review].

    Review by LINE will commence.

    Once the review by LINE is complete, the review result will be displayed on the [Service message template] tab. Only templates that pass review can be used with API for sending service messages.

# Elements of the template

Service message consist of (A) title, (B) detail, (C) note, and (D) footer. Create a template by combining these sections according to the use case. Choose a template that best serves the purpose of your service message.

# A. Title Section

The title section consists of the following elements.

Label Element Required Description
A-1 Title Required Maximum length is 40 characters.
A-2 Subtitle Optional Maximum length is 32 characters.
Note

If the maximum number of characters is exceeded, ellipses appears at the end. Be sure to observe the criterion for maximum number of characters so that ellipses are not displayed.

# B. Detail section

There are 2 types of layouts available for the detail section, "Detailed" and "Simple". The restrictions for the detail section are as follows:

[Detailed] consists of a shorter item name and content.

  • You can select up to 14 keys
  • Maximum length for key: 12 characters
  • Maximum length for value: 36 characters

[Simple] consists only of free-form content.

  • You can select up to one value.
  • Maximum length for value: 100 characters
Note

If the maximum number of characters is exceeded, an ellipsis appears at the end. Be sure to observe the maximum number of characters criterion so that ellipses are not displayed.

# C. Button Section

Data entry for the button section is required. The maximum number of buttons and button labels per template are fixed and cannot be changed.

The URL must be a permanent link to a page of your LINE MINI App.

Label Element Required Description
- First button Required Specify a URL that takes the user to view details regarding the service message in params.
- Other buttons Optional Specify a URL per button in params. Only the buttons that specify a URL are displayed.

Your LINE MINI App icon and LINE MINI App name are displayed in the footer section. When the user taps the footer, the home page of the corresponding LINE MINI App is displayed.

Note

When the template status is "Developing" or "Review", the LINE icon, along with the text, "Service Message", is temporarily displayed. Once the status is changed to "Published", your LINE MINI App icon and LINE MINI App name will be displayed instead.

# Sending service messages for the first time

Here are the steps to sending a service message for the first time from the LINE MINI App after a user action:

Test sending recommended

Before sending the service messages to users, we recommend that you test sending service messages and see how the message is displayed.

  1. Obtain the channel access token in advance.

    The channel access token does not need to be reacquired each time you send a service message.

    Note

    You may not use a channel access token for which you can designate an arbitrary expiration date (Channel Access Token v2.1).

  2. When notifying, obtain the access token by running the liff.getAccessToken() on your LINE MINI App.

  3. Send the access token obtained in step 2 to your server.

  4. Issue a service notification token

    Use the channel access token from step 1 and the access token from step 2.

    final OkHttpClient notifierApiClient = new OkHttpClient().newBuilder().build();
    final MediaType mediaType = MediaType.parse("application/json");
    final RequestBody notificationTokenRequestBody = RequestBody.create(mediaType, "{'liffAccessToken': 'eyJhbGciOiJIUzI1NiJ9…​'");
    final Request notificationTokenRequest = new Request.Builder()
      .url(BASE_URL + "/notifier/token")
      .method("POST", notificationTokenRequestBody)
      .addHeader("Content-Type", "application/json")
      .addHeader("Authorization", "Bearer W1TeHCgfH2Liwa...")
      .build();
    final NotificationTokenResponse response = notifierApiClient.newCall(request).execute();
    String notificationToken = notificationTokenResponse.getNotificationToken();
    int tokenRemainingCount = notificationTokenResponse.getRemainingCount();
    
  5. Sending a service message for the first time

    Use the service notification token obtained in step 4.

    If the template you use has template variables, specify the key-value pair in the params. If you do not specify the template variable for the required element, an error will be returned.

    Example of params:

    {
      ...
      "params": {
        // params sample to be updated
        "variable-name": "value",
        "button_uri_1": "detailView?userId=1234&purchaseID=5678"
      }
      ...
    }
    
    final RequestBody notificationRequestBody = RequestBody.create(mediaType,"{
      'templateName': 'reservation_confirmation_en',
      'notificationToken': '34c11a03-b726-49e3-8ce0-949387a9…​',
      'params': {
        'template-field-name': 'field-value',
        'template-field-name': 'field-value',
      }}");
    final Request notificationRequest = new Request.Builder()
      .url(BASE_URL + "/notifier/send?target=service")
      .method("POST", notificationRequestBody)
      .addHeader("Content-Type", "application/json")
      .addHeader("Authorization", "Bearer W1TeHCgfH2Liwa...")
      .build();
    final NotificationResponse notificationResponse = notifierApiClient.newCall(request).execute();
    notificationToken = notificationResponse.getNotificationToken();
    tokenRemainingCount = notificationResponse.getRemainingCount();
    
    Note

    Keep the service notification token (notificationToken) included in the response. This token is used to send subsequent service messages for the same user action. You can send more service messages for the same user action as long as the remainingCount included in the response is not zero and the token has not expired.

# Sending subsequent service messages

When you send subsequent service messages for the same user action, you do not need to have a new service notification token issued. Please use the service notification token that was included in the response when you last sent the service message.

...
JsonObject subsequentMessage = Json.createObjectBuilder()
  .add("notificationToken", notificationToken)
  .add("templateName", templateName)
  .add("params", templateData)
  .build();
...

if (tokenRemainingCount < 0)
{
  notificationRequestBody = RequestBody.create(mediaType, subsequentMessage.toString());
  notificationRequest = new Request.Builder()
        .url(BASE_URL + "/notifier/send?target=service")
        .method("POST", notificationRequestBody)
        .addHeader("Content-Type", mediaType.toString())
        .addHeader("Authorization", "Bearer W1TeHCgfH2Liwa...")
        .build();
  notificationResponse =
        notifierApiClient.newCall(notificationRequest).execute();
  notificationToken = notificationResponse.getNotificationToken();
  tokenRemainingCount = notificationResponse.getRemainingCount();
}
Note

Keep the service notification token (notificationToken) included in the response. This token is used to send subsequent service messages for the same user action. You can send more service messages for the same user action as long as the remainingCount included in the response is not zero and the token has not expired.