pwiz
pwiz

Reputation: 193

How to automatically change agent status on Amazon Connect?

I need step by step directions on how to load the CCP into a webpage and use the streams API. I would need the javascript to turn the agent from "missed" to "available" after 25 seconds.

Currently we have to manually update staus which doesn't make sense for our use case.

I saw on the Amazon Connect forum someone made mention of a way to automatically change the status of from Missed to Available.

If you're embedding the CCP and using the Streams API, you can check the agent status on refresh, and if it's in Missed Call, set it to Available. I have this set to happen after 10 seconds.

Upvotes: 4

Views: 3125

Answers (1)

Carlos Robles
Carlos Robles

Reputation: 10947

For an embedded CCP you can do this using Stream API. You can subscribe to the agent refresh status, and do it there.

connect.agent(function (agent) {
    logInfoMsg("Subscribing to events for agent " + agent.getName());
    logInfoMsg("Agent is currently in status of " + agent.getStatus().name);
    agent.onRefresh(handleAgentRefresh);
}

function handleAgentRefresh(agent) {
    var status = agent.getStatus().name;
    logInfoEvent("[agent.onRefresh] Agent data refreshed. Agent status is " + status);

    //if status == Missed Call, 
    //    set it to Available after 25 seconds."
    //For example -but maybe this is not the best approach

    if (status == "Missed") { //PLEASE review if "Missed" and "Availble"  are proper codes
        setTimeout(function () {
            agent.setState("Available", {
                success: function () {
                    logInfoEvent(" Agent is now Available");
                },
                failure: function (err) { 
                    logInfoEvent("Couldn't change Agent status to Available. Maybe already in another call?");
                }
            });
            ;
        }, 25000);
    }
}

If you also need to know how to embed the CCP in a website, you can just do something like this

<!DOCTYPE html>
<meta charset="UTF-8">
<html>
  <head>
    <script type="text/javascript" src="amazon-connect-1.4.js"></script>
  </head>
  <!-- Add the call to init() as an onload so it will only run once the page is loaded -->
  <body onload="init()">
    <div id=containerDiv style="width: 400px;height: 800px;"></div>
    <script type="text/javascript">
      var instanceURL = "https://my-instance-domain.awsapps.com/connect/ccp-v2/";
      // initialise the streams api
      function init() {
        // initialize the ccp
        connect.core.initCCP(containerDiv, {
          ccpUrl: instanceURL,            // REQUIRED
          loginPopup: true,               // optional, defaults to `true`
          region: "eu-central-1",         // REQUIRED for `CHAT`, optional otherwise
          softphone: {                    // optional
            allowFramedSoftphone: true,   // optional
            disableRingtone: false,       // optional
            ringtoneUrl: "./ringtone.mp3" // optional
           }
         });
      }
    </script>
  </body>
</html>

You can see the documentation for StreamsAPI here https://github.com/amazon-connect/amazon-connect-streams/blob/master/Documentation.md

Upvotes: 3

Related Questions