مرحبًا بالجميع

يشكّل إرسال الرسائل والأحداث عاملَين رئيسيَّين للتواصل بين الوكيل والمستخدم. يرسل الوكلاء الرسائل والأحداث والطلبات إلى المستخدمين من خلال واجهة برمجة تطبيقات الرسائل التجارية، ولكنهم يتلقون رسائل وأحداث من إنشاء المستخدمين في الردود التلقائية على الويب مثل JSON.

في ما يلي مثال على سلسلة محادثات تستخدم نموذج بيانات لتوضيح كيف يمكن للرسائل والأحداث والطلبات إنشاء تفاعلات مفيدة ومفيدة.

في هذا المثال، يبدأ المستخدم محادثة ويرسل الرسالة &مرحبًا، I'm World!"، ثم يردّ موظّف الدعم باستخدام &"مرحبًا، العالم&quot.

  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. يرسل الوكيل "مرحبًا, 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",
    }