Hello, World

메시지와 이벤트를 주고받는 것은 에이전트와 사용자 간 통신의 핵심 측면입니다. 에이전트는 Business Messages API를 통해 사용자에게 메시지, 이벤트, 요청을 보내지만 웹훅에서 사용자가 만든 메시지 및 이벤트를 JSON으로 수신합니다.

다음은 샘플 데이터를 사용하여 메시지, 이벤트, 요청을 통해 유용하고 의미 있는 상호작용을 만드는 방법을 보여주는 대화 흐름의 예입니다.

이 예시에서 사용자는 대화를 시작하고 "Hello, I'm World!&quot를 보내면 에이전트가 "Hello, World"로 응답합니다.

  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. 사용자가 'Hello 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",
    }
    
  4. 상담사가 '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'
      }
    }"
    
  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",
    }