> For the complete documentation index, see [llms.txt](https://docs.innopaas.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.innopaas.com/api-reference/whatsapp-business-api/webhook/li-shi-xiao-xi.md).

# 历史消息

| 字段                       | 数据类型    | 是否必填 | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------------ | ------- | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| wabaId                   | String  | 是    | WabaId                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| sender                   | String  | 是    | sender 号码                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| phoneNumberId            | String  | 是    | sender ID                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| history                  | Array   | 否    | 创建号码时收集的企业电话号码显示名称，或编辑已批准的显示名称时提交的名称                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| --metadata               |         | 否    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| -- --phase               | Integer | 是    | 参数值来监控阶段进度。值`2`表示当前阶段已完成。表示历史记录[阶段](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/history#phases-and-chunks)。值可以是：\* `0`— 表示消息来自第 0 天（商家接入时间）到第 1 天\* `1`— 表示消息来自第 1 天到第 90 天\* `2`— 表示消息来自第 90 天到第 180 天                                                                                                                                                                                                                                                                                                                            |
| -- --chunk\_order        | Integer | 是    | 参数值按顺序排列这些块，因为它们可能并非按顺序送达。表示[块](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/history#phases-and-chunks)编号，可用于对一系列 Webhook 进行排序。                                                                                                                                                                                                                                                                                                                                                                                                     |
| -- --progress            | Integer | 是    | 参数值来监控整体进度。值`100`表示同步已完成。表示同步进度的总百分比。最小值为`0`，最大值为`100`。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --threads                |         | 否    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| -- --id                  | String  | 是    | WhatsApp 用户的电话号码。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| -- --messages            | String  | 是    | 消息数组                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| -- -- --from             | String  | 是    | 务客户的电话号码或 WhatsApp 用户的电话号码。如果此值为商家的电话号码，则消息对象描述由商家发送给 WhatsApp 用户的消息。如果此值为 WhatsApp 用户的电话号码，则消息对象描述由 WhatsApp 用户发送给商家的消息。                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| -- -- --id               | String  | 是    | WhatsApp 消息编号。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -- -- --timestamp        | String  | 是    | Unix 时间戳，表示收信人设备收到消息的时间。如：1738796547                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| -- -- --type             | String  | 是    | [消息类型](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages)。请注意，此占位符在以上语法中出现了两次，因为它同时被用作`type`属性值及其匹配属性名称的占位符。请参阅[下方的 Payload 示例](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/history#examples)，以查看包含各种消息类型的对话。如果此值设为`media_placeholder`，则消息对象描述包含媒体素材的消息。在这种情况下，消息内容将被忽略。取而代之，后续会发送一个单独的历史记录 Webhook，其中描述消息内容和媒体素材编号，但仅针对查询前两周内发送的消息。请参阅下方描述媒体消息内容的[Payload 示例](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/history#examples)。 |
| -- -- --text             | Object  |      | 描述消息内容的对象。此值根据消息类型和消息内容而有所不同。例如，如果商家发送不带说明的`image`消息，该对象将不包含`caption`属性。请参阅[发送消息](https://developers.facebook.com/documentation/business-messaging/whatsapp/messages/send-messages)，了解每种消息类型的 Payload 示例。                                                                                                                                                                                                                                                                                                                                                                           |
| -- -- -- --body          | String  |      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| -- -- --history\_context | Object  | 是    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| -- -- -- --status        | String  | 是    | 表示消息的最新送达统计数据。值可以是：\* `DELIVERED`\* `ERROR`\* `PENDING`\* `PLAYED`\* `READ`\* `SENT`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| errors                   | String  | 否    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |

以下 Webhook 示例描述了两个消息对话：(1) 一个包含发送给 WhatsApp 用户的文本消息和视频消息以及 WhatsApp 用户回复的对话；(2) 一个包含发送给另一个 WhatsApp 用户的文本消息（感谢该用户下单）的对话。

请注意，第一条对话中的媒体消息内容未加以描述，而是触发[第二个 Webhook](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/history#examples)，描述该媒体消息的内容。

```json
{
    "id": "fd201190-50dc-4151-baec-1d16c8a704e1",
    "type": "whatsapp_history_message",
    "eventTime": "2023-10-16T13:04:57.644Z",
    "body": {
        "wabaId": "110129512080569",
        "sender": "108672736726376",
        "phoneNumberId": "123123123123123",
        "history": [
            {
                "metadata": {
                    "phase": 0,
                    "chunk_order": 1,
                    "progress": 55
                },
                "threads": [
                    {
                        "id": "16505551234",
                        "messages": [
                            {
                                "from": "15550783881",
                                "id": "wamid.HBgLMTY0NjcwNDM1OTUVAgARGBIyNDlBOEI5QUQ4NDc0N0FCNjMA",
                                "timestamp": "1739230955",
                                "type": "text",
                                "text": {
                                    "body": "Here's the info you requested! https://www.meta.com/quest/quest-3/"
                                },
                                "history_context": {
                                    "status": "READ"
                                }
                            },
                            {
                                "from": "15550783881",
                                "id": "wamid.QyNUEHBgLMTY0NjcwNDM1OTUVAgARGBI1Rj3NEYxMzAzMzQ5MkEA",
                                "timestamp": "1739230970",
                                "type": "media_placeholder",
                                "history_context": {
                                    "status": "PLAYED"
                                }
                            },
                            {
                                "from": "16505551234",
                                "id": "wamid.N0FCNjMAHBgLMTY0NjcwNDM1OTUVAgARGBIyNDlBOEI5QUQ4NDc0",
                                "timestamp": "1739230970",
                                "type": "text",
                                "text": {
                                    "body": "Thanks!"
                                },
                                "history_context": {
                                    "status": "READ"
                                }
                            }
                        ]
                    },
                    {
                        "id": "12125557890",
                        "messages": [
                            {
                                "from": "15550783881",
                                "id": "wamid.BIyNDlBOEI5N0FCNjMAHBgLMTY0NjcwNDM1OTUVAgARGQUQ4NDc0",
                                "timestamp": "1739230970",
                                "type": "text",
                                "text": {
                                    "body": "Thanks for your order! As a thank you, use code THANKS30 to get 30% of your next order."
                                },
                                "history_context": {
                                    "status": "DELIVERED"
                                }
                            }
                        ]
                    }
                ]
            }
        ]
    }
}
```

以下 Webhook 示例描述了媒体消息的内容。

```json
{
    "id": "fd201190-50dc-4151-baec-1d16c8a704e1",
    "type": "whatsapp_history_message",
    "eventTime": "2023-10-16T13:04:57.644Z",
    "body": {
        "wabaId": "110129512080569",
        "sender": "108672736726376",
        "phoneNumberId": "123123123123123",
        "messages": [
              {
                "from": "16505551234",
                "id": "wamid.QyNUEHBgLMTY0NjcwNDM1OTUVAgARGBI1Rj3NEYxMzAzMzQ5MkEA",
                "timestamp": "1738796547",
                "type": "image",
                "image": {
                  "caption": "Black Prince echeveria",
                  "mime_type": "image/jpeg",
                  "sha256": "3f9d94d399fa61c191bc1d4ca71375a035cd9b9f5b1128e1f0963a415c16b0cc",
                  "id": "24230790383178626",
                  "url":"https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=1808746433445380&source=webhook&ext=1786588846&hash=ATzuMr2uvZF_ilTxLF2sxHhzkfLBbPIRVfXxN2p2lX9MaA"
                }
              }
         ]
    }
}
```

聊天记录共享已被拒绝

```json
{
    "id": "fd201190-50dc-4151-baec-1d16c8a704e1",
    "type": "whatsapp_history_message",
    "eventTime": "2023-10-16T13:04:57.644Z",
    "body": {
        "wabaId": "110129512080569",
        "sender": "108672736726376",
        "phoneNumberId": "123123123123123",
        "history": [
            {
                "errors": [
                    {
                        "code": 2593109,
                        "title": "History sync is turned off by the business from the WhatsApp Business App",
                        "message": "History sync is turned off by the business from the WhatsApp Business App",
                        "error_data": {
                            "details": "History sharing is turned off by the business"
                        }
                    }
                ]
            }
        ]
    }
}
```
