APIチャンネルでメッセージを送信する方法
API Channel は暗黙的なコンタクト作成をサポートしていません。LivedDesk では、API Channel を 3 つのステップで使用します:
- コンタクトを作成する
- コンタクト情報に基づいて会話を作成する
- メッセージを送信する
コンタクトの作成
API エンドポイント
https://livedesk-api.engagelab.com/api/v2/accounts/contacts
リクエスト例
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/contacts \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407,
"name": "Test", // Optional
"email": "alice@acme.inc",
"phone_number": "+123456789",
"avatar_url": "https://example.com/avatar.png",
"identifier": "1234567890",
}
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/contacts \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407,
"name": "Test", // Optional
"email": "alice@acme.inc",
"phone_number": "+123456789",
"avatar_url": "https://example.com/avatar.png",
"identifier": "1234567890",
}
このコードブロックはフローティングウィンドウ内に表示されます
リクエストヘッダー
| Field | Type | Description |
|---|---|---|
| Authorization | string | 認証には Authorization: Basic base64(API Key:API Secret) を使用してください。API Key ページにアクセスして API Key と API Secret を取得し、コロンで結合してから Base64 エンコードしてください。 |
| Content-Type | application/json | データ型は、プレーンテキストメッセージには application/json を使用してください。 |
リクエストボディパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | channel ID. 「プロジェクト設定-チャンネル-特定のチャンネル-設定」のチャンネル ID に対応します。 |
| name | String | No | コンタクト名。 |
| String | No | メールアドレス。 | |
| phone_number | String | No | 連絡方法。 |
| avatar_url | String | No | 添付ファイルリンク。 |
| identifier | String | No | ユーザー識別子。 |
レスポンス例
{
"payload": {
"contact": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219259,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571703,
"contact_inboxes": []
},
"contact_inbox": {
"inbox": null,
"source_id": null
}
}
}
{
"payload": {
"contact": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219259,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571703,
"contact_inboxes": []
},
"contact_inbox": {
"inbox": null,
"source_id": null
}
}
}
このコードブロックはフローティングウィンドウ内に表示されます
レスポンスパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| additional_attributes | Object | No | 添付ファイルの属性。 |
| availability_status | String | No | オンライン状態、デフォルトは offline。 |
| String | No | メールアドレス。 | |
| id | String | No | コンタクト ID。 |
| name | String | No | 名前 |
| phone_number | String | No | 電話番号。 |
| blocked | String | No | ロックされているかどうか、デフォルトは false。 |
| identifier | String | No | ユーザー識別子。 |
| thumbnail | String | No | ユーザー識別子。 |
| custom_attributes | String | No | 顧客属性。 |
| created_at | String | No | 作成タイムスタンプ。 |
| contact_inboxes | Array | No | ユーザー識別子。 |
| inbox | String | No | channel channel。 |
| source_id | String | No | ソース ID。 |
会話の作成
API エンドポイント
https://livedesk-api.engagelab.com/api/v2/accounts/conversations
リクエスト例
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407, // Required
"contact_id": 2219256, // Either contact_id or source_id can be passed, but it must correctly identify the sender
"source_id": "123456789"
}
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407, // Required
"contact_id": 2219256, // Either contact_id or source_id can be passed, but it must correctly identify the sender
"source_id": "123456789"
}
このコードブロックはフローティングウィンドウ内に表示されます
リクエストヘッダー
| Field | Type | Description |
|---|---|---|
| Authorization | string | 認証には Authorization: Basic base64(API Key:API Secret) を使用してください。API Key ページにアクセスして API Key と API Secret を取得し、コロンで結合してから Base64 エンコードしてください。 |
| Content-Type | application/json | データ型は、プレーンテキストメッセージには application/json を使用してください。 |
リクエストボディパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | channel ID. コンタクト作成インターフェースで使用される ID と同じです。 |
| contact_id | String | No | コンタクト ID。コンタクト作成インターフェースのレスポンスからの id |
| source_id | String | No | ソース ID。 |
レスポンス例
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219256,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571624
},
"channel": "Channel::Api",
"hmac_verified": false
},
"id": 40,
"messages": [],
"account_id": 17623000010928,
"uuid": "660ce36f-46bb-4153-948c-8a26e6dab634",
"inbox_id": 407,
"additional_attributes": {},
"agent_last_seen_at": 0,
"assignee_last_seen_at": 0,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"priority": null,
"conversation_category": "chat",
"chat_mode": "private_chat",
"is_forum": false,
"created_at": 1766572062,
"updated_at": 1766572062.5803902,
"timestamp": 1766572062,
"first_reply_created_at": 0,
"unread_count": 0,
"last_non_activity_message": null,
"last_activity_at": 1766572062,
"waiting_since": 1766572062,
"sla_policy_id": null,
"ticket_id": null,
"over_limit": false,
"content_preview": {
"content": null,
"message_type": null,
"created_at": null
},
"platform": {
"channel_type": "Channel::Api",
"inbox_name": "JennyApi",
"inbox_id": 407
},
"account_info": {
"contact_name": "Test",
"contact_email": null,
"contact_phone": null,
"contact_id": 2219256,
"contact_avatar": ""
},
"assignment": {
"assignee_id": null,
"assignee_name": null,
"assignee_email": null,
"team_id": null,
"team_name": null
}
}
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219256,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571624
},
"channel": "Channel::Api",
"hmac_verified": false
},
"id": 40,
"messages": [],
"account_id": 17623000010928,
"uuid": "660ce36f-46bb-4153-948c-8a26e6dab634",
"inbox_id": 407,
"additional_attributes": {},
"agent_last_seen_at": 0,
"assignee_last_seen_at": 0,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"priority": null,
"conversation_category": "chat",
"chat_mode": "private_chat",
"is_forum": false,
"created_at": 1766572062,
"updated_at": 1766572062.5803902,
"timestamp": 1766572062,
"first_reply_created_at": 0,
"unread_count": 0,
"last_non_activity_message": null,
"last_activity_at": 1766572062,
"waiting_since": 1766572062,
"sla_policy_id": null,
"ticket_id": null,
"over_limit": false,
"content_preview": {
"content": null,
"message_type": null,
"created_at": null
},
"platform": {
"channel_type": "Channel::Api",
"inbox_name": "JennyApi",
"inbox_id": 407
},
"account_info": {
"contact_name": "Test",
"contact_email": null,
"contact_phone": null,
"contact_id": 2219256,
"contact_avatar": ""
},
"assignment": {
"assignee_id": null,
"assignee_name": null,
"assignee_email": null,
"team_id": null,
"team_name": null
}
}
このコードブロックはフローティングウィンドウ内に表示されます
レスポンスパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| meta | Object | No | メタデータオブジェクト。 |
| sender | Object | No | 送信者情報。 |
| additional_attributes | Object | No | 追加の属性。 |
| availability_status | String | No | 利用可能な状態。 |
| Null | No | メール。 | |
| id | Number | No | コンタクト ID。 |
| name | String | No | 送信者名。 |
| phone_number | Null | No | 電話番号。 |
| blocked | Boolean | No | ブロックされているかどうか。 |
| identifier | Null | No | ユーザー属性識別子。 |
| thumbnail | String | No | サムネイル。 |
| custom_attributes | Object | No | カスタム属性。 |
| created_at | Number | No | 会話作成タイムスタンプ。 |
| channel | String | No | チャンネルタイプ。 |
| hmac_verified | Boolean | No | HMAC 検証ステータス。 |
| id | Number | No | 会話 ID。 |
| messages | Array | No | メッセージ配列。 |
| account_id | Number | No | プロジェクト ID |
| uuid | String | No | 一意の識別子。 |
| inbox_id | Number | No | チャンネル ID。 |
| additional_attributes | Object | No | 追加の属性。 |
| agent_last_seen_at | Number | No | エージェント最終処理時間。 |
| assignee_last_seen_at | Number | No | 担当者最終処理時間。 |
| can_reply | Boolean | No | 返信可能かどうか。 |
| contact_last_seen_at | Number | No | コンタクト最終確認時間。 |
| custom_attributes | Object | No | カスタム属性。 |
| labels | Array | No | ラベル配列。 |
| muted | Boolean | No | ミュートされているかどうか。 |
| snoozed_until | Null | No | 一時停止されるまで。 |
| status | String | No | ステータス。 |
| priority | Null | No | 優先度。 |
| conversation_category | String | No | 会話カテゴリ。 |
| chat_mode | String | No | チャットモード。 |
| is_forum | Boolean | No | フォーラムかどうか。 |
| created_at | Number | No | 作成タイムスタンプ。 |
| updated_at | Number | No | 更新タイムスタンプ。 |
| timestamp | Number | No | タイムスタンプ。 |
| first_reply_created_at | Number | No | 最初の返信作成時間。 |
| unread_count | Number | No | 未読数。 |
| last_non_activity_message | Null | No | 最後の非アクティビティメッセージ。 |
| last_activity_at | Number | No | 最終アクティビティ時間。 |
| waiting_since | Number | No | 待機開始時間。 |
| sla_policy_id | Null | No | SLA ポリシー ID。 |
| ticket_id | Null | No | チケット ID。 |
| over_limit | Boolean | No | 制限を超えているかどうか。 |
| content_preview | Object | No | コンテンツプレビュー。 |
| content_preview.content | Null | No | プレビューコンテンツ。 |
| content_preview.message_type | Null | No | メッセージタイプ。 |
| content_preview.created_at | Null | No | 作成時間。 |
| platform | Object | No | プラットフォーム情報。 |
| channel_type | String | No | チャンネルタイプ。 |
| inbox_name | String | No | インボックス名。 |
| inbox_id | Number | No | インボックス ID。 |
| account_info | Object | No | アカウント情報。 |
| contact_name | String | No | コンタクト名。 |
| contact_email | Null | No | コンタクトメール。 |
| contact_phone | Null | No | コンタクト電話。 |
| contact_id | Number | No | コンタクト ID。 |
| contact_avatar | String | No | コンタクトアバター。 |
| assignment | Object | No | 割り当て情報。 |
| assignee_id | Null | No | 担当者 ID。 |
| assignee_name | Null | No | 担当者名。 |
| assignee_email | Null | No | 担当者メール。 |
| team_id | Null | No | チーム ID。 |
| team_name | Null | No | チーム名。 |
メッセージの送信
API エンドポイント
https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages
リクエスト例
curl -X POST 'https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"content": "Customer service sends a message, is it normal?",
"private": false,
"message_type": "incoming",
"content_attributes": {
"in_reply_to": 29
}
}'
curl -X POST 'https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"content": "Customer service sends a message, is it normal?",
"private": false,
"message_type": "incoming",
"content_attributes": {
"in_reply_to": 29
}
}'
このコードブロックはフローティングウィンドウ内に表示されます
リクエストヘッダー
| Field | Type | Description |
|---|---|---|
| Authorization | string | 認証には Authorization: Basic base64(API Key:API Secret) を使用してください。API Key ページにアクセスして API Key と API Secret を取得し、コロンで結合してから Base64 エンコードしてください。 |
| Content-Type | application/json | データ型は、プレーンテキストメッセージには application/json を使用してください。 |
リクエストボディパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| content | String | No | channel ID. 「プロジェクト設定-チャンネル-特定のチャンネル-設定」のチャンネル ID に対応します。 |
| private | String | No | コンタクト名。 |
| message_type | String | No | メッセージタイプ、outgoing または incoming。それぞれカスタマーサービス送信またはユーザー送信を表します。渡されない場合、デフォルトは outgoing になります。 |
| %content_attributes | String | No | コンテンツ属性。 |
| in_reply_to | String | No | 返信コンテンツ。 |

