LINEは、アジアにおいて、米国のモバイルユーザーにとってのFacebook MessagingやInstagramのような存在です。友人とのコミュニケーションや、お気に入りの製品やサービスに関する新しいプロモーションを発見するための、高速で簡単な手段です。LINEは日本と台湾で第1位のモバイルメッセージングプラットフォームであり、最大級の広告配信プラットフォームの1つでもあります。
このTDエクスポート連携により、Treasure Dataからジョブ結果を直接LINEメッセージングアカウントに書き込むことができます。
- Treasure DataからユーザーIDまたはIFAをLINEアカウントにエクスポートする。
- ユーザー、グループ、ルームに2つの方法でメッセージを送信:
- Push Message - 単一のユーザーにメッセージを送信。
- Multicast Message - 複数のユーザーにメッセージを送信。
- LINEメッセージへのメッセージ送信をサポート。10種類のタイプをサポート:
- 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
- Treasure Dataの基本知識
- LINEメッセージングの基本知識
- 公式LINEメッセージングアカウント
- Treasure Dataはデータの有効性を検証しません。Treasure Dataはアップロード前にNULLまたは空のデータのみをフィルタリングします。
データをエクスポートするクエリを実行する前に、Treasure Dataコンソールでデータ連携を作成および設定する必要があります。データ連携の一部として、連携にアクセスするための認証資格情報を提供します。
LINEは2つの認証方法をサポートしています:
- Channel Access Token (デフォルト)
- Short-Lived Token
- TD Consoleを開きます。
- Integrations Hub > Catalogに移動します。
- LINEを検索し、LINE Messagingを選択します。
- Create Authenticationを選択します。
- Authentication Methodドロップダウンから、Channel Access Tokenを選択します。
- LINEアカウントへの認証に使用されるLINE MessagingのChannel Access Tokenを入力します。
- Continueを選択します。
- 連携の名前を入力します。
- Doneを選択します。
- TD Consoleを開きます。
- Integrations Hub > Catalogに移動します。
- LINEを検索し、LINE Messagingを選択します。
- Create Authenticationを選択します。
- Authentication Methodドロップダウンから、Short Lived Tokenを選択します。
- LINE Messaging Channel Idを入力します。
- Channel Secretを入力します。
- Continueを選択します。
- 連携の名前を入力します。
- Doneを選択します。
- Data Workbench > Queriesに移動します。
- New Queryを選択します。
- databaseドロップダウンで、クエリしたいデータベースを入力します。この例ではtest_dbを使用します。
- クエリペインで、SQLクエリを入力します。
- Runを選択してクエリの結果を検証します。
ターゲット: Audience

ターゲット: Push Message

ターゲット: Multicast Message

注意:
Push MessageとMulticast Messageの2つのターゲットでは、受信者IDをスキーマで定義する必要があります。
Push Messageターゲットは、Template Message内でプレースホルダーをサポートします。
- プレースホルダーは{{ ... }}内に含まれる変数であり、スキーマで完全に定義する必要があります。各レコードの対応する値で置き換えられます。
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": "{{product_id}}",
"emojiId": "{{emoji_id}}"
},
"everyone": {
"type": "mention",
"mentionee": {
"type": "all"
}
}
}
}- Multicast Messageを使用する場合は、受信者IDカラムのみを定義する必要があります。
- Export Resultsを選択します。

- 外部サービスに結果をエクスポートするには、既存の認証を使用するか、新しい認証を作成します。次のいずれかを選択します。
- Use Existing Integration
- Create New Integration
Use Existing Integration
- Use Existing Integrationを選択します。
- 使用したい既存の連携を選択します。この例ではline_messaging_output_testを使用します。

- フォームに情報を入力します。
4. Doneを選択します。
| フィールド | 説明 |
|---|---|
| Target | データをアップロードする必要があるLINE Messageオブジェクト。サポートされるオブジェクト: - Audience - Push Message - Multicast Message |
| Use existing LINE Audience ID to push an audience | Audience NameではなくAudience IDを指定してオーディエンスをAudience Groupにアップロードします。 |
| Audience Name | Audience Nameを指定してオーディエンスをAudience Groupにアップロードします。 |
| Is IFAs Audience? | IFAオーディエンスをアップロードする場合は、このチェックボックスを選択します。それ以外の場合は、LINE User IDが使用されます。 |
| Template Message | テキストメッセージの入力エリア。 |
| Skip Invalid Message | 無効なメッセージをスキップし、有効なメッセージのみを送信する場合に有効にします。無効にした場合、無効なメッセージがあるとエラーメッセージが表示されます。 |
| Notification Disabled | サイレントでメッセージを送信する場合に有効にします。(デフォルト=False) |
| Custom Aggregation Units | 集計単位の名前。大文字と小文字が区別されます。例えば、Promotion_aとPromotion_Aは異なる単位名として扱われます。 - 最大単位数: 1 - 最大文字数: 30 - サポートされる文字タイプ: 半角英数字 (a-z, A-Z, 0-9) およびアンダースコア (_) |
新しいIntegrationを作成する
- Create New Integrationを選択します。
- TypeドロップダウンからLINE Messagingを選択します。
- 新しいintegrationの名前を入力します。
- Authentication MethodドロップダウンからChannel Access TokenまたはShort Lived Tokenを選択します。
- フォームに残りの情報を入力します。
6. Nextを選択します。 7. Export Resultsフォームに情報を入力します。 8. Doneを選択します。
| フィールド | 説明 |
|---|---|
| Name | このIntegrationの名前。 |
| Channel Access Token | LINEチャネルアクセストークンまたは永続的に有効な長期トークン。 |
| Chanel Id | LINEチャネルID (短期トークン認証用)。 |
| Channel Secret | LINEチャネルシークレット (短期トークン認証用) |
| Maximum Retry | システムが諦めるまでの再試行回数。デフォルト: 7 |
| Seconds to Wait For First Retry | 最初と2回目の試行の間の時間 (秒単位)。デフォルト: 15 |
| Seconds for Max Retry Wait | 2回目以降のすべての試行の間の時間 (秒単位)。デフォルト: 3600 |
| Seconds for Connection Timeout | HTTP呼び出し操作が中止されるまでの待機時間 (秒単位)。デフォルトは300 |
| Use existing LINE Audience ID to push an audience | Audience NameではなくAudience IDを指定してオーディエンスをAudience Groupにアップロードします。 |
| Audience Name | Audience Nameを指定してオーディエンスをAudience Groupにアップロードします。 |
| Is IFAs Audience? | IFAオーディエンスをアップロードする場合は、このチェックボックスを選択します。それ以外の場合は、LINE User IDが使用されます。 |
SELECT my_col as id FROM www_accessScheduled Jobs と Result Export を使用して、指定したターゲット宛先に出力結果を定期的に書き込むことができます。
Treasure Data のスケジューラー機能は、高可用性を実現するために定期的なクエリ実行をサポートしています。
2 つの仕様が競合するスケジュール仕様を提供する場合、より頻繁に実行するよう要求する仕様が優先され、もう一方のスケジュール仕様は無視されます。
例えば、cron スケジュールが '0 0 1 * 1' の場合、「月の日」の仕様と「週の曜日」が矛盾します。前者の仕様は毎月 1 日の午前 0 時 (00:00) に実行することを要求し、後者の仕様は毎週月曜日の午前 0 時 (00:00) に実行することを要求するためです。後者の仕様が優先されます。
Data Workbench > Queries に移動します
新しいクエリを作成するか、既存のクエリを選択します。
Schedule の横にある None を選択します。

ドロップダウンで、次のスケジュールオプションのいずれかを選択します:

ドロップダウン値 説明 Custom cron... Custom cron... の詳細を参照してください。 @daily (midnight) 指定されたタイムゾーンで 1 日 1 回午前 0 時 (00:00 am) に実行します。 @hourly (:00) 毎時 00 分に実行します。 None スケジュールなし。

| Cron 値 | 説明 |
|---|---|
0 * * * * | 1 時間に 1 回実行します。 |
0 0 * * * | 1 日 1 回午前 0 時に実行します。 |
0 0 1 * * | 毎月 1 日の午前 0 時に 1 回実行します。 |
| "" | スケジュールされた実行時刻のないジョブを作成します。 |
* * * * *
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)次の名前付きエントリを使用できます:
- Day of Week: sun, mon, tue, wed, thu, fri, sat.
- Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.
各フィールド間には単一のスペースが必要です。各フィールドの値は、次のもので構成できます:
| フィールド値 | 例 | 例の説明 |
|---|---|---|
| 各フィールドに対して上記で表示された制限内の単一の値。 | ||
フィールドに基づく制限がないことを示すワイルドカード '*'。 | '0 0 1 * *' | 毎月 1 日の午前 0 時 (00:00) に実行するようにスケジュールを設定します。 |
範囲 '2-5' フィールドの許可される値の範囲を示します。 | '0 0 1-10 * *' | 毎月 1 日から 10 日までの午前 0 時 (00:00) に実行するようにスケジュールを設定します。 |
カンマ区切りの値のリスト '2,3,4,5' フィールドの許可される値のリストを示します。 | 0 0 1,11,21 * *' | 毎月 1 日、11 日、21 日の午前 0 時 (00:00) に実行するようにスケジュールを設定します。 |
周期性インジケータ '*/5' フィールドの有効な値の範囲に基づいて、 スケジュールが実行を許可される頻度を表現します。 | '30 */2 1 * *' | 毎月 1 日、00:30 から 2 時間ごとに実行するようにスケジュールを設定します。 '0 0 */5 * *' は、毎月 5 日から 5 日ごとに午前 0 時 (00:00) に実行するようにスケジュールを設定します。 |
'*' ワイルドカードを除く上記の いずれかのカンマ区切りリストもサポートされています '2,*/5,8-10' | '0 0 5,*/10,25 * *' | 毎月 5 日、10 日、20 日、25 日の午前 0 時 (00:00) に実行するようにスケジュールを設定します。 |
- (オプション) Delay execution を有効にすることで、クエリの開始時刻を遅延させることができます。
クエリに名前を付けて保存して実行するか、単にクエリを実行します。クエリが正常に完了すると、クエリ結果は指定された宛先に自動的にエクスポートされます。
設定エラーにより継続的に失敗するスケジュールジョブは、複数回通知された後、システム側で無効化される場合があります。
(オプション) Delay execution を有効にすることで、クエリの開始時刻を遅延させることができます。
Audience Studio で activation を作成することで、segment データをターゲットプラットフォームに送信することもできます。
- Audience Studio に移動します。
- parent segment を選択します。
- ターゲット segment を開き、右クリックして、Create Activation を選択します。
- Details パネルで、Activation 名を入力し、前述の Configuration Parameters のセクションに従って activation を設定します。
- Output Mapping パネルで activation 出力をカスタマイズします。

- Attribute Columns
- Export All Columns を選択すると、変更を加えずにすべての列をエクスポートできます。
- + Add Columns を選択して、エクスポート用の特定の列を追加します。Output Column Name には、Source 列名と同じ名前があらかじめ入力されます。Output Column Name を更新できます。+ Add Columns を選択し続けて、activation 出力用の新しい列を追加します。
- String Builder
- + Add string を選択して、エクスポート用の文字列を作成します。次の値から選択します:
- String: 任意の値を選択します。テキストを使用してカスタム値を作成します。
- Timestamp: エクスポートの日時。
- Segment Id: segment ID 番号。
- Segment Name: segment 名。
- Audience Id: parent segment 番号。
- + Add string を選択して、エクスポート用の文字列を作成します。次の値から選択します:
- Schedule を設定します。

- スケジュールを定義する値を選択し、オプションでメール通知を含めます。
- Create を選択します。
batch journey の activation を作成する必要がある場合は、Creating a Batch Journey Activation を参照してください。
Treasure Workflow内で、このデータコネクタを使用してデータをエクスポートするように指定できます。
ワークフローを使用してデータをエクスポートする方法と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: trueTD Toolbeltが提供するCLIを使用して、クエリ結果をLINE messagingにエクスポートすることもできます。
td queryコマンドを使用する場合、--result RESULT_URLオプションでLINE messagingサーバーのURLを指定します。詳細については、td queryを参照してください。
オプションの形式はJSONで、一般的な構造は以下の通りです。
または
パラメータ
| Name | Description | Value | Default Value | Required |
|---|---|---|---|---|
| type | エクスポート先のサービス名を記述します。 | line_messaging | Yes | |
| auth_method | 認証方法は、長期トークンまたは期限付きトークンのいずれかを指定できます。 | channel_access_token short_lived_token | channel_access_token | Yes |
| access_token | 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 | データをアップロードする必要があるLINE Messageオブジェクト。 | - audience - push_message - multicast_message | audience | Yes |
| audience_name | Audience Group名。 | Yes, if use_audience_id = false | ||
| audience_id | Audience Group ID。 | Yes, if use_audience_id = true | ||
| use_audience_id | Audience Group Nameの代わりにIDを使用します。 | false | No | |
| is_ifa_audience | オーディエンスのタイプ。 | true | No | |
| template_message | プッシュするテンプレートメッセージ。メッセージをカスタマイズするためのplace_holderをサポートします。 | String | Yes, if target = push_message | |
| template_message_multicast | マルチキャストするテンプレートメッセージ。place_holderはサポートしていません。 | String | Yes, if target = template_message_multicast | |
| skip_invalid_message | Push Messageの無効なメッセージをスキップします。 | Boolean | true | No |
| skip_multicast_invalid_message | Multicast Messageの無効なメッセージをスキップします。 | Boolean | true | No |
| notification_disabled | マルチキャストメッセージ送信時の通知を無効にします。 | Boolean | true | No |
| custom_aggregation_units | マルチキャストメッセージのカスタム集計単位。 | String | No | |
| batch_size_multicast | マルチキャストメッセージのバッチサイズ。 | Integer 1から500の間である必要があります デフォルト: 10 | 10 | No |
| max_retry | リクエストが失敗した場合の最大再試行回数 | 8 | No | |
| initial_retry_wait | 最初の再試行前の初期待機時間 (秒単位) | 15 | No | |
| max_retry_wait | 再試行の最大待機時間 (秒単位) | 3600 | No | |
| connection_timeout | Pardotへのリクエストに対するHTTP接続タイムアウト (秒単位) | 300 | No |
Channel Access Tokenによる認証
out:
type: line_messaging
access_token: xxxx
auth_method: channel_access_token
...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プッシュメッセージの送信
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マルチキャストメッセージの送信
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- テキストメッセージ - Messaging APIリファレンス
{
"type": "text",
"text": "Hello, world"
} 2. テキストメッセージV2 - Messaging APIリファレンス
{
"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"
}
}
}
}- スティッカーメッセージ - Messaging APIリファレンス
{
"type": "sticker",
"packageId": "446",
"stickerId": "1988"
}- 画像メッセージ - Messaging APIリファレンス
{
"type": "image",
"originalContentUrl": "https://example.com/original.jpg",
"previewImageUrl": "https://example.com/preview.jpg"
}- 動画メッセージ - Messaging APIリファレンス
{
"type": "video",
"originalContentUrl": "https://example.com/original.mp4",
"previewImageUrl": "https://example.com/preview.jpg",
"trackingId": "track-id"
}- 音声メッセージ - Messaging APIリファレンス
{
"type": "audio",
"originalContentUrl": "https://example.com/original.m4a",
"duration": 60000
}- 位置情報メッセージ - Messaging APIリファレンス
{
{
"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 リファレンス
{
"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 リファレンス
{
"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 リファレンス
{
"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"
}
]
}
}
}- https://developers.line.biz/en/ にアクセスし、右上の login を選択します。

- Log in with LINE account を選択します。

- LINE 公式アカウントのユーザー名とパスワードを入力し、Log in を選択します。

- チャネルにアクセスします

- チャネルで Basic settings タブを選択します。
このタブに Channel ID と Channel secret が表示されます。
