Google Business Messages 功能將於 2024 年 7 月 31 日終止服務。請按
這裡瞭解詳情。
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",
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-09-11 (世界標準時間)。
[null,null,["上次更新時間: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 }"]]