Example: Control the routing of conversations

In this example, we'll route a conversation based on the following data:

  • priority
  • preferred or required agent
  • queue

For this integration, you'll need to configure the following:

  • Events and Conversation Direction: See event and direction support for different operations.
  • JSON for Configuration:
    {
       "request": {
          "authentication": {"type": "basic"},
          "method": "POST"
       },
       "response": {
          "set": {
             "priority": "{response.body.priority}",
             "queue": {
                "address": "{response.body.queue.address}"
             },
             "preferredAgent": "{response.body.preferredAgent}",
             "requiredAgents": {
                "agents": "{response.body.requiredAgents.agents}",
                "timeout": "{response.body.requiredAgents.timeout}"
             }
          }
       }
    }

    This example uses basic authentication and the POST method to route a conversation. The response sets the routing criteria for the conversation: priority, queue, preferred agent, and required agents. You can use this code and remove the routing options that aren't relevant to you or use the specific example for each criteria further below.

For the response, see Configuring a JSON response.

Set priority

This example sets the priority for the conversation.

{
  "request": {
    "authentication": {
      "type": "basic"
    },
    "method": "GET"
  },
  "response": {
    "set": {
      "priority": "{response.body.priority}"
    }
  }
}

Set preferred agent

This example sets the preferred agent for the conversation.

{
  "request": {
    "authentication": {
      "type": "basic"
    },
    "method": "GET",
    "params": {
      "filter": "source='{contact.source}'"
    }
  },
  "response": {
    "set": {
      "preferredAgent": "{response.body.agent}"
    }
  }
}

Set required agent

This example sets the required agent. The response returns an array of agents' chat addresses and the duration of the requirement (=timeout):

{
  "request": {
    "authentication": {
      "type": "basic"
    },
    "method": "GET",
    "params": {
      "phoneNumber": "{contact.source}"
    }
  },
  "response": {
    "set": {
      "requiredAgents": {
        "agents": "{response.body.requiredAgents.agents}",
        "timeout": "{response.body.requiredAgents.timeout}"
      }
    }
  }
}

This example sets the required agent. The response returns an array of objects in which chat address is taken from the array. The duration of the requirement (=timeout) is defined in the configuration:

{
  "request": {
    "authentication": {
      "type": "basic"
    },
    "method": "GET"
  },
  "response": {
    "set": {
      "requiredAgents": {
        "agents": [
          "{response.body.records[0].fields.agent}",
          "{response.body.records[1].fields.agent}"
        ],
        "timeout": "90"
      }
    }
  }
}

Set queue

This example fetches the last row from the response's queues and gets the id to set a queue for the conversation.

{
  "request": {
    "authentication": {
      "type": "basic"
    },
    "method": "GET"
  },
  "response": {
    "set": {
      "queue": {
        "id": "{response.body.queues[-1].id}"
      }
    }
  }
}