メッセージを送信

開発者は、API を使用して指定した conversation_id にメッセージを送信できます。

リクエストメソッド

POST

リクエスト URL

https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages

認証

詳細については、API Overview の認証手順を参照してください。

プレーンテキストのリクエスト

リクエスト例

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": "カスタマーサービスがメッセージを送信しています。これは正常ですか?", "private": false, "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": "カスタマーサービスがメッセージを送信しています。これは正常ですか?",
    "private": false,
    "content_attributes": {
        "in_reply_to": 29
    }
}'

            
このコードブロックはフローティングウィンドウ内に表示されます

リクエストヘッダー

Field Type Description
Authorization string Authorization: Basic base64(API Key:API Secret) を使用して認証します。API Keys ページで API Key と API Secret を取得し、コロンで連結して Base64 でエンコードしてください。
Content-Type application/json データの種類。プレーンテキストメッセージには application/json を使用します。

パスパラメーター

Field Type Required Description
conversation_id string Yes 会話 ID。

リクエストボディパラメーター

Field Type Required Description
content String Yes メッセージの内容。
private Boolean No メッセージを非公開にするかどうか。デフォルトは false です。
content_attributes Object No コンテンツ属性。たとえば、メッセージに返信する場合は、in_reply_to フィールドにメッセージ ID を指定します。

プレーンテキストのレスポンス例

レスポンス例

{ "id": 3030, "content": "Customer service is sending a message. Is this normal?", "inbox_id": 79, "conversation_id": 141, "message_type": 1, "content_type": "text", "status": "sent", "content_attributes": {}, "created_at": 1762331029, "private": false, "source_id": null, "sorting_id": 4, "sender": { "id": 3, "name": "TEST", "available_name": "TEST", "avatar_url": "", "type": "user", "availability_status": "offline", "thumbnail": "" } }
              
              {
    "id": 3030,
    "content": "Customer service is sending a message. Is this normal?",
    "inbox_id": 79,
    "conversation_id": 141,
    "message_type": 1,
    "content_type": "text",
    "status": "sent",
    "content_attributes": {},
    "created_at": 1762331029,
    "private": false,
    "source_id": null,
    "sorting_id": 4,
    "sender": {
        "id": 3,
        "name": "TEST",
        "available_name": "TEST",
        "avatar_url": "",
        "type": "user",
        "availability_status": "offline",
        "thumbnail": ""
    }
}

            
このコードブロックはフローティングウィンドウ内に表示されます

レスポンスパラメーター

Field Type Description
id Int メッセージ ID。
content String メッセージの内容。
inbox_id Int Inbox ID。
conversation_id Int 会話 ID。
message_type Int メッセージタイプ。
content_type String コンテンツタイプ。
status String sentdelivered などのメッセージステータス。
content_attributes Object コンテンツ属性。
created_at Int メッセージ作成時のタイムスタンプ。
private Boolean メッセージを非公開にするかどうか。
source_id Int ソース ID。
sorting_id Int ソート ID。
sender Object 送信者情報。
sender.id Int 送信者 ID。
sender.name String 送信者名。
sender.available_name String 送信者の表示名。
sender.avatar_url String 送信者のアバター URL。
sender.type String user などの送信者タイプ。
sender.availability_status String offline などの送信者のオンラインステータス。
sender.thumbnail String 送信者のサムネイル。

画像、音声、その他のファイルのリクエスト

リクエスト例

curl -X POST "https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages" \ -H "Authorization: Basic base64(api_key:api_secret)" \ -F "attachments[]=@/path/to/your/file.jpg" \ -F "content=以下に詳細画像があります"
              
              curl -X POST "https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages" \
  -H "Authorization: Basic base64(api_key:api_secret)" \
  -F "attachments[]=@/path/to/your/file.jpg" \
  -F "content=以下に詳細画像があります"

            
このコードブロックはフローティングウィンドウ内に表示されます

パスパラメーター

Field Type Required Description
conversation_id string Yes 会話 ID。

画像、音声、その他のファイルのレスポンス例

レスポンス例

{ "id": 3031, "content": "Detailed image below", "inbox_id": 79, "conversation_id": 141, "message_type": 1, "content_type": "text", "status": "sent", "content_attributes": {}, "created_at": 1762331762, "private": false, "source_id": null, "sorting_id": 5, "sender": { "id": 3, "name": "Wenjie Yu", "available_name": "Wenjie Yu", "avatar_url": "", "type": "user", "availability_status": "offline", "thumbnail": "" }, "attachments": [ { "id": 199, "message_id": 3031, "file_type": "image", "account_id": 14, "extension": null, "data_url": "https://livedesk.engagelab.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/android-icon-48x48.png", "thumb_url": "https://livedesk.engagelab.com/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJY0c1bkJqb0dSVlE2RTNKbGMybDZaVjkwYjE5bWFXeHNXd2RwQWZvdyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--63c890cbf173eb3dc92a8786fcc3e120c329852d/android-icon-48x48.png", "file_size": 589136, "width": null, "height": null } ] }
              
              {
    "id": 3031,
    "content": "Detailed image below",
    "inbox_id": 79,
    "conversation_id": 141,
    "message_type": 1,
    "content_type": "text",
    "status": "sent",
    "content_attributes": {},
    "created_at": 1762331762,
    "private": false,
    "source_id": null,
    "sorting_id": 5,
    "sender": {
        "id": 3,
        "name": "Wenjie Yu",
        "available_name": "Wenjie Yu",
        "avatar_url": "",
        "type": "user",
        "availability_status": "offline",
        "thumbnail": ""
    },
    "attachments": [
        {
            "id": 199,
            "message_id": 3031,
            "file_type": "image",
            "account_id": 14,
            "extension": null,
            "data_url": "https://livedesk.engagelab.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/android-icon-48x48.png",
            "thumb_url": "https://livedesk.engagelab.com/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJY0c1bkJqb0dSVlE2RTNKbGMybDZaVjkwYjE5bWFXeHNXd2RwQWZvdyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--63c890cbf173eb3dc92a8786fcc3e120c329852d/android-icon-48x48.png",
            "file_size": 589136,
            "width": null,
            "height": null
        }
    ]
}

            
このコードブロックはフローティングウィンドウ内に表示されます

レスポンスパラメーター

Field Type Description
id Int メッセージ ID。
content String メッセージの内容。
inbox_id Int Inbox ID。
conversation_id Int 会話 ID。
message_type Int メッセージタイプ。
content_type String コンテンツタイプ。
status String sentdelivered などのメッセージステータス。
content_attributes Object コンテンツ属性。
created_at Int メッセージ作成時のタイムスタンプ。
private Boolean メッセージを非公開にするかどうか。
source_id Int ソース ID。
sorting_id Int ソート ID。
sender Object 送信者情報。
sender.id Int 送信者 ID。
sender.name String 送信者名。
sender.available_name String 送信者の表示名。
sender.avatar_url String 送信者のアバター URL。
sender.type String user などの送信者タイプ。
sender.availability_status String offline などの送信者のオンラインステータス。
sender.thumbnail String 送信者のサムネイル。
attachments Array 添付ファイル情報のリスト。
attachments.id Int 添付ファイル ID。
attachments.message_id Int 関連付けられたメッセージの ID。
attachments.file_type String image などのファイルタイプ。
attachments.account_id Int アカウント ID。
attachments.extension String ファイル拡張子。
attachments.data_url String ファイル URL。
attachments.thumb_url String サムネイル URL(画像タイプのみ)。
attachments.file_size Int バイト単位のファイルサイズ。
attachments.width Int ファイルの幅(画像タイプのみ)。
attachments.height Int ファイルの高さ(画像タイプのみ)。

WhatsApp テンプレートメッセージのリクエスト例

リクエスト例

curl -X POST 'https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \ -H 'Content-Type: application/json' \ -H 'Authorization: Basic base64(api_key:api_secret)' \ -d '{ "content": "チャット UI に表示するテキスト", "message_type": "outgoing", "template_params": { "name": "order_update", "namespace": "optional_namespace", "language": "en_US", "category": "MARKETING", "processed_params": { "1": "John", "2": "発送済み" }, "header_params": { "type": "text", "text_variables": { "1": "注文番号 #456" } }, "footer_params": { "text_variables": { "1": "Acme Corp" } }, "button_params": [ { "index": 0, "sub_type": "url", "text": "track/12345" } ] } }'
              
              curl -X POST 'https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
    "content": "チャット UI に表示するテキスト",
    "message_type": "outgoing",
    "template_params": {
      "name": "order_update",
      "namespace": "optional_namespace",
      "language": "en_US",
      "category": "MARKETING",
      "processed_params": {
        "1": "John",
        "2": "発送済み"
      },
      "header_params": {
        "type": "text",
        "text_variables": {
         "1": "注文番号 #456" }
      },
      "footer_params": {
        "text_variables": { "1": "Acme Corp" }
      },
      "button_params": [
        {
          "index": 0,
          "sub_type": "url",
          "text": "track/12345"
        }
      ]
    }
  }'

            
このコードブロックはフローティングウィンドウ内に表示されます

パスパラメーター

Field Type Required Description
conversation_id string Yes 会話 ID。

リクエストボディパラメーター

Field Type Required Description
content String Yes チャットインターフェースに表示されるメッセージの内容。
message_type String Yes メッセージタイプ。テンプレートメッセージを送信する場合は、outgoing に設定します。
template_params Object Yes テンプレートメッセージのパラメーターオブジェクト。
template_params.name String Yes テンプレート名。
template_params.namespace String No テンプレートの namespace(WhatsApp Cloud / 360Dialog で使用)。
template_params.language String Yes en_US などのテンプレート言語コード。
template_params.category String No MARKETING などのテンプレートカテゴリ。
template_params.processed_params Object No テンプレート本文の変数値。キーには変数の位置("1""2")または変数名を指定します。
template_params.header_params Object No テンプレートヘッダーコンポーネントのパラメーター。詳しくは以下の説明を参照してください。
template_params.footer_params Object No テンプレートフッターコンポーネントのパラメーター。詳しくは以下の説明を参照してください。
template_params.button_params Array No テンプレートボタンコンポーネントのパラメーター。詳しくは以下の説明を参照してください。

header_params パラメーターの説明

header_params の構造は、ヘッダータイプによって異なります。

テキストタイプ:

{ "type": "text", "text_variables": { "1": "Order #456" } }
              
              {
  "type": "text",
  "text_variables": { "1": "Order #456" }
}

            
このコードブロックはフローティングウィンドウ内に表示されます

画像タイプ:

{ "type": "image", "media_url": "https://example.com/image.jpg" }
              
              {
  "type": "image",
  "media_url": "https://example.com/image.jpg"
}

            
このコードブロックはフローティングウィンドウ内に表示されます

動画タイプ:

{ "type": "video", "media_url": "https://example.com/video.mp4" }
              
              {
  "type": "video",
  "media_url": "https://example.com/video.mp4"
}

            
このコードブロックはフローティングウィンドウ内に表示されます

ファイルタイプ:

{ "type": "document", "media_url": "https://example.com/invoice.pdf", "filename": "invoice.pdf" }
              
              {
  "type": "document",
  "media_url": "https://example.com/invoice.pdf",
  "filename": "invoice.pdf"
}

            
このコードブロックはフローティングウィンドウ内に表示されます

位置情報タイプ:

{ "type": "location", "location": { "latitude": 37.7749, "longitude": -122.4194, "name": "Acme HQ", "address": "123 Main St, San Francisco" } }
              
              {
  "type": "location",
  "location": {
    "latitude": 37.7749,
    "longitude": -122.4194,
    "name": "Acme HQ",
    "address": "123 Main St, San Francisco"
  }
}

            
このコードブロックはフローティングウィンドウ内に表示されます
Field Type Required Description
type String Yes ヘッダータイプ。サポートされる値は textimagevideodocumentlocation です。
text_variables Object No テキストタイプで使用します。キーには変数の位置、値には置換内容を指定します。
media_url String No メディアタイプで使用します。メディアファイルの URL。
filename String No ファイルタイプで使用します。ファイル名。
location Object No 位置情報タイプで使用します。
location.latitude Float Yes 緯度。
location.longitude Float Yes 経度。
location.name String No 位置情報名。
location.address String No 位置情報の住所。

footer_params パラメーターの説明

{ "text_variables": { "1": "Acme Corp" } }
              
              {
  "text_variables": { "1": "Acme Corp" }
}

            
このコードブロックはフローティングウィンドウ内に表示されます
Field Type Required Description
text_variables Object No キーには変数の位置、値には置換内容を指定します。

button_params パラメーターの説明

[ { "index": 0, "sub_type": "url", "text": "track/12345" }, { "index": 1, "sub_type": "quick_reply", "payload": "OPT_OUT" } ]
              
              [
  {
    "index": 0,
    "sub_type": "url",
    "text": "track/12345"
  },
  {
    "index": 1,
    "sub_type": "quick_reply",
    "payload": "OPT_OUT"
  }
]

            
このコードブロックはフローティングウィンドウ内に表示されます
Field Type Required Description
index Int Yes 0 から始まるボタンインデックス。
sub_type String Yes ボタンタイプ。サポートされる値は urlquick_reply です。
text String No URL タイプのボタンで使用します。URL のサフィックスまたはリダイレクトパス。
payload String No quick_reply タイプのボタンで使用します。返されるペイロードの内容。

レスポンス例

成功レスポンス

{ "id": 123, "content": "Display text for chat UI", "message_type": 1, "status": "sent", "additional_attributes": { "template_params": { "name": "order_update", "language": "en_US", "category": "MARKETING" } } }
              
              {
  "id": 123,
  "content": "Display text for chat UI",
  "message_type": 1,
  "status": "sent",
  "additional_attributes": {
    "template_params": {
      "name": "order_update",
      "language": "en_US",
      "category": "MARKETING"
    }
  }
}

            
このコードブロックはフローティングウィンドウ内に表示されます

失敗レスポンス

{ "id": 123, "status": "failed", "content_attributes": { "external_error": "131047: Re-engagement message is not allowed" } }
              
              {
  "id": 123,
  "status": "failed",
  "content_attributes": {
    "external_error": "131047: Re-engagement message is not allowed"
  }
}

            
このコードブロックはフローティングウィンドウ内に表示されます

レスポンスパラメーター

Field Type Description
id Int メッセージ ID。
content String メッセージの内容。
message_type Int メッセージタイプ。
status String sentdeliveredfailed などのメッセージステータス。
additional_attributes Object 追加属性。
additional_attributes.template_params Object 送信されたテンプレートパラメーターに関する情報。
content_attributes Object コンテンツ属性。送信に失敗した場合は、エラー情報が含まれます。
content_attributes.external_error String メッセージ送信に失敗した場合に返される外部エラー情報。

失敗したメッセージを再試行する

メッセージのステータスが failed の場合は、次のエンドポイントを使用してメッセージのステータスをリセットし、再送信します。

リクエスト URL

POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages/:message_id/retry

パスパラメーター

Field Type Required Description
conversation_id string Yes 会話 ID。
message_id string Yes メッセージ ID。
Icon Solid Transparent White Qiyu
お問い合わせ