สวัสดีทุกคน

การส่งและรับข้อความและกิจกรรมต่างๆ คือแง่มุมหลักของการสื่อสาร ระหว่างตัวแทนและผู้ใช้ ตัวแทนจะส่งข้อความ กิจกรรม และคำขอถึงผู้ใช้ ผ่าน Business Messages API แต่ได้รับข้อความและเหตุการณ์ที่ผู้ใช้สร้างขึ้น ที่เว็บฮุคในรูปแบบ JSON

ด้านล่างนี้เป็นตัวอย่างขั้นตอนการสนทนาที่ใช้ข้อมูลตัวอย่างเพื่อแสดงวิธีการ อาจสร้างการโต้ตอบที่มีประโยชน์และมีความหมาย

ในตัวอย่างนี้ ผู้ใช้เริ่มการสนทนาและส่งข้อความ "สวัสดี ฉันชื่อ World's!" แล้วตัวแทนก็ตอบกลับด้วยคำว่า "สวัสดีชาวโลก"

  1. ผู้ใช้เริ่มการสนทนากับตัวแทน
  2. เมื่อผู้ใช้เริ่มต้นพิมพ์คำตอบ ผู้ใช้จะส่งกิจกรรมการพิมพ์ไปยัง ตัวแทน

    {
      "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",
    }
    
  3. ผู้ใช้ส่งข้อความ "สวัสดี ฉันชื่อโลก!" เป็นข้อความ

    {
      "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",
    }
    
  4. ตัวแทนจะส่งคำว่า "สวัสดีชาวโลก" เป็นข้อความ

    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'
      }
    }"
    
  5. เมื่อส่งข้อความ อุปกรณ์ของผู้ใช้จะส่งคืนใบตอบรับการส่ง

    {
      "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",
    }