The ResponseTemplate API provides methods for managing response templates.

Response templates are reusable messages that agents can copy to case or task forms. They provide quick and consistent messages to users and display standard chat response messages to requesters in Agent Chat. This API requires the Templated Responses plugin (com.sn_templated_snip), which is activated by default. This API is provided within the sn_templated_snip namespace.

For additional information on response templates, see Response templates.

ResponseTemplate - ResponseTemplate()

Instantiates a new ResponseTemplate object.

Table 1. Parameters
Name Type Description
None

Example

new sn_templated_snip.ResponseTemplate().query("incident","ef4225a40a0a0b5700d0b8a790747812", "", 0, 0, true, ""); 

ResponseTemplate - query(String tableName, String recordId, String searchTerm, Number limit, Number offset, Boolean includeEvaluatedBody, String errorFormat, Object opts)

Returns all response templates from a specified table that match the passed in query criteria.

Table 3. Returns
Type Description
Object Array of all templates that match the specified search criteria. Response templates with exact matches on short name appear first in the return results. All other returned response templates are sorted by name.

Each node in the Array may contain the following parameters:

  • sys_id: String. Unique identifier of the response template.
  • name: String. Name of the response template.
  • short_name: String. Short name of the response template.
  • body: HTML. Body of the response template.
  • short_name_match: Boolean. Flag that indicates whether an exact match occurred on the short name of the response template.
  • evaluated_response: Array. Results of the template evaluation.
    • success: Boolean. Flag that indicates whether all variables rendered properly.
    • evaluated_body: HTML. Rendered response template body.
    • error: Array. Entry for each evaluation error that occurred.
      • inAccessibleVariables: String. Variables in the response template body that could not be resolved.
      • unEvaluatedVariables: String. Variablesin the response template body that were not evaluated.
      • message: String. Error message.

Example

This example shows how to query for response templates associated with the incident table.

query("incident","ef4225a40a0a0b5700d0b8a790747812", "", 0, 0, false, "");

Successful response:

[
  {
    "sys_id": "5fc1d65993003300a9bc1d1e867ffb9c",
    "name": "Incident escalation",
    "short_name": "escalation",
    "template_body": "<p>Dear ${caller_id.first_name},</p>\r\n<p>Please note that your incident ${number} has been escalated to ${assignment_group}. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>${sys_updated_by}</p>"
  }
]

Example

Same query with an error response.

query("incident","fe4225a40a0a0b5700d0b8a790747812", "", 0, 0, false, "");

Error response:

[
  {
    "sys_id": "5fc1d65993003300a9bc1d1e867ffb9c",
    "name": "Incident escalation",
    "short_name": "escalation",
    "template_body": "<p>Dear ${caller.first_name},</p>\r\n<p>Please note that your incident ${number} has been escalated to ${assignment_group}. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>${sys_updated_by}</p>",
    "evaluated_response": {
      "success": false,
      "error": {
        "unEvaluatedVariables": "caller.first_name",
        "message": "Cannot evaluate following variables: caller.first_name"
      },
      "evaluated_body": "<p>Dear <span style='color:#ff0000'>${caller.first_name}</span>,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
    }
  }
]

ResponseTemplate - render(String templateId, String tableName, String recordId, String errorFormat, Object opts)

Renders the HTML body of a specified response template.

During rendering, all variables are resolved using the information from the specified table and record. If variables cannot be resolved, or any other problem occurs during rendering, the method returns an error message in the results.

Table 5. Returns
Type Description
Object Results of the render.
  • success: Flag that indicates whether the render was successful.
  • evaluated_body: String. For success, rendered response template body. For error, response template body which includes both rendered and non-renderable variables.
  • error: Object. Error message if render was unsuccessful.
    • unEvaluatedVariables: Variables that could not be rendered.
    • message: Error message.

Example

This code example shows how to request a rendered response template for the incident table.

render("5fc1d65993003300a9bc1d1e867ffb9c","incident","ef4225a40a0a0b5700d0b8a790747812", "")

Successful response:

{
  "success": true,
  "evaluated_body": "<p>Dear Beth,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}

Example

Same render request but returning an error response.

render("5fc1d65993003300a9bc1d1e867ffb9c","incident","ef4225a40a0a0b5700d0b8a790747812", "")

Error response:

{
  "success": false,
  "error": {
    "unEvaluatedVariables": "caller.first_name",
    "message": "Cannot evaluate following variables: caller.first_name"
  },
  "evaluated_body": "<p>Dear <span style='color:#ff0000'>${caller.first_name}</span>,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}