# 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.

# Flow of sending a service message

To send a service message, you need a service message template and a service notification token. Follow these steps to send:

  1. In the LINE Developers Console, add a service message template to the LINE MINI App channel.
  2. Issue a service notification token and send a service message based on the end user's action.
  3. Use the new service notification token issued in step 2 to send a subsequent service message, such as a reminder.

# 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.

Templates per category

LINE MINI App provides pre-formatted templates per category in the Service Message Catalog (opens new window). We created these templates considering likely business scenarios. Although the templates are pre-formatted, you may still slightly customize them, following the guideline, so that they better fit your service needs. Select the template(s) that matches your user base, and send a test message to your account to see a preview.

We now provide formatted templates per category in the LINE Developers Console.

  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).

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 these 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). This function is only available for sending service messages to developers with Admin or Tester privileges on the LINE MINI App channel, from a channel ready for publication.
    PUBLISHING Passed review. Used to send service messages from the production channel to the user of the LINE MINI App channel.

# Template elements

A service message consists of (A) title, (B) detail, (C) button, 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.

Label Section Description
A Title The title section consists of these elements.
  • Title (A-1)
  • Subtitle (A-2)
B Detail The detail section has two different layouts depending on template type:
  • "detailed": 1 key required; the maximum number of keys depends on the template you select. The maximum length for each key value is 36 characters (we recommend it to be no more than 10 characters to ensure proper delivery of your messages).
  • "simple": 1 key required; the maximum number of keys is 1 regardless of template type. The maximum length for key value is 100 characters (we recommend it to be no more than 32 characters to ensure proper delivery of your messages).
C Button The number of buttons you can use differs per template. Also, only buttons with configured URLs are displayed. Specify the Permanent link of your LINE MINI App page as the URL.
  • The first button is required and is displayed as the first link in the message.
  • The second button (and beyond) is optional and predefined based on the template you choose.
D Footer Your LINE MINI App icon and LINE MINI App name are displayed. When the user taps the footer, your LINE MINI App home page is displayed.
The footer when your LINE MINI App status is not "Published"

If the status of your LINE MINI App is "Developing" or "Reviewing", the LINE icon along with the text, "Service Message", will be displayed in the footer section. Once the status changes to "Published", the LINE MINI App icon and LINE MINI App name that you configured will be displayed.

Ellipses displayed when maximum number of characters is exceeded

If the maximum number of characters is exceeded, ellipses (...) appear at the end. Be sure to observe the criterion for maximum number of characters so that ellipses aren't displayed.

# 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 doesn't need to be reacquired each time you send a service message.

  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();
    
    Save the value contained in the response

    Keep the service notification token (notificationToken) included in the response. This token is used to send subsequent service messages for the same user action (session). You can send service messages for the same user action as many times as the number of remainingCount included in the response as long as the token has not expired.

    Sessions can be identified by the session ID (sessionId) included in the response.

# 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. 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();
}
Save the value contained in the response

Keep the service notification token (notificationToken) included in the response. This token is used to send subsequent service messages for the same user action (session). You can send service messages for the same user action as many times as the number of remainingCount included in the response as long as the token has not expired.

Sessions can be identified by the session ID (sessionId) included in the response.