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.
- Export the user IDs or IFAs from Treasure Data to a LINE account.
- Sent Message to Users, Groups, and Rooms in 2-way:
- Push Message - Sent message to a single user.
- Multicast Message - Sent message to multiple users.
- Support sending messages to LINE Message. Supported 10 types:
- Text Message - Messaging API reference
- Text Message V2 - Messaging API reference
- Sticker Message - Messaging API reference
- Image Message - Messaging API reference
- Video Message - Messaging API reference
- Audio Message - Messaging API reference
- Location Message - Messaging API reference
- Image Map Message - Messaging API reference
- Template Messages - Messaging API reference
- Flex Message - Messaging API reference
- Basic knowledge of Treasure Data
- Basic knowledge LINE messaging
- Official LINE messaging account
- Treasure Data does not verify the validity of your data; Treasure Data only filters NULL or empty data before uploading.
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
- Open TD Console.
- Navigate to Integrations Hub > Catalog.
- Search for LINE and select LINE Messaging.
- Select Create Authentication.
- From the Authentication Method drop-down, select Channel Access Token.
- Enter the LINE Messaging channel access token that will be used to authenticate to your LINE account.
- Select Continue.
- Enter a name for your connection.
- Select Done.
- Open TD Console.
- Navigate to Integrations Hub > Catalog.
- Search for LINE and select LINE Messaging.
- Select Create Authentication.
- From the Authentication Method drop-down, select Short Lived Token.
- Enter the LINE Messaging Channel Id**.**
- Enter the Channel Secret**.**
- Select Continue.
- Type a name for your connection.
- Select Done.
- Navigate to Data Workbench > Queries.
- Select New Query.
- In the database drop-down, enter the database you want to query. This example uses test_db.
- In the query pane, enter your SQL query.
- 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.
- Select Export Results.

- 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
- Select Use Existing Integration.
- Select the existing integration you want to use. This example uses line_messaging_output_test.

- Enter the information in the form.
4. Select Done.
| Field | Description |
|---|---|
| Target | The 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 audience | Upload audiences to an Audience Group by specifying Audience ID instead of Audience Name. |
| Audience Name | Upload 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 Message | The input area for a text message. |
| Skip Invalid Message | Enable 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 Disabled | Enable to send the message in silence. (Default=False). |
| Custom Aggregation Units | Name 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
- Select Create New Integration.
- From the Type drop-down, select LINE Messaging.
- Enter the name of the new integration.
- Choose Channel Access Token or Short Lived Token from the Authentication Method drop-down.
- Enter the remaining information in the form.
6. Select Next. 7. Enter the information in the Export Results form. 8. Select Done.
| Field | Description |
|---|---|
| Name | Name of this Integration. |
| Channel Access Token | LINE channel access token or long-lived token that is permanently valid. |
| Chanel Id | LINE channel Id (for short-lived token authentication). |
| Channel Secret | LINE channel secret (for short-lived token authentication) |
| Maximum Retry | The number of retries before the system gives up. Default: 7 |
| Seconds to Wait For First Retry | The time, in seconds, between the first and second attempt. Default: 15 |
| Seconds for Max Retry Wait | The time, in seconds, between the second and all subsequent attempts. Default: 3600 |
| Seconds for Connection Timeout | The time, in seconds, is to wait until an HTTP call operation is aborted. Default is 300 |
| Use existing LINE Audience ID to push an audience | Upload audiences to an Audience Group by specifying Audience ID instead of Audience Name. |
| Audience Name | Upload 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. |
SELECT my_col as id FROM www_accessYou 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.
Navigate to Data Workbench > Queries
Create a new query or select an existing query.
Next to Schedule, select None.

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

Drop-down Value Description 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. None No schedule.

| Cron Value | Description |
|---|---|
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 Value | Example | Example 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. |
- (Optional) You can delay the start time of a query by enabling the Delay execution.
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.
You can also send segment data to the target platform by creating an activation in the Audience Studio.
- Navigate to Audience Studio.
- Select a parent segment.
- Open the target segment, right-mouse click, and then select Create Activation.
- In the Details panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters.
- 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.
- + Add string to create strings for export. Select from the following values:
- Set a Schedule.

- Select the values to define your schedule and optionally include email notifications.
- Select Create.
If you need to create an activation for a batch journey, review Creating a Batch Journey Activation.
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: trueYou 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
| Name | Description | Value | Default Value | Required |
|---|---|---|---|---|
| type | Describe the name of the service as the destination of export. | line_messaging | Yes | |
| auth_method | The authentication method can specify either a :long-lived token or a limited-time token. | channel_access_token short_lived_token | channel_access_token | Yes |
| access_token | The Channel access token. | Yes, if auth_method=channel_access_token | ||
| client_id | Line Client Id. | Yes, if auth_method=short_lived_token | ||
| client_secret | Line Client Secret. | Yes, if auth_method=short_lived_token | ||
| target | The LINE Message object for which data needs to be uploaded. | - audience - push_message - multicast_message | audience | Yes |
| audience_name | Audience Group name. | Yes, if use_audience_id = false | ||
| audience_id | Audience Group ID. | Yes, if use_audience_id = true | ||
| use_audience_id | Use Audience Group ID instead of Name. | false | No | |
| is_ifa_audience | Type of audience. | true | No | |
| template_message | Template message to push. Support place_holder to customize the message. | String | Yes, if target = push_message | |
| template_message_multicast | Template message to multicast. Not supporting place_holder. | String | Yes, if target = template_message_multicast | |
| skip_invalid_message | Skip invalid message for Push Message. | Boolean | true | No |
| skip_multicast_invalid_message | Skip invalid message for Multicast Message. | Boolean | true | No |
| notification_disabled | Disable notifications for sending multicast message. | Boolean | true | No |
| custom_aggregation_units | Custom aggregation units for multicast message. | String | No | |
| batch_size_multicast | Batch size for multicast message. | Integer Must be between 1 and 500 Default: 10 | 10 | No |
| max_retry | Maximum number of retries when request failed | 8 | No | |
| initial_retry_wait | The initial amount of time before the first retry in seconds | 15 | No | |
| max_retry_wait | The maximum amount of time to wait for a retry in seconds | 3600 | No | |
| connection_timeout | The HTTP connection time out for a request to Pardot in seconds | 300 | No |
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: trueSent 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: trueSent 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- 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"
}
}
}
}- Sticker Message - Messaging API reference
{
"type": "sticker",
"packageId": "446",
"stickerId": "1988"
}- Image Message - Messaging API reference
{
"type": "image",
"originalContentUrl": "https://example.com/original.jpg",
"previewImageUrl": "https://example.com/preview.jpg"
}- Video Message - Messaging API reference
{
"type": "video",
"originalContentUrl": "https://example.com/original.mp4",
"previewImageUrl": "https://example.com/preview.jpg",
"trackingId": "track-id"
}- Audio Message - Messaging API reference
{
"type": "audio",
"originalContentUrl": "https://example.com/original.m4a",
"duration": 60000
}- 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
}- 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
}
}
]
}- 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"
}
]
}
}- 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"
}
]
}
}
}- Go to https://developers.line.biz/en/ and select login in the top right corner.

- Select Log in with LINE account.

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

- Access your Channel

- In your channel, select the Basic settings tab.
You will see Channel ID and Channel secret on this tab.
