Skip to content
Last updated

LINE Messaging Export Integration

LINE is in Asia what Facebook Messaging and Instagram are to US mobile users—a fast and easy way to communicate with friends and to discover new promotions about favorite products and services. LINE is the number one mobile messaging platform in Japan and Taiwan and is also one of the largest advertising delivery platforms.

This TD export integration allows you to write job results from Treasure Data directly to a LINE Messaging account.

What can you do with this Integration?

Prerequisites

  • Basic knowledge of Treasure Data
  • Basic knowledge LINE messaging
  • Official LINE messaging account

Requirements and Limitations

  • Treasure Data does not verify the validity of your data; Treasure Data only filters NULL or empty data before uploading.

Use the TD Console to Create a Connection

You must create and configure the data connection in the Treasure Data console prior to running the query that will export data. As part of the data connection, you provide authentication credentials to access the integration.

Line supports two authentication methods:

  • Channel Access Token (Default)
  • Short-Lived Token

Create a new Channel Access Token Authentication

  1. Open TD Console.
  2. Navigate to Integrations Hub > Catalog.
  3. Search for LINE and select LINE Messaging.
  4. Select Create Authentication.
  5. From the Authentication Method drop-down, select Channel Access Token.
  6. Enter the LINE Messaging channel access token that will be used to authenticate to your LINE account.
  7. Select Continue.
  8. Enter a name for your connection.
  9. Select Done.

Create a new Short-Lived Token Authentication

  1. Open TD Console.
  2. Navigate to Integrations Hub > Catalog.
  3. Search for LINE and select LINE Messaging.
  4. Select Create Authentication.
  5. From the Authentication Method drop-down, select Short Lived Token.
  6. Enter the LINE Messaging Channel Id**.**
  7. Enter the Channel Secret**.**
  8. Select Continue.
  9. Type a name for your connection.
  10. Select Done.

Define your Query

  1. Navigate to  Data Workbench > Queries.
  2. Select New Query.
  3. In the database drop-down, enter the database you want to query. This example uses test_db.
  4. In the query pane, enter your SQL query.
  5. Select Run to validate the results of the query.

Target: Audience

Target: Push Message

Target: Multicast Message

NOTE:

  • The recipient ID is required to be defined in the schema for 2 target Push Message and Multicast Messge.

  • The Push Message target supports placeholders in the Template Message.

    • Placeholders are variables contained within {{ ... }} and required to be fully defined in the schema. And will be replaced by the corresponding value in each record.
  • Example in Push Message target Template Message.

{
  "type": "textV2",
  "text": "Welcome, {user1}! {laugh}\n {everyone} There is a newcomer!",
  "substitution": {
    "user1": {
      "type": "mention",
      "mentionee": {
        "type": "user",
        "userId": "{{user_1_id}}"
      }
    },
    "laugh": {
      "type": "emoji",
      "productId": "{{product_id}}",
      "emojiId": "{{emoji_id}}"
    },
    "everyone": {
      "type": "mention",
      "mentionee": {
        "type": "all"
      }
    }
  }
}
  • If using Multicast Message, it should define only the recipient ID column.

Specify the Result Export Target

  1. Select Export Results.

  1. To export the results to an external service, you can use an existing authentication or create a new one. Choose either
  • Use Existing Integration
  • Create New Integration

Use Existing Integration

  1. Select Use Existing Integration.
  2. Select the existing integration you want to use. This example uses line_messaging_output_test.
  3. Enter the information in the form.

4. Select Done.

FieldDescription
TargetThe LINE Message object for which data needs to be uploaded. Supported objects: - Audience - Push Message - Multicast Message
Use existing LINE Audience ID to push an audienceUpload audiences to an Audience Group by specifying Audience ID instead of Audience Name.
Audience NameUpload audiences to an Audience Group by specifying Audience Name.
Is IFAs Audience?Select this checkbox if you are uploading IFA audiences. Otherwise, LINE User ID is used.
Template MessageThe input area for a text message.
Skip Invalid MessageEnable to skip invalid message and just send the valid message. If unable, if there is any invalid message, it will raise an error message.
Notification DisabledEnable to send the message in silence. (Default=False).
Custom Aggregation UnitsName of aggregation unit. Case-sensitive. For example, Promotion_a and Promotion_A are considered as different unit names. - Max unit number: 1 - Max character limit: 30 - Supported character types: Half-width alphanumeric characters (a-z, A-Z, 0-9) and underscore (_)

Create a New Integration

  1. Select Create New Integration.
  2. From the Type drop-down, select LINE Messaging.
  3. Enter the name of the new integration.
  4. Choose Channel Access Token or Short Lived Token from the Authentication Method drop-down.
  5. Enter the remaining information in the form.

6. Select Next. 7. Enter the information in the Export Results form. 8. Select Done.

FieldDescription
NameName of this Integration.
Channel Access TokenLINE channel access token or long-lived token that is permanently valid.
Chanel IdLINE channel Id (for short-lived token authentication).
Channel SecretLINE channel secret (for short-lived token authentication)
Maximum RetryThe number of retries before the system gives up. Default: 7
Seconds to Wait For First RetryThe time, in seconds, between the first and second attempt. Default: 15
Seconds for Max Retry WaitThe time, in seconds, between the second and all subsequent attempts. Default: 3600
Seconds for Connection TimeoutThe time, in seconds, is to wait until an HTTP call operation is aborted. Default is 300
Use existing LINE Audience ID to push an audienceUpload audiences to an Audience Group by specifying Audience ID instead of Audience Name.
Audience NameUpload audiences to an Audience Group by specifying the Audience Name.
Is IFAs Audience?Select this checkbox if you are uploading IFA audiences. Otherwise, the LINE User ID is used.

Example Query

SELECT my_col as id FROM www_access

(Optional) Schedule Query Export Jobs

You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.

Treasure Data's scheduler feature supports periodic query execution to achieve high availability.

When two specifications provide conflicting schedule specifications, the specification requesting to execute more often is followed while the other schedule specification is ignored.

For example, if the cron schedule is '0 0 1 * 1', then the 'day of month' specification and 'day of week' are discordant because the former specification requires it to run every first day of each month at midnight (00:00), while the latter specification requires it to run every Monday at midnight (00:00). The latter specification is followed.

Scheduling your Job Using TD Console

  1. Navigate to Data Workbench > Queries

  2. Create a new query or select an existing query.

  3. Next to Schedule, select None.

  4. In the drop-down, select one of the following schedule options:

    Drop-down ValueDescription
    Custom cron...Review Custom cron... details.
    @daily (midnight)Run once a day at midnight (00:00 am) in the specified time zone.
    @hourly (:00)Run every hour at 00 minutes.
    NoneNo schedule.

Custom cron... Details

Cron ValueDescription
0 * * * *Run once an hour.
0 0 * * *Run once a day at midnight.
0 0 1 * *Run once a month at midnight on the morning of the first day of the month.
""Create a job that has no scheduled run time.
 *    *    *    *    *
 -    -    -    -    -
 |    |    |    |    |
 |    |    |    |    +----- day of week (0 - 6) (Sunday=0)
 |    |    |    +---------- month (1 - 12)
 |    |    +--------------- day of month (1 - 31)
 |    +-------------------- hour (0 - 23)
 +------------------------- min (0 - 59)

The following named entries can be used:

  • Day of Week: sun, mon, tue, wed, thu, fri, sat.
  • Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.

A single space is required between each field. The values for each field can be composed of:

Field ValueExampleExample Description
A single value, within the limits displayed above for each field.
A wildcard '*' to indicate no restriction based on the field.'0 0 1 * *'Configures the schedule to run at midnight (00:00) on the first day of each month.
A range '2-5', indicating the range of accepted values for the field.'0 0 1-10 * *'Configures the schedule to run at midnight (00:00) on the first 10 days of each month.
A list of comma-separated values '2,3,4,5', indicating the list of accepted values for the field.0 0 1,11,21 * *'Configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month.
A periodicity indicator '*/5' to express how often based on the field's valid range of values a schedule is allowed to run.'30 */2 1 * *'Configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. '0 0 */5 * *' configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month.
A comma-separated list of any of the above except the '*' wildcard is also supported '2,*/5,8-10'.'0 0 5,*/10,25 * *'Configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month.
  1. (Optional) You can delay the start time of a query by enabling the Delay execution.

Execute the Query

Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically exported to the specified destination.

Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.

(Optional) You can delay the start time of a query by enabling the Delay execution.

Activate a Segment in Audience Studio

You can also send segment data to the target platform by creating an activation in the Audience Studio.

  1. Navigate to Audience Studio.
  2. Select a parent segment.
  3. Open the target segment, right-mouse click, and then select Create Activation.
  4. In the Details panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters.
  5. Customize the activation output in the Output Mapping panel.

  • Attribute Columns
    • Select Export All Columns to export all columns without making any changes.
    • Select + Add Columns to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select + Add Columnsto add new columns for your activation output.
  • String Builder
    • + Add string to create strings for export. Select from the following values:
      • String: Choose any value; use text to create a custom value.
      • Timestamp: The date and time of the export.
      • Segment Id: The segment ID number.
      • Segment Name: The segment name.
      • Audience Id: The parent segment number.
  1. Set a Schedule.

  • Select the values to define your schedule and optionally include email notifications.
  1. Select Create.

If you need to create an activation for a batch journey, review Creating a Batch Journey Activation.

(Optional) Configure Export Results in Workflow

Within Treasure Workflow, you can specify using this data connector to export data.

Learn more about using workflows to export datawith the TD Toolbelt.

_export:
  td:
  database: td.database

+line_messaging_export_task:
  td>: export_line_messaging.sql
  database: ${td.database}
  result_connection: {your_connection_name}
  result_settings:
    audience_name: audience_name_abc
  	use_audience_id: false
  	is_ifa_audience: true

(Optional) Export Integration Using the CLI

You can also use the CLI provided by TD Toolbelt to export query results to LINE messaging.

Using the td query command, you would specify the LINE messaging server URL with the --result RESULT_URL option.  See td query for more information.

The format of the option is JSON, and the general structure is as follows.

Or

Parameters

NameDescriptionValueDefault ValueRequired
typeDescribe the name of the service as the destination of export.line_messagingYes
auth_methodThe authentication method can specify either a :long-lived token or a limited-time token.channel_access_token short_lived_tokenchannel_access_tokenYes
access_tokenThe Channel access token.Yes, if auth_method=channel_access_token
client_idLine Client Id.Yes, if auth_method=short_lived_token
client_secretLine Client Secret.Yes, if auth_method=short_lived_token
targetThe LINE Message object for which data needs to be uploaded.- audience - push_message - multicast_messageaudienceYes
audience_nameAudience Group name.Yes, if use_audience_id = false
audience_idAudience Group ID.Yes, if use_audience_id = true
use_audience_idUse Audience Group ID instead of Name.falseNo
is_ifa_audienceType of audience.trueNo
template_messageTemplate message to push. Support place_holder to customize the message.StringYes, if target = push_message
template_message_multicastTemplate message to multicast. Not supporting place_holder.StringYes, if target = template_message_multicast
skip_invalid_messageSkip invalid message for Push Message.BooleantrueNo
skip_multicast_invalid_messageSkip invalid message for Multicast Message.BooleantrueNo
notification_disabledDisable notifications for sending multicast message.BooleantrueNo
custom_aggregation_unitsCustom aggregation units for multicast message.StringNo
batch_size_multicastBatch size for multicast message.Integer Must be between 1 and 500 Default: 1010No
max_retryMaximum number of retries when request failed8No
initial_retry_waitThe initial amount of time before the first retry in seconds15No
max_retry_waitThe maximum amount of time to wait for a retry in seconds3600No
connection_timeoutThe HTTP connection time out for a request to Pardot in seconds300No

Example for Usage

Authentication with Channel Access Token

out:
  type: line_messaging
  access_token: xxxx
  auth_method: channel_access_token
  ...

Authentication with Short Lived Token

out:
  type: line_messaging
  client_id: 1234
  client_secret: xxxx
  auth_method: short_lived_token  ...

Upload Audience

out:
   type: line_messaging
   access_token: xxxx
   auth_method: channel_access_token
   target: audience
   audience_name: test group
   use_audience_id: true
   audience_id: 33948315694
   is_ifa_audience: true

Sent Push Message

out:
  type: line_messaging
  access_token: xxxx
  auth_method: channel_access_token
  target: push_message
  template_message: |
    {
      "type": "textV2",
      "text": "Welcome, {user1}! {laugh}\n{everyone} There is a newcomer!",
      "substitution": {
          "user1": {
          "type": "mention",
          "mentionee": {
              "type": "user",
              "userId": "{{user_1_id}}"
          }
          },
          "laugh": {
              "type": "emoji",
              "productId": "{{emoji_product_id}}",
              "emojiId": "{{emoji_id}}"
          },
          "everyone": {
              "type": "mention",
              "mentionee": {
                  "type": "all"
          }
          }
      }
    }
  skip_invalid_message: true

Sent Multicast Message

out:
  type: line_messaging
  target: multicast_message
  access_token: xxxx
  auth_method: channel_access_token
  template_message_multicast: |
    {
      "type": "textV2",
      "text": "Hi, new friend ! {laugh}",
      "substitution": {
          "laugh": {
              "type": "emoji",
              "productId": "670e0cce840a8236ddd4ee4c",
              "emojiId": "006"
          }
          }
      }
    }
  skip_multicast_invalid_message: true

Example Template Message

  1. Text Message - Messaging API reference
{
   "type": "text",
   "text": "Hello, world"
}

2. Text Message V2 - Messaging API reference

{
  "type": "textV2",
  "text": "Welcome, {user1}! {laugh}\n{everyone} There is a newcomer!",
  "substitution": {
    "user1": {
      "type": "mention",
      "mentionee": {
        "type": "user",
        "userId": "U49585cd0d5..."
      }
    },
    "laugh": {
      "type": "emoji",
      "productId": "5a8555cfe6256cc92ea23c2a",
      "emojiId": "002"
    },
    "everyone": {
      "type": "mention",
      "mentionee": {
        "type": "all"
      }
    }
  }
}
  1. Sticker Message - Messaging API reference
{
  "type": "sticker",
  "packageId": "446",
  "stickerId": "1988"
}
  1. Image Message - Messaging API reference
{
  "type": "image",
  "originalContentUrl": "https://example.com/original.jpg",
  "previewImageUrl": "https://example.com/preview.jpg"
}
  1. Video Message - Messaging API reference
{
  "type": "video",
  "originalContentUrl": "https://example.com/original.mp4",
  "previewImageUrl": "https://example.com/preview.jpg",
  "trackingId": "track-id"
}
  1. Audio Message - Messaging API reference
{
  "type": "audio",
  "originalContentUrl": "https://example.com/original.m4a",
  "duration": 60000
}
  1. Location Message - Messaging API reference
{
  "type": "location",
  "title": "my location",
  "address": "1-3 Kioicho, Chiyoda-ku, Tokyo, 102-8282, Japan",
  "latitude": 35.67966,
  "longitude": 139.73669
}
  1. Imagemap Message - Messaging API reference
{
  "type": "imagemap",
  "baseUrl": "https://example.com/bot/images/rm001",
  "altText": "This is an imagemap",
  "baseSize": {
    "width": 1040,
    "height": 1040
  },
  "video": {
    "originalContentUrl": "https://example.com/video.mp4",
    "previewImageUrl": "https://example.com/video_preview.jpg",
    "area": {
      "x": 0,
      "y": 0,
      "width": 1040,
      "height": 585
    },
    "externalLink": {
      "linkUri": "https://example.com/see_more.html",
      "label": "See More"
    }
  },
  "actions": [
    {
      "type": "uri",
      "linkUri": "https://example.com/",
      "area": {
        "x": 0,
        "y": 586,
        "width": 520,
        "height": 454
      }
    },
    {
      "type": "message",
      "text": "Hello",
      "area": {
        "x": 520,
        "y": 586,
        "width": 520,
        "height": 454
      }
    }
  ]
}
  1. Template Messages - Messaging API reference
{
  "type": "template",
  "altText": "This is a buttons template",
  "template": {
    "type": "buttons",
    "thumbnailImageUrl": "https://example.com/bot/images/image.jpg",
    "imageAspectRatio": "rectangle",
    "imageSize": "cover",
    "imageBackgroundColor": "#FFFFFF",
    "title": "Menu",
    "text": "Please select",
    "defaultAction": {
      "type": "uri",
      "label": "View detail",
      "uri": "http://example.com/page/123"
    },
    "actions": [
      {
        "type": "postback",
        "label": "Buy",
        "data": "action=buy&itemid=123"
      },
      {
        "type": "postback",
        "label": "Add to cart",
        "data": "action=add&itemid=123"
      },
      {
        "type": "uri",
        "label": "View detail",
        "uri": "http://example.com/page/123"
      }
    ]
  }
}
  1. Flex Message - Messaging API reference
{
  "type": "flex",
  "altText": "this is a flex message",
  "contents": {
    "type": "bubble",
    "body": {
      "type": "box",
      "layout": "vertical",
      "contents": [
        {
          "type": "text",
          "text": "hello"
        },
        {
          "type": "text",
          "text": "world"
        }
      ]
    }
  }
}

Appendix A: How to get a LINE Channel ID and Channel secret?

  1. Go to https://developers.line.biz/en/ and select login in the top right corner.

  1. Select Log in with LINE account.

  1. Enter your official LINE account's user name and password and select Log in.

  1. Access your Channel

  1. In your channel, select the Basic settings tab.

You will see Channel ID and Channel secret on this tab.