Integrate application with Connect Customer agent workspace agent data
To integrate your application with agent data from the Connect Customer agent workspace, instantiate the agent client as follows:
import { AgentClient } from "@amazon-connect/contact"; const agentClient = new AgentClient({ provider });
Note
You must first instantiate the
AmazonConnectApp which initializes the default AmazonConnectProvider and
returns { provider } . This is the recommended option.
Alternatively, see the API reference to customize your client’s configuration.
Once the agent client is instantiated, you can use it to subscribe to events and make requests.
Example agent event
The following code sample subscribes a callback to the availability state change event. Whenever the agent’s state is modified, the agent workspace will invoke your provided callback, passing in the event data payload for your function to operate on. In this example, it logs the event data to the console.
import { AgentAvailabilityStateChanged } from "@amazon-connect/contact"; // A simple callback that logs the availability state change event data // returned by the workspace whenever the logged-in agent's availability state changes. const handler = async (data: AgentAvailabilityStateChanged) => { console.log(data); }; // Subscribe to the availability state change topic using the above handler. agentClient.onAvailabilityStateChanged(handler);
Example agent request
The following code sample submits a getARN request and then logs
the returned data to the console.
const arn = await agentClient.getARN(); console.log(`Got the arn value: ${arn}`);
The above agent event and request are non-exhaustive. For a full list of available agent events and requests, see the API Reference.