---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# CTIOperationResponse - Scoped, Global

# CTIOperationResponse - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 21 minutes to read

The CTIOperationResponse script include provides methods to set and get data on the current CTIOperationResponse object.

You use CTIOperationResponse objects to pass information between an operation handler and a
message transformer within the ServiceNow
Voice framework.

Typically, an operation handler is responsible for setting values on the CTIOperationResponse
object as it processes the associated request. A message transformer is then responsible for
getting the values from the CTIOperationRequest object and building the CTI-specific payload
that is sent back to the computer telephony integrator (CTI) provider.  
The ServiceNow base system provides working operation handlers and message transformers that enable connection to Amazon Connect. When building contact flows within Amazon Connect, there are two integration points between Amazon services and a ServiceNow instance:

* Amazon Web Services (AWS) Lambda Proxy (Invoke AWS Lambda function)
* AWS Lex Bot (Get Customer Input)
{#CTIOperationResponseAPI__ul_pqp_3hl_hlb}You can find the available operation handlers and message transformers for these integration points in the Operation Handlers \[sn_cti_operation_handler\] and Provider Message Transformer \[sn_cti_provider_msg_transormer\] tables.

The following operation handler script shows how to use various
CTIOperationResponse methods to set values on the CTIOperationResponse
object.  

    (function(/*CTIOperationRequest*/ request, /*CTIOperationResponse*/ response) {

      try {
        var state = request.getParameter('$state');
        if(!state) {
          state = 'new';
        }
        var phone = request.getParameter('contact.phone');
        var username = request.getParameter('contact.username');
        var someDataPresent = phone || username;
        if(!someDataPresent) {
          throw 'phone or username must be supplied';
        }
        if('new' === state) {
          var userGr = null;
          if(phone || username) {
            userGr = new GlideRecordSecure('sys_user');
            var qc = null;
            if(phone) {
              qc = userGr.addQuery('phone', phone);
              qc.addOrCondition('mobile_phone', phone);
              qc.addOrCondition("home_phone", phone);
            }
            if(username) {
              if(qc) {
                qc.addOrCondition('user_name', username);
              } else {
                qc = userGr.addQuery('user_name', username);
              }
            }
            // If there was criteria then run the query
            if(qc) {
              userGr.query();
            } else {
              userGr = null;
            }
          }
    			
          var foundUser = userGr && userGr.next();

          var phonelogGr = new GlideRecord('sn_openframe_phone_log');
          phonelogGr.initialize();
          phonelogGr.setValue('call_id', request.getParameter('contact.id'));
          phonelogGr.setValue('phone_number', phone);
          if(foundUser) {
            phonelogGr.setValue('contact', userGr.getUniqueValue());
          }
          phonelogGr.insert();
    			
          var interactionGr = new GlideRecordSecure('interaction');
          interactionGr.initialize();
          interactionGr.setValue('type', 'phone');
          interactionGr.setValue('short_description', 'User Contact via Phone: ' + phone);
          interactionGr.setValue('channel_metadata_table', 'sn_openframe_phone_log');
          interactionGr.setValue('channel_metadata_document',phonelogGr.getUniqueValue());
    			
          if(foundUser) {
            interactionGr.setValue('opened_for', userGr.getUniqueValue());
            response.setSessionAttribute('snc_user_first_name', userGr.getValue('first_name'));
            response.setSessionAttribute('snc_user_last_name', userGr.getValue('last_name'));
            response.setSessionAttribute('snc_user_sys_id', userGr.getUniqueValue());
          } else {
            response.setSessionAttribute('snc_user_sys_id', "USER_NOT_FOUND");
          }
          interactionGr.setValue('state', 'new');

          var interactionId = interactionGr.insert();

          response.setStatusCode(200);
          response.setMessage('success');
          response.setSessionAttribute('interactionTable', 'interaction');
          response.setSessionAttribute('interactionId', interactionId);

        }
      } catch(e) {
        ctx.setError(e);
      }

    })(request, response);

For additional information on creating operation handlers, see [Configure a contact flow for an
automated caller interaction](https://www.servicenow.com/docs/access?context=establish-automated-bot-interactions&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

The following message transformer script gets the values set on the CTIOperationResponse
object and stores them in the CTI-specific payload that is then sent back to the CTI
provider.  

    (function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {
    	// AWS Connect Lambda expects name value pairs only
    	var out = {};
    	for(var k in operationResponse.getSessionAttributes()) {
    		out[k] = operationResponse.getSessionAttributes()[k];
    	}
    	out.statusCode = operationResponse.getStatusCode();
    	out.message = operationResponse.getMessage();
    	httpResponse.setBody(out);
    })(operationResponse, httpResponse);

This script include runs in the `sn_cti_core` namespace. Before you are able to access the CTIOperationRequest script include, the ServiceNow
Voice Core (sn_cti_core) plugin must be installed. For information on this installation, see [Install ServiceNow Voice applications](https://www.servicenow.com/docs/access?context=install-ccc-apps&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

For additional information on the ServiceNow
Voice, see [ServiceNow Voice](https://www.servicenow.com/docs/access?context=cloud-call-center-overview&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

## CTIOperationResponse - CTIOperationResponse(String origin) {#ariaid-title2}

Instantiates a CTIOperationResponse object.
{#CTIOpResp-CTIOperationResp_S__table_zx4_l3y_glb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#CTIOpResp-CTIOperationResp_S__table_zx4_l3y_glb}  

    var response = new sn_cti_core.CTIOperationResponse();
    response.setMinorVersion(3);

## CTIOperationResponse - getAuthToken() {#ariaid-title3}

Returns the authentication token that was set on the CTIOperationResponse
object.
This token is used by the ServiceNow
Voice framework to authenticate the current ServiceNow
Voice user before executing the requested operation handler if the handler's
auth_required flag is set to true. The
auth_required flag is a field in the Operation Handler
\[sn_cti_operation_handler\] table. The life of an authentication token should be for the life
of the call session, but is determined by the CTI provider.

You can define whatever authentication/authorization handling required by your
implementation by creating your own authentication operation handler. Regardless of how the
authentication token is generated, the message translator must pass the token back in the
CTI payload. Additionally, the CTI provider must store this authentication token locally and
pass it in each operation request that requires authentication.

If using the instance provided authenticate operation handler, the handler initiates the
creation of the authentication token based on a four-digit user-entered pin. It then sets
the authentication token in the sessionAttributes object of the CTIOperationResponse object.
The associated message transformer translates the sessionAttributes object into the
CTI-specific payload and then sends it to the CTI provider.  
Note:  
If the authentication token is not passed, all requests to execute operation handlers with the auth_required flag set will fail. If you do not use authentication, you do not need to maintain authentication tokens.  
The ServiceNow base system provides working operation handlers and message transformers that enable connection to Amazon Connect. When building contact flows within Amazon Connect, there are two integration points between Amazon services and a ServiceNow instance:

* Amazon Web Services (AWS) Lambda Proxy (Invoke AWS Lambda function)
* AWS Lex Bot (Get Customer Input)
{#CTIOpResp-getAuthToken__ul_pqp_3hl_hlb}You can find the available operation handlers and message transformers for these integration points in the Operation Handlers \[sn_cti_operation_handler\] and Provider Message Transformer \[sn_cti_provider_msg_transormer\] tables. {#CTIOpResp-getAuthToken__table_bfd_c4x_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 2. Parameters]

{#CTIOpResp-getAuthToken__table_bfd_c4x_zkb} {#CTIOpResp-getAuthToken__table_cfd_c4x_zkb__entry__2}

| Type | Description |
|-|-|
| String | The authentication token previously set on the CTIOperationRequest object. If not set, returns null. |
[Table 3. Returns]

{#CTIOpResp-getAuthToken__table_cfd_c4x_zkb}  

    var response = new sn_cti_core.CTIOperationResponse();
    var token = response.getAuthToken();

## CTIOperationResponse - getError() {#ariaid-title4}

Returns the error object associated with the current CTIOperationResponse
object.
You might use this information to formulate the payload returned to the computer telephony
integration (CTI) provider.
{#CTIOpResp-getError__table_szx_nt4_blb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 4. Parameters]

{#CTIOpResp-getError__table_szx_nt4_blb} {#CTIOpResp-getError__table_tzx_nt4_blb__entry__2}

| Type | Description |
|-|-|
| Object | Operation error information. The format of this object is determined by the CTI provider. If an error does not exist, returns null. |
[Table 5. Returns]

{#CTIOpResp-getError__table_tzx_nt4_blb}  

    (function( /*CTIProviderResponseExecutionContext*/ ctx, /*CTIOperationRequest*/ operationRequest, /*CTIOperationResponse*/ operationResponse, /*HTTPResponse*/ httpResponse) {
        var sessionAttributes = {},
            intentResponse;
        var statusCode = -1;
        var message = 'Unprocessed';
        if (operationResponse) {
            statusCode = operationResponse.getStatusCode();
            sessionAttributes = operationResponse.getSessionAttributes();
            message = operationResponse.getMessage();
            var error = operationResponse.getError();
            if (error) {
                sessionAttributes.error = error;
            }
        }
        if (sn_cti_core.CTIRequestDispatcher.Constants.HTTP.Status.AUTH_REQUIRED.code === statusCode) {
            //first call for a secure action without authentication token
            sessionAttributes.statusCode = 401;
            sessionAttributes.message = message;
            intentResponse = {
                sessionAttributes: sessionAttributes,
                dialogAction: {
                    type: 'Close',
                    fulfillmentState: 'Fulfilled',
                    message: {
                        contentType: 'PlainText',
                        content: 'This operation requires authentication. Say authenticate for authentication.'
                    }
                }
            };
        } else if ('DialogCodeHook' === operationRequest.getParameter('$$invocationSource')) {
            //pass back authToken and interactionId
            sessionAttributes.authToken = operationRequest.getAuthToken();
            sessionAttributes.interactionId = operationRequest.getInteractionSysId();
    		var originalSlots = operationRequest.getParameter('$$slots');
            var responseParameters = operationResponse ? operationResponse.getParameters() : {};
            responseParameters = responseParameters ? responseParameters : {};
            // See if we processing happened and we got a dialogAction
    		var responseDialogAction = responseParameters['dialogAction'];
    		// Default dialog action
            var dialogAction = {
                type: 'Delegate',
                slots: originalSlots
            };
    		// If the response doesn't contain an override replay the inputs
            if (responseDialogAction) {
                // We bypassed dialoghook so delegate and pass through inputs
                dialogAction = responseDialogAction;
            }
            intentResponse = {
                sessionAttributes: sessionAttributes,
                dialogAction: dialogAction
            };
        } else {
            // Override required session attributes
            sessionAttributes.statusCode = statusCode;
            sessionAttributes.message = message;
            // Build response template
            intentResponse = {
                sessionAttributes: sessionAttributes,
                dialogAction: {
                    type: 'Close',
                    fulfillmentState: 'Fulfilled',
                    message: {
                        contentType: 'PlainText',
                        content: message
                    }
                }
            };
        }
        httpResponse.setBody(intentResponse);
    })(ctx, operationRequest, operationResponse, httpResponse);

## CTIOperationResponse - getInteractionSysId() {#ariaid-title5}

Returns the sys_id of the interaction record associated with the call session that was
set on the CTIOperationResponse object.
The [CTIOperationResponse -
setInteractionSysId(String Id)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-setInteractionSysId_S "Sets the sys_id of the interaction record associated with the operation request on the current CTIOperationResponse object.")
method must have been called prior to
calling this method.
{#CTIOpResp-getInteractionSysId__table_cjp_gpg_ykb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 6. Parameters]

{#CTIOpResp-getInteractionSysId__table_cjp_gpg_ykb} {#CTIOpResp-getInteractionSysId__table_djp_gpg_ykb__entry__2}

| Type | Description |
|-|-|
| String | The sys_id of the interaction record set on the CTIOperationResponse object. Interaction records are located in the Interaction \[interaction\] table. If the interaction record sys_id is not set, the method returns null. |
[Table 7. Returns]

{#CTIOpResp-getInteractionSysId__table_djp_gpg_ykb}  

    var request = new sn_cti_core.CTIOperationResponse();
    var interactionId = request.getInteractionSysId();

## CTIOperationResponse - getMajorVersion() {#ariaid-title6}

Returns the major version of the computer telephony integrator (CTI) software set on
the current CTIOperationResponse object.
Use this method if the CTI providers connected to your ServiceNow
instance are running multiple versions of their software, as different software versions may
require different payloads. If the payload is only slightly different between the software
versions, it may make sense to have only a single message transformer. You can then handle
the payload differences by just checking the version of software making the request within
your message transformer. If the required payload is significantly different between
versions, it may be more effective to use multiple message transformers.
{#CTIOpResp-getMajorVersion__table_olp_qvg_ykb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 8. Parameters]

{#CTIOpResp-getMajorVersion__table_olp_qvg_ykb} {#CTIOpResp-getMajorVersion__table_plp_qvg_ykb__entry__2}

| Type | Description |
|-|-|
| Number | Major version number of the CTI software. If the major version was never set, returns 1. |
[Table 9. Returns]

{#CTIOpResp-getMajorVersion__table_plp_qvg_ykb}  

    var request = new sn_cti_core.CTIOperationResponse();
    var majorVersion = response.getMajorVersion();

## CTIOperationResponse - getMessage() {#ariaid-title7}

Returns the message string set on the current CTIOperationResponse object.
Typically this is a message that is spoken back to the user once an operation is complete.
You can set this value using the [CTIOperationResponse -
setMessage(String message)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-setMessage_S "Sets a text message on the current CTIOperationResponse object.") method.
{#CTIOpResp-getMessage__table_p3z_hh4_blb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 10. Parameters]

{#CTIOpResp-getMessage__table_p3z_hh4_blb} {#CTIOpResp-getMessage__table_q3z_hh4_blb__entry__2}

| Type | Description |
|-|-|
| String | Message text. If no message exists, returns null. |
[Table 11. Returns]

{#CTIOpResp-getMessage__table_q3z_hh4_blb}  

    (function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {
      // AWS Connect Lambda expects name value pairs only
      var out = {};
      for(var k in operationResponse.getSessionAttributes()) {
        out[k] = operationResponse.getSessionAttributes()[k];
      }
      out.statusCode = operationResponse.getStatusCode();
      out.message = operationResponse.getMessage();
      httpResponse.setBody(out);
    })(operationResponse, httpResponse);

## CTIOperationResponse - getMinorVersion() {#ariaid-title8}

Returns the minor version of the computer telephony integrator (CTI) software set on
the current CTIOperationResponse object.
Use this method if the CTI providers connected to your ServiceNow
instance are running multiple versions of their software, as different software versions may
require different payloads. If the payload is only slightly different between the software
versions, it may make sense to have only a single message transformer. You can then handle
the payload differences by just checking the version of software making the request within
your message transformer. If the required payload is significantly different between
versions, it may be more effective to use multiple message transformers.
{#CTIOpResp-getMinorVersion__table_chp_z41_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 12. Parameters]

{#CTIOpResp-getMinorVersion__table_chp_z41_zkb} {#CTIOpResp-getMinorVersion__table_dhp_z41_zkb__entry__2}

| Type | Description |
|-|-|
| Number | Minor version number of the payload associated with this interaction. If the minor version was never set, returns 0. |
[Table 13. Returns]

{#CTIOpResp-getMinorVersion__table_dhp_z41_zkb}  

    var request = new sn_cti_core.CTIOperationResponse();
    var minorVersion = request.getMinorVersion();

## CTIOperationResponse - getParameter(String key) {#ariaid-title9}

Returns the value of a specified key previously set on the current CTIOperationResponse
object.
Using the get/set parameter methods enables the passing of
virtually any string or number value between an operation handler and a message transformer.
The parameter object can contain zero or more key/value pairs of data that directly
correlate to the current operation response. The operation handler determines what key/value
pairs are required as it produces these values. Use the [CTIOperationResponse -
setParameter(String key, Object value)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-setParameter_S_O "Sets the specified key-value pair on the associated CTIOperationResponse object.")
method to set parameters on the
current CTIOperationResponse object.
{#CTIOpResp-getParameter_S__table_n1d_rgr_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | The name of the key value to return. |
[Table 14. Parameters]

{#CTIOpResp-getParameter_S__table_n1d_rgr_zkb} {#CTIOpResp-getParameter_S__table_o1d_rgr_zkb__entry__2}

| Type | Description |
|-|-|
| String | The value of the passed in key. If no such key exists, returns null. |
[Table 15. Returns]

{#CTIOpResp-getParameter_S__table_o1d_rgr_zkb}  

    var request = new sn_cti_core.CTIOperationResponse();
    var parm = request.getParameter('contact.phone');

## CTIOperationResponse - getParameters() {#ariaid-title10}

Returns the key-value pairs for all parameters that were previously set on the current
CTIOperationResponse object.
Using the get/set parameter methods enables the passing of
virtually any string or number value between an operation handler and a message transformer.
The parameter object can contain zero or more key/value pairs of data that directly
correlate to the current operation response. The operation handler determines what key/value
pairs are required as it produces these values. Use the [CTIOperationResponse -
setParameter(String key, Object value)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-setParameter_S_O "Sets the specified key-value pair on the associated CTIOperationResponse object.")
method to set parameters on the
current CTIOperationResponse object.
{#CTIOpResp-getParameters__table_hcc_y3b_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 16. Parameters]

{#CTIOpResp-getParameters__table_hcc_y3b_zkb} {#CTIOpResp-getParameters__table_icc_y3b_zkb__entry__2}

| Type | Description |
|-|-|
| Object | A map of key-value pairs that were previously set on the CTIOperationResponse object. This key-value pairs are free-form and defined by the needs of the operation handler. The returned values are either Strings or Numbers. |
[Table 17. Returns]

{#CTIOpResp-getParameters__table_icc_y3b_zkb}  

    (function( /*CTIProviderResponseExecutionContext*/ ctx, /*CTIOperationRequest*/ operationRequest, /*CTIOperationResponse*/ operationResponse, /*HTTPResponse*/ httpResponse) {
      var sessionAttributes = {},
          intentResponse;
      var statusCode = -1;
      var message = 'Unprocessed';
      if (operationResponse) {
        statusCode = operationResponse.getStatusCode();
        sessionAttributes = operationResponse.getSessionAttributes();
        message = operationResponse.getMessage();
        var error = operationResponse.getError();
        if (error) {
          sessionAttributes.error = error;
        }
      }
      if (sn_cti_core.CTIRequestDispatcher.Constants.HTTP.Status.AUTH_REQUIRED.code === statusCode) {
        //first call for a secure action without authentication token
        sessionAttributes.statusCode = 401;
        sessionAttributes.message = message;
        intentResponse = {
          sessionAttributes: sessionAttributes,
          dialogAction: {
            type: 'Close',
            fulfillmentState: 'Fulfilled',
            message: {
              contentType: 'PlainText',
              content: 'This operation requires authentication. Say authenticate for authentication.'
            }
          }
        };
      } else if ('DialogCodeHook' === operationRequest.getParameter('$$invocationSource')) {
          //pass back authToken and interactionId
          sessionAttributes.authToken = operationRequest.getAuthToken();
          sessionAttributes.interactionId = operationRequest.getInteractionSysId();
          var originalSlots = operationRequest.getParameter('$$slots');
          var responseParameters = operationResponse ? operationResponse.getParameters() : {};
          responseParameters = responseParameters ? responseParameters : {};
          // See if processing happened and we got a dialogAction
          var responseDialogAction = responseParameters['dialogAction'];
          // Default dialog action
          var dialogAction = {
            type: 'Delegate',
            slots: originalSlots
          };
          // If the response doesn't contain an override replay the inputs
          if (responseDialogAction) {
            // We bypassed dialoghook so delegate and pass through inputs
            dialogAction = responseDialogAction;
          }
            intentResponse = {
                sessionAttributes: sessionAttributes,
                dialogAction: dialogAction
            };
        } else {
          // Override required session attributes
          sessionAttributes.statusCode = statusCode;
          sessionAttributes.message = message;
          // Build response template
          intentResponse = {
            sessionAttributes: sessionAttributes,
            dialogAction: {
              type: 'Close',
              fulfillmentState: 'Fulfilled',
              message: {
                contentType: 'PlainText',
                content: message
              }
            }
          };
      }
      httpResponse.setBody(intentResponse);
    })(ctx, operationRequest, operationResponse, httpResponse);

## CTIOperationResponse - getSessionAttribute(String key) {#ariaid-title11}

Returns the value for a specified session attribute key set on the current
CTIOperationResponse object.
Using the get/set session attribute methods enables the
passing of virtually any string or number value between an operation handler and a message
transformer. Session attributes can also be accessed within a contact flow. The
sessionAttribute object can contain zero or more key/value pairs of data, such as the
contact's phone number, that are valid for the duration of a computer telephony integration
provider defined session. The operation handler determines what session attribute key/value
pairs are needed as it utilizes these values during processing. Typically the operation
handler sets these attributes on the CTIOperationResponse object by calling the [CTIOperationResponse -
setSessionAttribute(String key, Object value)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-setSessionAttribute_S_O "Sets the specified session attribute key-value pair on the associated CTIOperationResponse object.")
method and the message transformer consumes the attributes using this method.
{#CTIOpResp-getSessionAttribute_S__table_v1k_cwr_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | The name of the key value to return. |
[Table 18. Parameters]

{#CTIOpResp-getSessionAttribute_S__table_v1k_cwr_zkb} {#CTIOpResp-getSessionAttribute_S__table_w1k_cwr_zkb__entry__2}

| Type | Description |
|-|-|
| String | Value of the passed in key. If no such key exists, returns null. |
[Table 19. Returns]

{#CTIOpResp-getSessionAttribute_S__table_w1k_cwr_zkb}  

    var response = new sn_cti_core.CTIOperationResponse();
    var phoneAttribute = response.getSessionAttribute('contact.phone');

## CTIOperationResponse - getSessionAttributes() {#ariaid-title12}

Returns the key-value pairs for all session attributes that were previously set on the
current CTIOperationResponse object.
Using the get/set session attribute methods enables the
passing of virtually any string or number value between an operation handler and a message
transformer. Session attributes can also be accessed within a contact flow. The
sessionAttribute object can contain zero or more key/value pairs of data, such as the
contact's phone number, that are valid for the duration of a computer telephony integration
provider defined session. The operation handler determines what session attribute key/value
pairs are needed as it utilizes these values during processing. Typically the operation
handler sets these attributes on the CTIOperationResponse object by calling the [CTIOperationResponse -
setSessionAttribute(String key, Object value)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-setSessionAttribute_S_O "Sets the specified session attribute key-value pair on the associated CTIOperationResponse object.")
method and the message transformer consumes the attributes using this method.
{#CTIOpResp-getSessionAttributes__table_ujd_ltr_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 20. Parameters]

{#CTIOpResp-getSessionAttributes__table_ujd_ltr_zkb} {#CTIOpResp-getSessionAttributes__table_vjd_ltr_zkb__entry__2}

| Type | Description |
|-|-|
| Object | A map of key-value pairs that were previously set on the CTIOperationResponse object. This key-value pairs are free-form and defined by the needs of the operation handler. The returned values are either Strings or Numbers. |
[Table 21. Returns]

{#CTIOpResp-getSessionAttributes__table_vjd_ltr_zkb}  

    (function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {
      // AWS Connect Lambda expects name value pairs only
      var out = {};
      for(var k in operationResponse.getSessionAttributes()) {
        out[k] = operationResponse.getSessionAttributes()[k];
      }
      out.statusCode = operationResponse.getStatusCode();
      out.message = operationResponse.getMessage();
      httpResponse.setBody(out);
    })(operationResponse, httpResponse);

## CTIOperationResponse - getStatusCode() {#ariaid-title13}

Returns the status code set on the current CTIOperationResponse object.
These status codes should correspond with standard HTTP status codes, such as 200 for
success, 401 for authorization required. Typically, the resultant status codes are
determined by the operation handler and are set on the CTIOperationResponse object using the
[CTIOperationResponse -
setStatusCode(String statusCode)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-setStatusCode_N "Sets the status code of the current operation request on the CTIOperationResponse object.") method. The message transformer then uses this method to
include the status code in the payload returned to the computer telephony integrator
provider.
{#CTIOPResp-getStatusCode__table_hjx_cp4_blb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 22. Parameters]

{#CTIOPResp-getStatusCode__table_hjx_cp4_blb} {#CTIOPResp-getStatusCode__table_ijx_cp4_blb__entry__2}

| Type | Description |
|-|-|
| Number | Status code of the current operation. If a status code has not been set, returns -1. |
[Table 23. Returns]

{#CTIOPResp-getStatusCode__table_ijx_cp4_blb}  

    (function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {
      // AWS Connect Lambda expects name value pairs only
      var out = {};
      for(var k in operationResponse.getSessionAttributes()) {
        out[k] = operationResponse.getSessionAttributes()[k];
      }
      out.statusCode = operationResponse.getStatusCode();
      out.message = operationResponse.getMessage();
      httpResponse.setBody(out);
    })(operationResponse, httpResponse);

## CTIOperationResponse - setAuthToken(String token) {#ariaid-title14}

Sets an authentication token on the current CTIOperationResponse object.
This token is used by the ServiceNow
Voice framework to authenticate the current ServiceNow
Voice user before executing the requested operation handler if the handler's
auth_required flag is set to true. The
auth_required flag is a field in the Operation Handler
\[sn_cti_operation_handler\] table. The life of an authentication token should be for the life
of the call session, but is determined by the CTI provider.

You can define whatever authentication/authorization handling required by your
implementation by creating your own authentication operation handler. Regardless of how the
authentication token is generated, the message translator must pass the token back in the
CTI payload. Additionally, the CTI provider must store this authentication token locally and
pass it in each operation request that requires authentication.

If using the instance provided authenticate operation handler, the handler initiates the
creation of the authentication token based on a four-digit user-entered pin. It then sets
the authentication token in the sessionAttributes object of the CTIOperationResponse object.
The associated message transformer translates the sessionAttributes object into the
CTI-specific payload and then sends it to the CTI provider.  
Note:  
If the authentication token is not passed, all requests to execute operation handlers with the auth_required flag set will fail. If you do not use authentication, you do not need to maintain authentication tokens.  
The ServiceNow base system provides working operation handlers and message transformers that enable connection to Amazon Connect. When building contact flows within Amazon Connect, there are two integration points between Amazon services and a ServiceNow instance:

* Amazon Web Services (AWS) Lambda Proxy (Invoke AWS Lambda function)
* AWS Lex Bot (Get Customer Input)
{#CTIOpResp-setAuthToken_S__ul_pqp_3hl_hlb}You can find the available operation handlers and message transformers for these integration points in the Operation Handlers \[sn_cti_operation_handler\] and Provider Message Transformer \[sn_cti_provider_msg_transormer\] tables. {#CTIOpResp-setAuthToken_S__table_xvb_3wx_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 24. Parameters]

{#CTIOpResp-setAuthToken_S__table_xvb_3wx_zkb} {#CTIOpResp-setAuthToken_S__table_yvb_3wx_zkb__entry__2}

| Type | Description |
|-|-|
| String | The authentication token to use to authenticate operations that have the auth_required flag set. |
[Table 25. Returns]

{#CTIOpResp-setAuthToken_S__table_yvb_3wx_zkb}  

    var response = new sn_cti_core.CTIOperationResponse();
    var authenticate = <Your authentication code here>; // Authenticate the user
    if (authenticated) {
    	var claims = {
    		"interactionId":interactionGr.sys_id.toString()
    	};
    	var jwt = new sn_cti_core.AuthHelpers().generateJWT(claims);
    	response.setAuthToken(jwt);
    }

## CTIOperationResponse - setError(Object error) {#ariaid-title15}

Sets the error object in the current CTIOperationResponse object.
You can use the error object in the component to formulate the payload to send to the
computer telephony integrator (CTI) provider.
{#CTIOpResp-setError_O__table_jdf_vw4_blb__entry__3}

| Name | Type | Description |
|-|-|-|
| error | Object | Information about the error that was detected while processing the requested operation. The format of this object is determined by the CTI provider. |
[Table 26. Parameters]

{#CTIOpResp-setError_O__table_jdf_vw4_blb} {#CTIOpResp-setError_O__table_kdf_vw4_blb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 27. Returns]

{#CTIOpResp-setError_O__table_kdf_vw4_blb}  

    var response = new sn_cti_core.CTIOperationResponse();
    response.setError(new Error("You did not supply a field"));

## CTIOperationResponse - setInteractionSysId(String Id) {#ariaid-title16}

Sets the sys_id of the interaction record associated with the operation request on the
current CTIOperationResponse object.
{#CTIOpResp-setInteractionSysId_S__table_usk_lrg_ykb__entry__3}

| Name | Type | Description |
|-|-|-|
| sys_id | String | The sys_id to set for the current interaction. |
[Table 28. Parameters]

{#CTIOpResp-setInteractionSysId_S__table_usk_lrg_ykb} {#CTIOpResp-setInteractionSysId_S__table_vsk_lrg_ykb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 29. Returns]

{#CTIOpResp-setInteractionSysId_S__table_vsk_lrg_ykb}  

    var response = new sn_cti_core.CTIOperationResponse();
    response.setInteractionSysId('98529cc55380001048e5ddeeff7b120b');

## CTIOperationResponse - setMajorVersion(Number majorVersion) {#ariaid-title17}

Sets the major version of the computer telephony integrator (CTI) provider software
making the request on the associated CTIOperationResponse object.
Use this method if the CTI providers connected to your ServiceNow
instance are running multiple versions of their software, as different software versions may
require different payloads. If the payload is only slightly different between the software
versions, it may make sense to have only a single message transformer. You can then handle
the payload differences by just checking the version of software making the request within
your message transformer. If the required payload is significantly different between
versions, it may be more effective to use multiple message transformers.
{#CTIOpResp-setMajorVersion_N__table_jlt_pz1_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| majorVersion | Number | Major version of the CTI provider software making the operation request. If this value was not previously set, returns 1. |
[Table 30. Parameters]

{#CTIOpResp-setMajorVersion_N__table_jlt_pz1_zkb} {#CTIOpResp-setMajorVersion_N__table_klt_pz1_zkb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 31. Returns]

{#CTIOpResp-setMajorVersion_N__table_klt_pz1_zkb}  

    var request = new sn_cti_core.CTIOperationResponse();
    request.setMajorVersion(2);

## CTIOperationResponse - setMessage(String message) {#ariaid-title18}

Sets a text message on the current CTIOperationResponse object.
Typically this is a message that is spoken back to the user once an operation is complete
and is set by the associated operation handler. The message transformer then uses the [CTIOperationResponse -
getMessage()](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-getMessage "Returns the message string set on the current CTIOperationResponse object.") method to obtain the message
and pass it back to the computer telephony integration provider.
{#CTIOpResp-setMessage_S__table_eyb_l44_blb__entry__3}

| Name | Type | Description |
|-|-|-|
| message | String | Message text |
[Table 32. Parameters]

{#CTIOpResp-setMessage_S__table_eyb_l44_blb} {#CTIOpResp-setMessage_S__table_fyb_l44_blb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 33. Returns]

{#CTIOpResp-setMessage_S__table_fyb_l44_blb}  

    (function(/*CTIOperationRequest*/ request, /*CTIOperationResponse*/ response, /*Context*/ ctx) {	
      var notes = '', lang = request.getLanguage();
      try { 
    		
        var interactionGr = request.getInteractionRecord();

        var now_GR = new GlideRecord('sys_user');
        if(interactionGr && now_GR.get(interactionGr.opened_for.toString())) {	
        if(now_GR.locked_out == true) {
            notes += gs.getMessageLang("User record found locked. Unlocking the account.\n", lang);
            now_GR.locked_out=false;
            now_GR.update();
            response.setStatusCode(200);
            response.setMessage(gs.getMessageLang("Your account has been unlocked.", lang));
          } else {
            notes += gs.getMessageLang("User record not locked.\n", lang);
            response.setStatusCode(200);
            response.setMessage(gs.getMessageLang("Your account doesn't seem to be locked.", lang));
          }	
        } else {
          notes += gs.getMessageLang("User record not found. Transfer to agent\n", lang);
          response.setStatusCode(302);
          response.setMessage(gs.getMessageLang("I am unable to find your record. Let me transfer to someone who can help.", lang));
        }
        if(interactionGr) {
          interactionGr.work_notes = notes;
          interactionGr.update();
        }
      } catch(e) {
        ctx.setError(e);
      }
    })(request, response, ctx);

## CTIOperationResponse - setMinorVersion(Number minorVersion) {#ariaid-title19}

Sets the minor version of the computer telephony integrator (CTI) provider software
making the request on the associated CTIOperationResponse object.
Use this method if the CTI providers connected to your ServiceNow
instance are running multiple versions of their software, as different software versions may
require different payloads. If the payload is only slightly different between the software
versions, it may make sense to have only a single message transformer. You can then handle
the payload differences by just checking the version of software making the request within
your message transformer. If the required payload is significantly different between
versions, it may be more effective to use multiple message transformers.
{#CTIOpResp-setMinorVersion_N__table_zqj_52b_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| minorVersion | Number | Minor version of the CTI provider software making the operation request. If this value was not previously set, returns 0. |
[Table 34. Parameters]

{#CTIOpResp-setMinorVersion_N__table_zqj_52b_zkb} {#CTIOpResp-setMinorVersion_N__table_arj_52b_zkb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 35. Returns]

{#CTIOpResp-setMinorVersion_N__table_arj_52b_zkb}  

    var response = new sn_cti_core.CTIOperationResponse();
    response.setMinorVersion(3);

## CTIOperationResponse - setParameter(String key, Object value) {#ariaid-title20}

Sets the specified key-value pair on the associated CTIOperationResponse
object.
Using the get/set parameter methods enables the passing of virtually any string or number
value between an operation handler and a message transformer. The parameter object can
contain zero or more key/value pairs of data that directly correlate to the current
operation request. The operation handler determines what key/value pairs are required as it
consumes these values. Typically the operation handler sets these parameters on the
CTIOperationResponse object by calling this method and the message transformer consumes them
using the [CTIOperationResponse -
getParmeter(String key)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-getParameter_S "Returns the value of a specified key previously set on the current CTIOperationResponse object.") or [CTIOperationResponse -
getSParameters()](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-getParameters "Returns the key-value pairs for all parameters that were previously set on the current CTIOperationResponse object.") method.  
Note:  
You should only store objects that can survive a `JSON.parse(JSON.stringify(object))` operation. Objects not meeting this criteria may not propagate correctly through the entire operation processing chain.  
For example:

    var x = {
      "string": 'abc',
      "int": 123,
      "float": 1.234,
      "number": new Number(3),
      "boolean": true,
      "date": new Date(2006, 0, 2, 15, 4, 5),
      "object": {
        "string": 'abc',
        "int": 123,
        "float": 1.234,
        "number": new Number(3),
        "boolean": true,
        "date": new Date(2006, 0, 2, 15, 4, 5)
      },
      "function": function(abc) {

      }
    }
    var stringify = JSON.stringify(x);
    gs.info(stringify);
    var hydrate = JSON.parse(stringify);
    var stringify2 = JSON.stringify(hydrate);
    gs.info(stringify2);

Produces:

    {"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z","object":{"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z"}}
    {"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z","object":{"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z"}}

{#CTIOpResp-setParameter_S_O__table_ab4_k3r_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | Name of the key under which to store the associated value. |
| value | Object | Value to store for the key. Valid data types: * string * int * float * number * boolean * date * object {#CTIOpResp-setParameter_S_O__ul_mcs_2sr_zkb} |
[Table 36. Parameters]

{#CTIOpResp-setParameter_S_O__table_ab4_k3r_zkb} {#CTIOpResp-setParameter_S_O__table_bb4_k3r_zkb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 37. Returns]

{#CTIOpResp-setParameter_S_O__table_bb4_k3r_zkb}  

    var response = new sn_cti_core.CTIOperationResponse();
    response.setParameter('contact.phone', '+15552222345');
    response.setParameter('contact.okToCall', true);
    response.setParameter('contact.address', {
        street: '1234 Main St'
        city: 'API City',
        zip: 91335
    });

## CTIOperationResponse - setSessionAttribute(String key, Object value) {#ariaid-title21}

Sets the specified session attribute key-value pair on the associated
CTIOperationResponse object.
Using the get/set session attribute methods enables the passing of virtually any string or
number value between an operation handler and a message transformer. The sessionAttribute
object can contain zero or more key/value pairs of data that are valid for the duration of a
computer telephony integration provider defined session. Session attributes can also be
accessed within a contact flow. The operation handler determines what session attribute
key/value pairs are needed as it consumes these values. Typically the operation handler sets
these attributes on the CTIOperationResponse object by calling this method and the message
transformer gets the attributes using the [CTIOperationResponse -
getSessionAttribute(String key)](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-getSessionAttribute_S "Returns the value for a specified session attribute key set on the current CTIOperationResponse object.") or [CTIOperationResponse -
getSessionAttribute()](https://servicenow-prod.fluidtopics.net/5ijvP7RkHP~~EiAqN4XyIA#CTIOpResp-getSessionAttributes "Returns the key-value pairs for all session attributes that were previously set on the current CTIOperationResponse object.") method.  
Note:  
You should only store objects that can survive a `JSON.parse(JSON.stringify(object))` operation. Objects not meeting this criteria may not propagate correctly through the entire operation processing chain.  
For example:

    var x = {
      "string": 'abc',
      "int": 123,
      "float": 1.234,
      "number": new Number(3),
      "boolean": true,
      "date": new Date(2006, 0, 2, 15, 4, 5),
      "object": {
        "string": 'abc',
        "int": 123,
        "float": 1.234,
        "number": new Number(3),
        "boolean": true,
        "date": new Date(2006, 0, 2, 15, 4, 5)
      },
      "function": function(abc) {

      }
    }
    var stringify = JSON.stringify(x);
    gs.info(stringify);
    var hydrate = JSON.parse(stringify);
    var stringify2 = JSON.stringify(hydrate);
    gs.info(stringify2);

Produces:

    {"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z","object":{"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z"}}
    {"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z","object":{"string":"abc","int":123,"float":1.234,"number":3,"boolean":true,"date":"2006-01-02T23:04:05.000Z"}}

{#CTIOpResp-setSessionAttribute_S_O__table_ihm_rxr_zkb__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | Name of the session attribute key under which to set the associated value. |
| value | Object | Value to set. Valid data types: * string * int * float * number * boolean * date * object {#CTIOpResp-setSessionAttribute_S_O__ul_mcs_2sr_zkb} |
[Table 38. Parameters]

{#CTIOpResp-setSessionAttribute_S_O__table_ihm_rxr_zkb} {#CTIOpResp-setSessionAttribute_S_O__table_jhm_rxr_zkb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 39. Returns]

{#CTIOpResp-setSessionAttribute_S_O__table_jhm_rxr_zkb}  

    var response = new sn_cti_core.CTIOperationResponse();
    response.setSessionAttribute('contact.phone', '+15552222345');
    response.setSessionAttribute('contact.okToCall', true);
    response.setSessionAttribute('contact.address', {
        street: '1234 Main St'
        city: 'API City',
        zip: 91335
    });

## CTIOperationResponse - setStatusCode(Number statusCode) {#ariaid-title22}

Sets the status code of the current operation request on the CTIOperationResponse
object.
You can use any integer values to define the status, but it is recommended that you emulate
the HTTP status codes, such as 200 = Ok/Success, 400 = Bad Request, 401 = Unauthorized.
{#CTIOpResp-setStatusCode_N__table_inh_4r4_blb__entry__3}

| Name | Type | Description |
|-|-|-|
| statusCode | Number | Integer that uniquely identifies the status of the requested operation. |
[Table 40. Parameters]

{#CTIOpResp-setStatusCode_N__table_inh_4r4_blb} {#CTIOpResp-setStatusCode_N__table_jnh_4r4_blb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 41. Returns]

{#CTIOpResp-setStatusCode_N__table_jnh_4r4_blb}  

    (function(/*CTIOperationRequest*/ request, /*CTIOperationResponse*/ response, /*Context*/ ctx) {	
      var notes = '', lang = request.getLanguage();
      try { 
    		
        var interactionGr = request.getInteractionRecord();

        var now_GR = new GlideRecord('sys_user');
        if(interactionGr && now_GR.get(interactionGr.opened_for.toString())) {	
        if(now_GR.locked_out == true) {
            notes += gs.getMessageLang("User record found locked. Unlocking the account.\n", lang);
            now_GR.locked_out=false;
            now_GR.update();
            response.setStatusCode(200);
            response.setMessage(gs.getMessageLang("Your account has been unlocked.", lang));
          } else {
            notes += gs.getMessageLang("User record not locked.\n", lang);
            response.setStatusCode(200);
            response.setMessage(gs.getMessageLang("Your account doesn't seem to be locked.", lang));
          }	
        } else {
          notes += gs.getMessageLang("User record not found. Transfer to agent\n", lang);
          response.setStatusCode(302);
          response.setMessage(gs.getMessageLang("I am unable to find your record. Let me transfer to someone who can help.", lang));
        }
        if(interactionGr) {
          interactionGr.work_notes = notes;
          interactionGr.update();
        }
      } catch(e) {
        ctx.setError(e);
      }
    })(request, response, ctx);


