मैसेज और इवेंट भेजना और पाना, एजेंट और उपयोगकर्ता के बीच बातचीत के मुख्य पहलू हैं. एजेंट, Business Messages API की मदद से उपयोगकर्ताओं को मैसेज, इवेंट, और अनुरोध भेजते हैं. हालांकि, एजेंट को अपने वेबहुक के लिए उपयोगकर्ताओं के बनाए गए मैसेज और इवेंट, JSON के तौर पर मिलते हैं.
नीचे उदाहरण के तौर पर बातचीत का एक उदाहरण दिया गया है, जिसमें नमूने के तौर पर दिया गया डेटा इस्तेमाल किया गया है. यह दिखाता है कि मैसेज, इवेंट, और अनुरोध किस तरह उपयोगी और काम के इंटरैक्शन बना सकते हैं.
इस उदाहरण में, उपयोगकर्ता बातचीत शुरू करता है और मैसेज भेजता है;नमस्ते, I'm World!", तो एजेंट "नमस्ते, 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", }
उपयोगकर्ता मैसेज के तौर पर "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", }
एजेंट, मैसेज के तौर पर "नमस्ते, 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", }