שלום עולם

שליחה וקבלה של הודעות ואירועים הם ההיבטים העיקריים בתקשורת בין סוכן למשתמש. סוכנים שולחים הודעות, אירועים ובקשות למשתמשים דרך Business Messages API, אבל מקבלים הודעות ואירועים שנוצרו על ידי משתמשים ב-webhooks שלהם כ-JSON.

בהמשך אפשר למצוא תרחיש לדוגמה של שיחות שמתבסס על נתונים לדוגמה, כדי להמחיש איך הודעות, אירועים ובקשות יכולים ליצור אינטראקציות מועילות ומשמעותיות.

בדוגמה הזו, המשתמש מתחיל שיחה ושולח את ההודעה "שלום, I'm 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. המשתמש שולח "שלום, 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",
    }
    
  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",
    }