การสื่อสารและรับส่งข้อความเป็นองค์ประกอบหลักของการสื่อสารระหว่างตัวแทนและผู้ใช้ ตัวแทนจะส่งข้อความ กิจกรรม และคําขอไปยังผู้ใช้ผ่าน Business Messages API แต่จะรับข้อความและเหตุการณ์ที่ผู้ใช้สร้างขึ้นในเว็บฮุคเป็น JSON
ด้านล่างนี้คือตัวอย่างกระบวนการสนทนาที่ใช้ข้อมูลตัวอย่างในการแสดงให้เห็นวิธีที่ข้อความ เหตุการณ์ และคําขอสร้างการโต้ตอบที่เป็นประโยชน์และมีความหมาย
ในตัวอย่างนี้ ผู้ใช้เริ่มต้นการสนทนาและส่งข้อความ "สวัสดี ฉันโลก!" จากนั้นตัวแทนจะตอบกลับด้วย "สวัสดี โลก"
- ผู้ใช้เริ่มการสนทนากับตัวแทน
เมื่อผู้ใช้เริ่มพิมพ์คําตอบ ก็จะส่งกิจกรรมการพิมพ์ไปยัง Agent
{ "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", }
ผู้ใช้ส่ง &"สวัสดี ฉันเป็น'm โลก!" เป็นข้อความ
{ "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", }
ตัวแทนจะส่ง "สวัสดีทั่วโลก" เป็นข้อความ
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", }