

# Amazon Connect Agent Workspace Agent API
Agent

The Amazon Connect SDK provides an `AgentClient` which serves as an interface that your app in the Amazon Connect agent workspace can use to subscribe to agent events and make agent data requests.

The `AgentClient` accepts an optional constructor argument, ` ConnectClientConfig` which itself is defined as:

```
export type ConnectClientConfig = {  
    context?: ModuleContext;  
    provider?: AmazonConnectProvider;
};
```

If you do not provide a value for this config, then the client will default to using the ** AmazonConnectProvider** set in the global provider scope. You can also manually configure this using **setGlobalProvider**.

You can instantiate the agent client as follows:

```
import { AgentClient } from "@amazon-connect/contact";
 
const agentClient = new AgentClient({ provider });
```

**Note**  
You must first instantiate the [ AmazonConnectApp](getting-started-initialize-sdk.md) which initializes the default AmazonConnectProvider and returns ` { provider } `. This is the recommended option.

Alternatively, providing a constructor argument:

```
import { AgentClient } from "@amazon-connect/contact";
        
const agentClient = new AgentClient({
    context: sampleContext,  
    provider: sampleProvider
});
```

The following sections describe API calls for working with the Agent API.

**Topics**
+ [getARN()](3P-apps-agent-requests-getarn.md)
+ [getChannelConcurrency()](3P-apps-agent-requests-getchannelconcurrency.md)
+ [getExtension()](3P-apps-agent-requests-getextension.md)
+ [getName()](3P-apps-agent-requests-getname.md)
+ [getRoutingProfile()](3P-apps-agent-requests-getroutingprofile.md)
+ [getState()](3P-apps-agent-requests-getstate.md)
+ [listAvailabilityStates()](3P-apps-agent-requests-listavailabilitystates.md)
+ [listQuickConnects()](3P-apps-agent-requests-listquickconnects.md)
+ [offEnabledChannelListChanged()](3P-apps-agent-requests-off-enabledchannellistchanged.md)
+ [offRoutingProfileChanged()](3P-apps-agent-requests-off-routingprofilechanged.md)
+ [onEnabledChannelListChanged()](3P-apps-agent-requests-on-enabledchannellistchanged.md)
+ [onRoutingProfileChanged()](3P-apps-agent-requests-on-routingprofile-changed.md)
+ [setAvailabilityState()](3P-apps-agent-requests-setavailabilitystate.md)
+ [setAvailabilityStateByName()](3P-apps-agent-requests-setavailabilitystatebyname.md)
+ [setOffline()](3P-apps-agent-requests-setoffline.md)
+ [onStateChanged()](3P-apps-agent-events-statechanged-sub.md)
+ [offStateChanged()](3P-apps-agent-events-statechanged-unsub.md)

# Get the ARN of the agent in Amazon Connect Agent Workspace
getARN()

Returns the Amazon Resource Name(ARN) of the user that's currently logged in to the Amazon Connect agent workspace.

```
async getARN(): Promise<string>          
```

 **Permissions required:** 

```
User.Details.View                
```

# Get the limit of contacts for the agent in Amazon Connect Agent Workspace
getChannelConcurrency()

Returns a map of `ChannelType`-to-number indicating how many concurrent contacts can an Amazon Connect agent workspace agent have on a given channel. 0 represents a disabled channel.

```
async getChannelConcurrency(): Promise<AgentChannelConcurrencyMap>         
```

 **Permissions required:** 

```
User.Configuration.View              
```

# Get the extension of the agent in Amazon Connect Agent Workspace
getExtension()

Returns phone number of the agent currently logged in to the Amazon Connect agent workspace. This is the phone number that is dialed by the Amazon Connect to connect calls to the agent for incoming and outgoing calls if soft phone is not enabled.

```
async getExtension(): Promise<string | null>         
```

 **Permissions required:** 

```
User.Configuration.View              
```

# Get the name of the agent in Amazon Connect Agent Workspace
getName()

Returns the name of the user that's currently logged in to the Amazon Connect agent workspace.

```
async getName(): Promise<string>          
```

 **Permissions required:** 

```
User.Details.View                
```

# Get the routing profile of the agent in Amazon Connect Agent Workspace
getRoutingProfile()

Returns the routing profile of the agent currently logged in to the Amazon Connect agent workspace. The routing profile contains the following fields:
+ `channelConcurrencyMap`: See agent.[Get the limit of contacts for the agent in Amazon Connect Agent Workspace](3P-apps-agent-requests-getchannelconcurrency.md) for more info.
+ `defaultOutboundQueue`: The default queue which should be associated with outbound contacts. See queues for details on properties.
+ `name`: The name of the routing profile.
+ `queues`: The queues contained in the routing profile. Each queue object has the following properties:
  + `name`: The name of the queue.
  + `queueARN`: The ARN of the queue.
  + `queueId`: Alias for queueARN.
+ `routingProfileARN`: The routing profile ARN.
+ `routingProfileId`: Alias for `routingProfileARN`.

```
async getRoutingProfile(): Promise<AgentRoutingProfile>         
```

 **Permissions required:** 

```
User.Configuration.View               
```

# Get the current state of the agent in Amazon Connect Agent Workspace
getState()

Returns the Amazon Connect agent workspace agent's current `AgentState` object indicating their availability state type. This object contains the following fields:
+ `agentStateARN`: The agent's current state ARN.
+ `name`: The name of the agent's current availability state.
+ `startTimestamp`: A `Date` object that indicates when the state was set.
+ `type`: The agent's current availability state type, as per the ` AgentStateType` enumeration. The different values are as follows:
  +  `routable` 
  +  `not_routable` 
  +  `after_call_work` 
  +  `system` 
  +  `error` 
  +  `offline` 

```
async getState(): Promise<AgentState>          
```

 **Permissions required:** 

```
User.Status.View                
```

# Get all the availability states configured for the current agent in Amazon Connect Agent Workspace
listAvailabilityStates()

 Get all the availability states configured for the current agent. 

 **Signature** 

```
listAvailabilityStates(): Promise<AgentState[]>
```

 **Usage** 

```
const availabilityStates: AgentState[] = await agentClient.listAvailabilityStates();        
```

 **Output - AgentState** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  agentStateARN  |  string  |  Amazon Reference Number of agent state  | 
|  type  |  string  |  It could be "routable" \$1 "not\$1routable" \$1 "after\$1call\$1work" \$1 "system" \$1 "error" \$1 "offline"  | 
|  name  |  string  |  Name of the agent state like Available or Offline  | 
|  startTimestamp  |  Date  |  A Date object that indicates when the state was set.  | 

 **Permissions required:** 

```
User.Configuration.View              
```

# Get the list of Quick Connect endpoints associated with a given queue in Amazon Connect Agent Workspace
listQuickConnects()

 Get the list of Quick Connect endpoints associated with the given queue(s). Optionally you can pass in a parameter to override the default max-results value of 500. 

 **Signature** 

```
listQuickConnects(
    queueARNs: QueueARN | QueueARN[],
    options?: ListQuickConnectsOptions,
  ): Promise<ListQuickConnectsResult>
```

 **Usage** 

```
const routingProfile: AgentRoutingProfile = await agentClient.getRoutingProfile();
const quickConnects: ListQuickConnectsResult = await agentClient.listQuickConnects(routingProfile.queues[0].queueARN);
```

 **Input** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  queueARNs Required  |  string \$1 string[]  |  One or more Queue ARNs for which the Queue Connects need to be retrieved  | 
|  options.maxResults  |  number  |  The maximum number of results to return per page. The default value is 500  | 
|  options.nextToken  |  string  |  The token for the next set of results. Use the value returned in the previous response in the next request to retrieve the next set of results.  | 

 **Output - ListQuickConnectsResult** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  quickConnects  |  QuickConnect[]  |  Its either AgentQuickConnect or QueueQuickConnect or PhoneNumberQuickConnect which contains endpointARN and name. Additionally PhoneNumberQuickConnect contains phoneNumber  | 
|  nextToken  |  string  |  If there are additional results, this is the token for the next set of results.  | 

 **Permissions required:** 

```
User.Configuration.View              
```

# Unsubscribe from agent enabled channel list changes in Amazon Connect Agent Workspace
offEnabledChannelListChanged()

Unsubscribes from EnabledChannelListChanged event.

 **Signature** 

```
offEnabledChannelListChanged(handler: EnabledChannelListChangedHandler): void                
```

# Unsubscribe from agent routing profile changes in Amazon Connect Agent Workspace
offRoutingProfileChanged()

Unsubscribes from RoutingProfileChanged event.

 **Signature** 

```
offRoutingProfileChanged(handler: RoutingProfileChangedHandler): void                
```

# Subscribe to agent enabled channel list changes in Amazon Connect Agent Workspace
onEnabledChannelListChanged()

Creates a subscription for EnabledChannelListChanged event. This gets triggered when an Agent's enabled channels get updated.

 **Signature** 

```
const handler: EnabledChannelListChangedHandler = async (data: EnabledChannelListChanged) => {
    console.log("Agent channel list change occurred! " + data);
};

agentClient.onEnabledChannelListChanged(handler);

// EnabledChannelListChanged Structure
{
    enabledChannels: AgentRoutingProfileChannelTypes[];
    previous?: {
        enabledChannels: AgentRoutingProfileChannelTypes[];
    };
}
```

 **Permissions required:** 

```
*
```

# Subscribe to agent routing profile changes in Amazon Connect Agent Workspace
onRoutingProfileChanged()

Creates a subscription for RoutingProfileChanged event. This gets triggered when an Agent's routing profile gets updated.

 **Signature** 

```
const handler: RoutingProfileChangedHandler = async (data: AgentRoutingProfileChanged) => {
    console.log("Agent routing profile change occurred! " + data);
};

agentClient.onRoutingProfileChanged(handler);

// AgentRoutingProfileChanged Structure
{
    routingProfile: AgentRoutingProfile;
    previous?: {
        routingProfile: AgentRoutingProfile;
    };
}
```

 **Permissions required:** 

```
*
```

# Set the agent state with the given agent state ARN in Amazon Connect Agent Workspace
setAvailabilityState()

 Set the agent state with the given agent state ARN. By default, the promise resolves after the agent state is set in the backend. The response status is either `updated` or `queued` based on the current agent state.

 **Signature** 

```
 setAvailabilityState(
    agentStateARN: string,
  ): Promise<SetAvailabilityStateResult>
```

 **Usage** 

```
const availabilityStates: AgentState[] = await agentClient.listAvailabilityStates();
const availabilityStateResult:SetAvailabilityStateResult = await agentClient.setAvailabilityState(availabilityStates[0].agentStateARN);
```

 **Input** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  agentStateARN Required  |  string  |  The ARN of the agent state  | 

 **Output - SetAvailabilityStateResult** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  status  |  string  |  The status will be updated or queued depending on if the agent is currently handling an active contact.  | 
|  current  |  AgentState  |  Reperesents the current state of the agent.  | 
|  next  |  AgentState  |  It'll be the target state if the agent is handling active contact. Applicable when the status is queued. | 

 **Permissions required:** 

```
User.Configuration.Edit              
```

# Set the agent state with the given agent state name in Amazon Connect Agent Workspace
setAvailabilityStateByName()

Sets the agent state with the given agent state name. The promise resolves after the agent state is set in the backend. The response status is either `updated` or ` queued` based on the current agent state.

 **Signature** 

```
setAvailabilityStateByName(
    agentStateName: string,
  ): Promise<SetAvailabilityStateResult>
```

 **Usage** 

```
const availabilityStateResult: SetAvailabilityStateResult = await agentClient.setAvailabilityStateByName('Available');
```

 **Input** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  agentStateName Required  |  string  |  The name of the agent state  | 

 **Output - SetAvailabilityStateResult** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  status  |  string  |  The status will be "updated" or "queued" depends on if the agent is currently handling an active contact. | 
|  current  |  AgentState  |  Reperesents the current state of the agent.  | 
|  next  |  AgentState  |  It'll be the target state if the agent is handling active contact. Applicable when the status is queued | 

 **Permissions required:** 

```
User.Configuration.Edit              
```

# Sets the agent state to Offline in Amazon Connect Agent Workspace
setOffline()

 Sets the agent state to Offline. The promise resolves after the agent state is set in the backend.

 **Signature** 

```
  setOffline(): Promise<SetAvailabilityStateResult>
```

 **Usage** 

```
const availabilityStateResult: SetAvailabilityStateResult = await agentClient.setOffline();
```

 **Output - SetAvailabilityStateResult** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
|  status  |  string  |  The status will be updated or queued depending on if the agent is currently handling an active contact. | 
|  current  |  AgentState  |  Represents the current state of the agent.  | 
|  next  |  AgentState  |  It'll be the target state if the agent is handling active contact. Applicable when the status is queued. | 

 **Permissions required:** 

```
User.Configuration.Edit              
```

# Subscribe a callback function when an Amazon Connect Agent Workspace agent state changes
onStateChanged()

Subscribes a callback function to-be-invoked whenever an agent state changed event occurs in the Amazon Connect agent workspace.

 **Signature** 

```
onStateChanged(handler: AgentStateChangedHandler)
```

 **Usage** 

```
const handler: AgentStateChangedHandler = async (data: AgentStateChangedEventData) => {
    console.log("Agent state change occurred! " + data);
};

agentClient.onStateChanged(handler);

// AgentStateChangedEventData Structure
{
  state: string;
  previous: {
    state: string;
  };
}
```

 **Permissions required:** 

```
User.Status.View                
```

# Unsubscribe a callback function when an Amazon Connect Agent Workspace agent state changes
offStateChanged()

Unsubscribes the callback function from the agent stated change event in the Amazon Connect agent workspace.

 **Signature** 

```
offStateChanged(handler: AgentStateChangedHandler)
```

 **Usage** 

```
agentClient.offStateChanged(handler);              
```