メッセージ送信

開発者は API を通じて指定された 会話ID にメッセージを送信できます。

リクエストメソッド

POST

リクエストURL

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

認証

認証方式の詳細については API 概要 を参照してください。

テキストリクエスト

リクエスト例

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   
    }
}'

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

リクエストヘッダー

フィールド 説明
Authorization string Authorization: Basic base64(API Key:API Secret) を使用して認証を行います。API キーページで API Key と API Secret を取得し、両者をコロンで連結した上で Base64 エンコードしてください。
Content-Type application/json データタイプ。通常のテキストメッセージでは application/json を使用します。

パスパラメータ

フィールド 必須 説明
conversation_id string はい 会話ID。

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

フィールド 必須 説明
content String はい メッセージ内容。
private Boolean いいえ プライベートメッセージかどうか。デフォルトは false。
content_attributes Object いいえ コンテンツ属性。例えばメッセージに返信する際は in_reply_to フィールドでメッセージIDを指定します。

テキストレスポンス例

レスポンス例

{ "id": 3030, "content": "エージェントがメッセージを送信しています、正常ですか", "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": "エージェントがメッセージを送信しています、正常ですか",
    "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 Int メッセージID。
content String メッセージ内容。
inbox_id Int 受信箱ID。
conversation_id Int 会話ID。
message_type Int メッセージタイプ。
content_type String コンテンツタイプ。
status String メッセージステータス。例: "sent"、"delivered" など。
content_attributes Object コンテンツ属性。
created_at Int メッセージ作成タイムスタンプ。
private Boolean プライベートメッセージかどうか。
source_id Int ソースID。
sorting_id Int ソートID。
sender Object 送信者情報。
id Int 送信者ID。
name String 送信者名。
available_name String 送信者表示名。
avatar_url String 送信者アバターURL。
type String 送信者タイプ(例: user)。
availability_status String 送信者オンライン状態(例: offline)。
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[]=@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[]=@attachments[]=@/path/to/your/file.jpg" \
  -F "content=詳細画像は以下の通りです" 

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

パスパラメータ

フィールド 必須 説明
conversation_id string はい 会話ID。

画像/音声などのファイルレスポンス例

レスポンス例

{ "id": 3031, "content": "詳細画像は以下の通りです", "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": "詳細画像は以下の通りです",
    "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 Int メッセージID。
content String メッセージ内容。
inbox_id Int 受信箱ID。
conversation_id Int 会話ID。
message_type Int メッセージタイプ。
content_type String コンテンツタイプ。
status String メッセージステータス。例: "sent"、"delivered" など。
content_attributes Object コンテンツ属性。
created_at Int メッセージ作成タイムスタンプ。
private Boolean プライベートメッセージかどうか。
source_id Int ソースID。
sorting_id Int ソートID。
sender Object 送信者情報。
id Int 送信者ID。
name String 送信者名。
available_name String 送信者表示名。
avatar_url String 送信者アバターURL。
type String 送信者タイプ(例: user)。
availability_status String 送信者オンライン状態(例: offline)。
thumbnail String 送信者サムネイル。
attachments Array 添付ファイル情報のリスト。
id Int 添付ファイルID。
message_id Int 所属メッセージID。
file_type String ファイルタイプ(例: image)。
account_id Int アカウントID。
extension String ファイル拡張子。
data_url String ファイルURL。
thumb_url String サムネイルURL(画像タイプのみ)。
file_size Int ファイルサイズ(バイト)。
width Int ファイル幅(画像タイプのみ)。
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株式会社" } }, "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株式会社" }
      },
      "button_params": [
        {
          "index": 0,
          "sub_type": "url",
          "text": "track/12345"
        }
      ]
    }
  }'

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

パスパラメータ

フィールド 必須 説明
conversation_id string はい 会話ID。

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

フィールド 必須 説明
content String はい メッセージ内容。チャットUIでの表示に使用します。
message_type String はい メッセージタイプ。テンプレートメッセージ送信時は outgoing で固定。
template_params Object はい テンプレートメッセージパラメータオブジェクト。
name String はい テンプレート名。
namespace String いいえ テンプレート名前空間(WhatsApp Cloud / 360Dialog で使用)。
language String はい テンプレート言語コード。例: en_US
category String いいえ テンプレートカテゴリ。例: MARKETING
processed_params Object いいえ テンプレート本文の変数値。Key は変数位置("1""2")または変数名。
header_params Object いいえ テンプレートヘッダーコンポーネントパラメータ。詳細は下記を参照。
footer_params Object いいえ テンプレートフッターコンポーネントパラメータ。詳細は下記を参照。
button_params Array いいえ テンプレートボタンコンポーネントパラメータ。詳細は下記を参照。

header_params パラメータ説明

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

テキストタイプ:

{ "type": "text", "text_variables": { "1": "注文 #456" } }
              
              {
  "type": "text",
  "text_variables": { "1": "注文 #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本社", "address": "サンフランシスコ市メインストリート123" } }
              
              {
  "type": "location",
  "location": {
    "latitude": 37.7749,
    "longitude": -122.4194,
    "name": "Acme本社",
    "address": "サンフランシスコ市メインストリート123"
  }
}

            
このコードブロックはフローティングウィンドウ内に表示されます
フィールド 必須 説明
type String はい ヘッダータイプ。textimagevideodocumentlocation をサポート。
text_variables Object いいえ テキストタイプ時に使用。Key は変数位置、Value は置換内容。
media_url String いいえ メディアタイプ時に使用。メディアファイルのURL。
filename String いいえ ドキュメントタイプ時に使用。ファイル名。
location Object いいえ 位置情報タイプ時に使用。
latitude Float はい 緯度。
longitude Float はい 経度。
name String いいえ 位置名。
address String いいえ 位置の住所。
{ "text_variables": { "1": "Acme株式会社" } }
              
              {
  "text_variables": { "1": "Acme株式会社" }
}

            
このコードブロックはフローティングウィンドウ内に表示されます
フィールド 必須 説明
text_variables Object いいえ Key は変数位置、Value は置換内容。

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"
  }
]

            
このコードブロックはフローティングウィンドウ内に表示されます
フィールド 必須 説明
index Int はい ボタンインデックス。0 から始まります。
sub_type String はい ボタンタイプ。urlquick_reply をサポート。
text String いいえ URL タイプボタン時に使用。URL サフィックスまたはリダイレクトパス。
payload String いいえ quick_reply タイプボタン時に使用。返却される payload の内容。

レスポンス例

成功レスポンス

{ "id": 123, "content": "チャットUI表示テキスト", "message_type": 1, "status": "sent", "additional_attributes": { "template_params": { "name": "order_update", "language": "en_US", "category": "MARKETING" } } }
              
              {
  "id": 123,
  "content": "チャット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"
  }
}

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

レスポンスパラメータ

フィールド 説明
id Int メッセージID。
content String メッセージ内容。
message_type Int メッセージタイプ。
status String メッセージステータス。例: sentdeliveredfailed など。
additional_attributes Object 追加属性。
template_params Object 送信済みのテンプレートパラメータ情報。
content_attributes Object コンテンツ属性。送信失敗時はエラー情報を含みます。
external_error String 外部エラー情報。メッセージ送信失敗時に返却されます。

失敗メッセージの再試行

メッセージステータスが failed の場合、以下のAPIでメッセージステータスをリセットして再送信できます:

リクエストURL

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

パスパラメータ

フィールド 必須 説明
conversation_id string はい 会話ID。
message_id string はい メッセージID。
Icon Solid Transparent White Qiyu
お問い合わせ