Uploaded image for project: 'Chat Solution'
  1. Chat Solution
  2. CSN-5394

Send multiple bot responses in an array of messages rather than sending them as different messages

    XMLWordPrintable

Details

    • Spike
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • chat 3.18.0
    • None
    • bot-connector, CCM, Chat Server
    • None
    • Software (SOFTWARE)
    • Sprint# 60 (Nov 1-12), Sprint# 61 (Nov 17 - Dec 1), Sprint# 62 (Dec 6 - 17)

    Description

      Current Implementation

      1. A customer sends a message. Chat Server sends the message to the Bot Connector
      2. Bot Connector calls Rasa API to get a response to a message
      3. Rasa responds with multiple messages for the detected intent. It responds with the following payload:
        response: 
        { ...,
          "data": [
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 1"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 2"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 3"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 4"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 5"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 6"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 7"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 8"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 9"
            },
            {
              "recipient_id": "VCIyIoTXp2FLAbH7eq1Kk",
              "text": "msg 10"
            }
          ],
          ...
        }
        
      1. Bot Connector iterates over these messages and sends them one by one to Chat Server. It is due to a limitation of the Chat Server message payload where one can send only one text body per message. So bot connector sends the following payload one by one to Chat Server
        {
          "conversationId": "VCIyIoTXp2FLAbH7eq1Kk",
          "messageId": "9af18a53-7680-44d9-854e-90de9bdf72fe",
          "type": "BotMessage",
          "from": {
            "id": "Vjx3vYztjRV51_c_VV_q4",
            "name": "customer name",
            "firstName": "customer name",
            "lastName": "",
            "type": "Customer"
          },
          "bot": {
            "id": "bot",
            "name": "EF Bot",
            "type": "Rasa",
            "botResponseType": "simple"
          },
          "timestamp": "2021-12-10T12:36:03.954Z",
          "input": "hi",
          "attachments": [],
          "intents": [
            {
              "name": "greet",
              "confidence": "0.988152801990509"
            }
          ],
          "entities": [],
          "output": [
            {
              "name": "message text body",
              "confidence": "0.988152801990509",
              "data": {
                "elements": "null",
                "quick_replies": "null",
                "buttons": "null",
                "attachment": "null",
                "image": "null",
                "location": "null",
                "custom": "null"
              }
            }
          ]
        }
        

        Although the output object is an array of objects, Chat Server only supports one object in this array.

      1. Chat Server sends this payload to CCM (for non-web channels) via ActiveMQ channel queue
      2. CCM consumes these messages from the ActiveMQ channel queue in an asynchronous fashion and sends them to the destination. The order of these messages cannot be guaranteed because of the asynchronous nature of the CCM process

      Proposed Solution

      1. When Bot Connector receives the array of messages from Rasa API. It should send them to the Chat Server in the following payload
        {
          "conversationId": "VCIyIoTXp2FLAbH7eq1Kk",
          "messageId": "9af18a53-7680-44d9-854e-90de9bdf72fe",
          "type": "BotMessage",
          "from": {
            "id": "Vjx3vYztjRV51_c_VV_q4",
            "name": "customer name",
            "firstName": "customer name",
            "lastName": "",
            "type": "Customer"
          },
          "bot": {
            "id": "bot",
            "name": "EF Bot",
            "type": "Rasa",
            "botResponseType": "simple"
          },
          "timestamp": "2021-12-10T12:36:03.954Z",
          "input": "hi",
          "attachments": [],
          "intents": [
            {
              "name": "greet",
              "confidence": "0.988152801990509"
            }
          ],
          "entities": [],
          "output": [
            {
              "name": "message text body 1",
              "confidence": "0.988152801990509",
              "data": {
                "elements": "null",
                "quick_replies": "null",
                "buttons": "null",
                "attachment": "null",
                "image": "null",
                "location": "null",
                "custom": "null"
              }
            },
            {
              "name": "message text body 2",
              "confidence": "0.988152801990509",
              "data": {
                "elements": "null",
                "quick_replies": "null",
                "buttons": "null",
                "attachment": "null",
                "image": "null",
                "location": "null",
                "custom": "null"
              }
            },
            {
              "name": "message text body 3",
              "confidence": "0.988152801990509",
              "data": {
                "elements": "null",
                "quick_replies": "null",
                "buttons": "null",
                "attachment": "null",
                "image": "null",
                "location": "null",
                "custom": "null"
              }
            },
            ...
          ]
        }
        
      2. Chat Server will parse the output object as a single message and will send it to the CCM via the ActiveMQ channel queue
      3. CCM will consume this message from the ActiveMQ channel queue and will parse this message asynchronously. Now that this message contains multiple text bodies, CCM will iterate over this array in a synchronous fashion, sending them one by one and maintaining the order.

      Attachments

        Issue Links

          Activity

            People

              jawad.bokhari Jawad Bokhari
              awais.aslam Awais Aslam
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 4 hours
                  4h
                  Remaining:
                  Remaining Estimate - 4 hours
                  4h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified