Configure advanced assignment rules using JS API

If the default assignment rules are insufficient for your requirements, you can create custom rules using our JavaScript API. This will allow you to fine-tune the chat assignment logic to suit your specific needs. Here is an example:

window.chaportConfig = {
  appId: '<yourAppId>',
  assignments: {
    rules: [
      // assign to the example.com team if a visitor is on example.com
      { 'example.com-team-id': ['page_url', 'contains', 'example.com'] },

      // assign to the sales team if the visitor's role in your system is 'lead' (hypothetical example)
      { 'sales-team-id': function (cp) { return cp.compare(yourUser.role, '=', 'lead') } },

      // assign to the VIP team if your isVIP function returns true
      { 'vip-team-id': function (cp) { return isVIP() } },

      // assign to the US Sales team if visitor's location is US
      { 'us-sales-team-id': ['country', '=', 'US'] },

      // assign to the Spanish support team if visitor's language is Spanish
      { 'es-support-team-id': ['language', '=', 'es'] },

      // assign everything else to John
      { 'john-id': true },
    ],
  },
};

To find the operator ID, open the Chaport app in a browser, go to the Operators tab, and select the desired operator. The operator ID is a set of numbers and letters located in the URL after https://app.chaport.com/#/operators/.

To find the team ID, go to Settings → Teams, select the desired team, and copy the set of numbers and letters in the URL after https://app.chaport.com/#/settings/teams/.

Please note: JavaScript API, teams, and assignment rules are only available on our paid plans.

To learn more, read the following articles: