

# Amazon Connect Agent Workspace Message Template API
MessageTemplate

The Amazon Connect SDK provides a `MessageTemplateClient` which serves as an interface that you can use to make requests to search and get content from your Amazon Connect Message Template Knowledge Base.

The `MessageTemplateClient` 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 { MessageTemplateClient } from "@amazon-connect/message-template";

const messageTemplateClient = new MessageTemplateClient({ 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 { MessageTemplateClient } from "@amazon-connect/message-template";
            
const messageTemplateClient = new MessageTemplateClient({
    context: sampleContext,  
    provider: sampleProvider
});
```

**Note**  
Third-party applications must be configured with \$1 permission in order to utilize the MessageTemplateClient APIs.

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

**Topics**
+ [getContent()](3P-apps-message-template-requests-getcontent.md)
+ [isEnabled()](3P-apps-message-template-requests-isenabled.md)
+ [searchMessageTemplates()](3P-apps-message-template-requests-searchmessagetemplates.md)

# Get content of a message template in Amazon Connect Agent Workspace
getContent()

Gets the content of a message template. This includes plaintext or html content of the body of the message template as a string, the subject of the message template, and attachments if they are configured on the message template. Attributes in the message template will be filled if they are system attributes, agent attributes, or custom attributes set up in the contact flow. More information on the attributes can be found here: [ https://docs.aws.amazon.com/connect/latest/adminguide/personalize-templates.html](https://docs.aws.amazon.com/connect/latest/adminguide/personalize-templates.html)

 **Signature** 

```
getContent(messageTemplateId: string, contactId: string): Promise<MessageTemplateContent>
```

 **messageTemplateId** 

The messageTemplateId can be either the ID or the ARN of a message template
+ Passing in the ARN returned by searchMessageTemplates is recommended here, since this will get the content of the active version of the message template.
+ Passing in the ID will return the content of the latest version of the message template. A qualifier can be appended to the messageTemplateId to get the content of a different version of the message template.

More information on qualifiers can be found here:

 [ https://docs.aws.amazon.com/connect/latest/APIReference/API\$1amazon-q-connect\$1GetMessageTemplate.html](https://docs.aws.amazon.com/connect/latest/APIReference/API_amazon-q-connect_GetMessageTemplate.html) 

More information on versioning can be found here:

 [ https://docs.aws.amazon.com/connect/latest/adminguide/about-version-message-templates.html](https://docs.aws.amazon.com/connect/latest/adminguide/about-version-message-templates.html) 

 **contactId** 

The current contact to add the message template to. This is used to populate attributes in the message template

 **MessageTemplateContent Properties** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
| subject | string | Message subject populated in the template | 
| body | MessageTemplateBody | Message body content populated in the template. This can include plainText or html or both | 
| attachments | MessageTemplateAttachment[] | Attachments populated in the template | 
| attributesNotInterpolated | string[] | List of attributes that were not automatically populated in the message template. If all attributes were automatically populated, this list will be empty | 

 **MessageTemplateBody Properties** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
| plainText | string | Plain text content of the message template as a string. It is possible for both the plain text and html to be populated, or for only the plain text or html content to be populated | 
| html | string | HTML content of the message template as a string | 

 **MessageTemplateAttachment Properties** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
| fileName | string | Name of the attachment | 
| fileId | string | ID of the attachment | 
| downloadUrl | string | URL to download the attachment from | 

# Determine if the Message Template feature is enabled in Amazon Connect Agent Workspace
isEnabled()

Returns the MessageTemplateEnabledState object, which indicates if the message template feature is enabled for the Connect instance. The Message Template feature is considered enabled if there is a knowledge base for message templates configured for the instance. The object contains the following fields:
+ `isEnabled`: A boolean indicating if the feature is enabled
+ `knowledgeBaseId`: The id of the Message Template Knowledge Base (if the feature is enabled)

 **Signature** 

```
isEnabled(): Promise<MessageTemplateEnabledState>
```

# Retrieve message templates that match a search query in Amazon Connect Agent Workspace
searchMessageTemplates()

Returns the SearchMessageTemplatesResponse object, which contains the matching message templates and a token to retrieve the next page of results, if available. The SearchMessageTemplatesParams object is used to configure the search, allowing you to filter by various criteria, as well as specify the channels and pagination options. If no filter text is provided, all active message templates for the agent's routing profile and the channel(s) specified are returned.

 **Signature** 

```
searchMessageTemplates(request: SearchMessageTemplatesParams): Promise<SearchMessageTemplatesResponse>
```

 **SearchMessageTemplatesResponse Properties** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
| messageTemplate | MessageTemplate[] | List of message templates matching the search criteria specified in the request | 
| 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. | 

 **MessageTemplate Properties** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
| messageTemplateArn | string | The ARN of the message template. This contains the active version qualifier at the end of the ARN | 
| messageTemplateId | string | The ID of the message template. This does NOT contain a qualifier with the version of the message template. | 
| name | string | Name of the message template | 
| description | string | Description of the message template | 

 **SearchMessageTemplatesParams Properties** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
| channels | MessageTemplateChannel[] | The channel(s) to return message templates for. If the list is empty, no message templates will be returned. Supported values: "EMAIL" | 
| queries | MessageTemplateQueryField[] | Queries are used to filter the returned message templates by name or description. Leaving the queries empty will return all message templates associated with the agent's routing profile | 
| maxResults | number | Maximum number of message templates to return | 
| 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. | 

 **MessageTemplateQueryField Properties** 


|  **Parameter**  |  **Type**  |  **Description**  | 
| --- | --- | --- | 
| name | "name" \$1 "description" | The message templates will be filtered by the values matching the text in the name field provided | 
| values | string[] | The values of the attribute to query the message templates by | 
| priority | "HIGH" \$1 "MEDIUM" \$1 "LOW" | The importance of the attribute field when calculating query result relevancy scores. The value set for this parameter affects the ordering of search results. | 
| allowFuzziness | boolean | Whether the query expects only exact matches on the attribute field values. The results of the query will only include exact matches if this parameter is set to false. | 
| operator | "CONTAINS" \$1 "CONTAINS\$1AND\$1PREFIX" | Include all templates that contain the values or only templates that contain the values as the prefix. | 