我们将于 2024 年 7 月 31 日逐步淘汰 Google Business Messages。点击
此处了解详情。
Hello, World
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
发送及接收信息和事件是代理与用户间沟通的核心环节。代理通过 Business Messages API 向用户发送信息、事件和请求,但通过网络钩子以 JSON 格式接收用户创建的信息和事件。
下面是一个对话流程示例,它使用示例数据来说明信息、事件和请求如何形成有用且有意义的互动。
在此示例中,用户发起对话并发送“Hello, I'm World!”信息,然后代理回复“Hello, World”。

- 用户发起与代理的对话。
用户开始输入回复后,会向代理发送输入事件。
{
"agent": "brands/1111/agents/2222",
"conversationId": "3333",
"customAgentId": "hello-world-bot",
"requestId": "1234567890",
"userStatus": {
"isTyping": "true",
"createTime": "2020-10-02T15:01:23.045123456Z",
},
"sendTime": "2020-10-02T15:01:24.045123456Z",
}
用户发送“Hello, I'm World!”信息。
{
"agent": "brands/1111/agents/2222",
"conversationId": "3333",
"customAgentId": "hello-world-bot",
"requestId": "123123123",
"message": {
"messageId": "4444",
"name": "conversations/12345/messages/67890",
"text": "Hello! I'm World!",
"createTime": "2020-10-02T15:05:23.045123456Z",
},
"context": {
"entryPoint": "PLACESHEET",
"userInfo": {
"displayName": "Michael",
"userDeviceLocale": "en",
},
"resolvedLocale": "en",
}
"sendTime": "2020-10-02T15:05:24.045123456Z",
}
代理发送“Hello, World”信息。
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/3333/messages" \
-H "Content-Type: application/json" \
-H "`oauth2l header --json path/to/service/account/key.json businessmessages`" \
-d "{
'messageId': '5555',
'text': 'Hello, World',
'representative': {
'avatarImage': 'https://hello.world/avatar.jpg',
'displayName': 'Hello World Agent',
'representativeType': 'BOT'
}
}"
信息送达后,用户的设备会返回递送回执。
{
"agent": "brands/1111/agents/2222",
"conversationId": "3333",
"customAgentId": "hello-world-bot",
"receipts" : {
"receipts": [
{
"message": "conversations/3333/messages/5555",
"receiptType": "DELIVERED",
}
],
"createTime": "2020-10-02T16:01:23.045123456Z",
},
"sendTime": "2020-10-02T16:01:24.045123456Z",
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-09-11。
[null,null,["最后更新时间 (UTC):2024-09-11。"],[[["\u003cp\u003eAgents and users communicate by sending and receiving messages and events through the Business Messages API and webhooks.\u003c/p\u003e\n"],["\u003cp\u003eUser interactions, such as typing and sending messages, are sent to the agent as JSON payloads containing relevant information like user details and message content.\u003c/p\u003e\n"],["\u003cp\u003eAgents can respond to users with messages containing text and optional representative details like display name and avatar.\u003c/p\u003e\n"],["\u003cp\u003eThe platform provides delivery receipts to the agent, confirming the delivery status of messages sent to the user.\u003c/p\u003e\n"]]],[],null,["# Hello, World\n\nSending and receiving messages and events are the core aspects of communication\nbetween an agent and a user. Agents send messages, events, and requests to users\nthrough the Business Messages API but receive user-created messages and events\nat their webhooks as JSON.\n\nBelow is an example conversation flow that uses sample data to illustrate how\nmessages, events, and requests can create useful and meaningful interactions.\n\nIn this example, the user starts a conversation and sends the message \"Hello,\nI'm World!\", then the agent responds with \"Hello, World\".\n\n1. The user begins the conversation with the agent.\n2. Once the user begins typing a response, they send a typing event to the\n agent.\n\n {\n \"agent\": \"brands/1111/agents/2222\",\n \"conversationId\": \"3333\",\n \"customAgentId\": \"hello-world-bot\",\n \"requestId\": \"1234567890\",\n \"userStatus\": {\n \"isTyping\": \"true\",\n \"createTime\": \"2020-10-02T15:01:23.045123456Z\",\n },\n \"sendTime\": \"2020-10-02T15:01:24.045123456Z\",\n }\n\n3. The user sends \"Hello, I'm World!\" as a message.\n\n {\n \"agent\": \"brands/1111/agents/2222\",\n \"conversationId\": \"3333\",\n \"customAgentId\": \"hello-world-bot\",\n \"requestId\": \"123123123\",\n \"message\": {\n \"messageId\": \"4444\",\n \"name\": \"conversations/12345/messages/67890\",\n \"text\": \"Hello! I'm World!\",\n \"createTime\": \"2020-10-02T15:05:23.045123456Z\",\n },\n \"context\": {\n \"entryPoint\": \"PLACESHEET\",\n \"userInfo\": {\n \"displayName\": \"Michael\",\n \"userDeviceLocale\": \"en\",\n },\n \"resolvedLocale\": \"en\",\n }\n \"sendTime\": \"2020-10-02T15:05:24.045123456Z\",\n }\n\n4. The agent sends \"Hello, World\" as a message.\n\n curl -X POST \"https://businessmessages.googleapis.com/v1/conversations/3333/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"`oauth2l header --json path/to/service/account/key.json businessmessages`\" \\\n -d \"{\n 'messageId': '5555',\n 'text': 'Hello, World',\n 'representative': {\n 'avatarImage': 'https://hello.world/avatar.jpg',\n 'displayName': 'Hello World Agent',\n 'representativeType': 'BOT'\n }\n }\"\n\n5. Upon message delivery, the user's device returns a delivery receipt.\n\n {\n \"agent\": \"brands/1111/agents/2222\",\n \"conversationId\": \"3333\",\n \"customAgentId\": \"hello-world-bot\",\n \"receipts\" : {\n \"receipts\": [\n {\n \"message\": \"conversations/3333/messages/5555\",\n \"receiptType\": \"DELIVERED\",\n }\n ],\n \"createTime\": \"2020-10-02T16:01:23.045123456Z\",\n },\n \"sendTime\": \"2020-10-02T16:01:24.045123456Z\",\n }"]]