{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":718,"path":"api-reference/server-api-reference/CTIOperationResponseAPI.md","title":"CTIOperationResponse - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# CTIOperationResponse - Scoped, Global\n\nThe CTIOperationResponse script include provides methods to set and get data on the current CTIOperationResponse object.\n\nYou use CTIOperationResponse objects to pass information between an operation handler and a message transformer within the ServiceNow Voice framework.\n\nTypically, 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.\n\nThe 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:\n\n-   Amazon Web Services \\(AWS\\) Lambda Proxy \\(Invoke AWS Lambda function\\)\n-   AWS Lex Bot \\(Get Customer Input\\)\n\nYou 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.\n\nThe following operation handler script shows how to use various CTIOperationResponse methods to set values on the CTIOperationResponse object.\n\n```\n(function(/*CTIOperationRequest*/ request, /*CTIOperationResponse*/ response) {\n\n  try {\n    var state = request.getParameter('$state');\n    if(!state) {\n      state = 'new';\n    }\n    var phone = request.getParameter('contact.phone');\n    var username = request.getParameter('contact.username');\n    var someDataPresent = phone || username;\n    if(!someDataPresent) {\n      throw 'phone or username must be supplied';\n    }\n    if('new' === state) {\n      var userGr = null;\n      if(phone || username) {\n        userGr = new GlideRecordSecure('sys_user');\n        var qc = null;\n        if(phone) {\n          qc = userGr.addQuery('phone', phone);\n          qc.addOrCondition('mobile_phone', phone);\n          qc.addOrCondition(\"home_phone\", phone);\n        }\n        if(username) {\n          if(qc) {\n            qc.addOrCondition('user_name', username);\n          } else {\n            qc = userGr.addQuery('user_name', username);\n          }\n        }\n        // If there was criteria then run the query\n        if(qc) {\n          userGr.query();\n        } else {\n          userGr = null;\n        }\n      }\n\t\t\t\n      var foundUser = userGr && userGr.next();\n\n      var phonelogGr = new GlideRecord('sn_openframe_phone_log');\n      phonelogGr.initialize();\n      phonelogGr.setValue('call_id', request.getParameter('contact.id'));\n      phonelogGr.setValue('phone_number', phone);\n      if(foundUser) {\n        phonelogGr.setValue('contact', userGr.getUniqueValue());\n      }\n      phonelogGr.insert();\n\t\t\t\n      var interactionGr = new GlideRecordSecure('interaction');\n      interactionGr.initialize();\n      interactionGr.setValue('type', 'phone');\n      interactionGr.setValue('short_description', 'User Contact via Phone: ' + phone);\n      interactionGr.setValue('channel_metadata_table', 'sn_openframe_phone_log');\n      interactionGr.setValue('channel_metadata_document',phonelogGr.getUniqueValue());\n\t\t\t\n      if(foundUser) {\n        interactionGr.setValue('opened_for', userGr.getUniqueValue());\n        response.setSessionAttribute('snc_user_first_name', userGr.getValue('first_name'));\n        response.setSessionAttribute('snc_user_last_name', userGr.getValue('last_name'));\n        response.setSessionAttribute('snc_user_sys_id', userGr.getUniqueValue());\n      } else {\n        response.setSessionAttribute('snc_user_sys_id', \"USER_NOT_FOUND\");\n      }\n      interactionGr.setValue('state', 'new');\n\n      var interactionId = interactionGr.insert();\n\n      response.setStatusCode(200);\n      response.setMessage('success');\n      response.setSessionAttribute('interactionTable', 'interaction');\n      response.setSessionAttribute('interactionId', interactionId);\n\n    }\n  } catch(e) {\n    ctx.setError(e);\n  }\n\n})(request, response);\n```\n\nFor additional information on creating operation handlers, see [Configure a contact flow for an automated caller interaction](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/establish-automated-bot-interactions.md).\n\nThe 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.\n\n```\n(function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {\n\t// AWS Connect Lambda expects name value pairs only\n\tvar out = {};\n\tfor(var k in operationResponse.getSessionAttributes()) {\n\t\tout[k] = operationResponse.getSessionAttributes()[k];\n\t}\n\tout.statusCode = operationResponse.getStatusCode();\n\tout.message = operationResponse.getMessage();\n\thttpResponse.setBody(out);\n})(operationResponse, httpResponse);\n```\n\nThis 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/install-ccc-apps.md).\n\nFor additional information on the ServiceNow Voice, see [ServiceNow Voice](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/cloud-call-center-overview.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## CTIOperationResponse - CTIOperationResponse\\(String origin\\)\n\nInstantiates a CTIOperationResponse object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nresponse.setMinorVersion(3);\n```\n\n## CTIOperationResponse - getAuthToken\\(\\)\n\nReturns the authentication token that was set on the CTIOperationResponse object.\n\nThis 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.\n\nYou 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.\n\nIf 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.\n\n**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.\n\nThe 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:\n\n-   Amazon Web Services \\(AWS\\) Lambda Proxy \\(Invoke AWS Lambda function\\)\n-   AWS Lex Bot \\(Get Customer Input\\)\n\nYou 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The authentication token previously set on the CTIOperationRequest object. If not set, returns null.|\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nvar token = response.getAuthToken();\n```\n\n## CTIOperationResponse - getError\\(\\)\n\nReturns the error object associated with the current CTIOperationResponse object.\n\nYou might use this information to formulate the payload returned to the computer telephony integration \\(CTI\\) provider.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|Operation error information. The format of this object is determined by the CTI provider. If an error does not exist, returns null.|\n\n```\n(function( /*CTIProviderResponseExecutionContext*/ ctx, /*CTIOperationRequest*/ operationRequest, /*CTIOperationResponse*/ operationResponse, /*HTTPResponse*/ httpResponse) {\n    var sessionAttributes = {},\n        intentResponse;\n    var statusCode = -1;\n    var message = 'Unprocessed';\n    if (operationResponse) {\n        statusCode = operationResponse.getStatusCode();\n        sessionAttributes = operationResponse.getSessionAttributes();\n        message = operationResponse.getMessage();\n        var error = operationResponse.getError();\n        if (error) {\n            sessionAttributes.error = error;\n        }\n    }\n    if (sn_cti_core.CTIRequestDispatcher.Constants.HTTP.Status.AUTH_REQUIRED.code === statusCode) {\n        //first call for a secure action without authentication token\n        sessionAttributes.statusCode = 401;\n        sessionAttributes.message = message;\n        intentResponse = {\n            sessionAttributes: sessionAttributes,\n            dialogAction: {\n                type: 'Close',\n                fulfillmentState: 'Fulfilled',\n                message: {\n                    contentType: 'PlainText',\n                    content: 'This operation requires authentication. Say authenticate for authentication.'\n                }\n            }\n        };\n    } else if ('DialogCodeHook' === operationRequest.getParameter('$$invocationSource')) {\n        //pass back authToken and interactionId\n        sessionAttributes.authToken = operationRequest.getAuthToken();\n        sessionAttributes.interactionId = operationRequest.getInteractionSysId();\n\t\tvar originalSlots = operationRequest.getParameter('$$slots');\n        var responseParameters = operationResponse ? operationResponse.getParameters() : {};\n        responseParameters = responseParameters ? responseParameters : {};\n        // See if we processing happened and we got a dialogAction\n\t\tvar responseDialogAction = responseParameters['dialogAction'];\n\t\t// Default dialog action\n        var dialogAction = {\n            type: 'Delegate',\n            slots: originalSlots\n        };\n\t\t// If the response doesn't contain an override replay the inputs\n        if (responseDialogAction) {\n            // We bypassed dialoghook so delegate and pass through inputs\n            dialogAction = responseDialogAction;\n        }\n        intentResponse = {\n            sessionAttributes: sessionAttributes,\n            dialogAction: dialogAction\n        };\n    } else {\n        // Override required session attributes\n        sessionAttributes.statusCode = statusCode;\n        sessionAttributes.message = message;\n        // Build response template\n        intentResponse = {\n            sessionAttributes: sessionAttributes,\n            dialogAction: {\n                type: 'Close',\n                fulfillmentState: 'Fulfilled',\n                message: {\n                    contentType: 'PlainText',\n                    content: message\n                }\n            }\n        };\n    }\n    httpResponse.setBody(intentResponse);\n})(ctx, operationRequest, operationResponse, httpResponse);\n```\n\n## CTIOperationResponse - getInteractionSysId\\(\\)\n\nReturns the sys\\_id of the interaction record associated with the call session that was set on the CTIOperationResponse object.\n\nThe [CTIOperationResponse - setInteractionSysId\\(String Id\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method must have been called prior to calling this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_djp_gpg_ykb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nSys\\_id of the interaction record set on the CTIOperationResponse object.If the interaction record sys\\_id is not set, the method returns null.\n\nTable: Interaction \\[interaction\\]\n\n</td></tr></tbody>\n</table>```\nvar request = new sn_cti_core.CTIOperationResponse();\nvar interactionId = request.getInteractionSysId();\n\n```\n\n## CTIOperationResponse - getMajorVersion\\(\\)\n\nReturns the major version of the computer telephony integrator \\(CTI\\) software set on the current CTIOperationResponse object.\n\nUse 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_plp_qvg_ykb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nNumber\n\n</td><td>\n\nMajor version number of the CTI software.If the major version was never set, returns `1`.\n\n</td></tr></tbody>\n</table>```\nvar request = new sn_cti_core.CTIOperationResponse();\nvar majorVersion = response.getMajorVersion();\n```\n\n## CTIOperationResponse - getMessage\\(\\)\n\nReturns the message string set on the current CTIOperationResponse object.\n\nTypically 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Message text. If no message exists, returns null.|\n\n```\n(function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {\n  // AWS Connect Lambda expects name value pairs only\n  var out = {};\n  for(var k in operationResponse.getSessionAttributes()) {\n    out[k] = operationResponse.getSessionAttributes()[k];\n  }\n  out.statusCode = operationResponse.getStatusCode();\n  out.message = operationResponse.getMessage();\n  httpResponse.setBody(out);\n})(operationResponse, httpResponse);\n```\n\n## CTIOperationResponse - getMinorVersion\\(\\)\n\nReturns the minor version of the computer telephony integrator \\(CTI\\) software set on the current CTIOperationResponse object.\n\nUse 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_dhp_z41_zkb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nNumber\n\n</td><td>\n\nMinor version number of the payload associated with this interaction.If the minor version was never set, returns `0`.\n\n</td></tr></tbody>\n</table>```\nvar request = new sn_cti_core.CTIOperationResponse();\nvar minorVersion = request.getMinorVersion();\n```\n\n## CTIOperationResponse - getParameter\\(String key\\)\n\nReturns the value of a specified key previously set on the current CTIOperationResponse object.\n\nUsing 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method to set parameters on the current CTIOperationResponse object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|The name of the key value to return.|\n\n|Type|Description|\n|----|-----------|\n|String|The value of the passed in key. If no such key exists, returns null.|\n\n```\nvar request = new sn_cti_core.CTIOperationResponse();\nvar parm = request.getParameter('contact.phone');\n```\n\n## CTIOperationResponse - getParameters\\(\\)\n\nReturns the key-value pairs for all parameters that were previously set on the current CTIOperationResponse object.\n\nUsing 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method to set parameters on the current CTIOperationResponse object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\n(function( /*CTIProviderResponseExecutionContext*/ ctx, /*CTIOperationRequest*/ operationRequest, /*CTIOperationResponse*/ operationResponse, /*HTTPResponse*/ httpResponse) {\n  var sessionAttributes = {},\n      intentResponse;\n  var statusCode = -1;\n  var message = 'Unprocessed';\n  if (operationResponse) {\n    statusCode = operationResponse.getStatusCode();\n    sessionAttributes = operationResponse.getSessionAttributes();\n    message = operationResponse.getMessage();\n    var error = operationResponse.getError();\n    if (error) {\n      sessionAttributes.error = error;\n    }\n  }\n  if (sn_cti_core.CTIRequestDispatcher.Constants.HTTP.Status.AUTH_REQUIRED.code === statusCode) {\n    //first call for a secure action without authentication token\n    sessionAttributes.statusCode = 401;\n    sessionAttributes.message = message;\n    intentResponse = {\n      sessionAttributes: sessionAttributes,\n      dialogAction: {\n        type: 'Close',\n        fulfillmentState: 'Fulfilled',\n        message: {\n          contentType: 'PlainText',\n          content: 'This operation requires authentication. Say authenticate for authentication.'\n        }\n      }\n    };\n  } else if ('DialogCodeHook' === operationRequest.getParameter('$$invocationSource')) {\n      //pass back authToken and interactionId\n      sessionAttributes.authToken = operationRequest.getAuthToken();\n      sessionAttributes.interactionId = operationRequest.getInteractionSysId();\n      var originalSlots = operationRequest.getParameter('$$slots');\n      var responseParameters = operationResponse ? operationResponse.getParameters() : {};\n      responseParameters = responseParameters ? responseParameters : {};\n      // See if processing happened and we got a dialogAction\n      var responseDialogAction = responseParameters['dialogAction'];\n      // Default dialog action\n      var dialogAction = {\n        type: 'Delegate',\n        slots: originalSlots\n      };\n      // If the response doesn't contain an override replay the inputs\n      if (responseDialogAction) {\n        // We bypassed dialoghook so delegate and pass through inputs\n        dialogAction = responseDialogAction;\n      }\n        intentResponse = {\n            sessionAttributes: sessionAttributes,\n            dialogAction: dialogAction\n        };\n    } else {\n      // Override required session attributes\n      sessionAttributes.statusCode = statusCode;\n      sessionAttributes.message = message;\n      // Build response template\n      intentResponse = {\n        sessionAttributes: sessionAttributes,\n        dialogAction: {\n          type: 'Close',\n          fulfillmentState: 'Fulfilled',\n          message: {\n            contentType: 'PlainText',\n            content: message\n          }\n        }\n      };\n  }\n  httpResponse.setBody(intentResponse);\n})(ctx, operationRequest, operationResponse, httpResponse);\n```\n\n## CTIOperationResponse - getSessionAttribute\\(String key\\)\n\nReturns the value for a specified session attribute key set on the current CTIOperationResponse object.\n\nUsing 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method and the message transformer consumes the attributes using this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|The name of the key value to return.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the passed in key. If no such key exists, returns null.|\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nvar phoneAttribute = response.getSessionAttribute('contact.phone');\n```\n\n## CTIOperationResponse - getSessionAttributes\\(\\)\n\nReturns the key-value pairs for all session attributes that were previously set on the current CTIOperationResponse object.\n\nUsing 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method and the message transformer consumes the attributes using this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\n(function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {\n  // AWS Connect Lambda expects name value pairs only\n  var out = {};\n  for(var k in operationResponse.getSessionAttributes()) {\n    out[k] = operationResponse.getSessionAttributes()[k];\n  }\n  out.statusCode = operationResponse.getStatusCode();\n  out.message = operationResponse.getMessage();\n  httpResponse.setBody(out);\n})(operationResponse, httpResponse);\n```\n\n## CTIOperationResponse - getStatusCode\\(\\)\n\nReturns the status code set on the current CTIOperationResponse object.\n\nThese 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method. The message transformer then uses this method to include the status code in the payload returned to the computer telephony integrator provider.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|Status code of the current operation. If a status code has not been set, returns -1.|\n\n```\n(function (/*CTIOperationResponse*/operationResponse, /*HTTPResponse*/ httpResponse) {\n  // AWS Connect Lambda expects name value pairs only\n  var out = {};\n  for(var k in operationResponse.getSessionAttributes()) {\n    out[k] = operationResponse.getSessionAttributes()[k];\n  }\n  out.statusCode = operationResponse.getStatusCode();\n  out.message = operationResponse.getMessage();\n  httpResponse.setBody(out);\n})(operationResponse, httpResponse);\n```\n\n## CTIOperationResponse - setAuthToken\\(String token\\)\n\nSets an authentication token on the current CTIOperationResponse object.\n\nThis 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.\n\nYou 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.\n\nIf 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.\n\n**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.\n\nThe 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:\n\n-   Amazon Web Services \\(AWS\\) Lambda Proxy \\(Invoke AWS Lambda function\\)\n-   AWS Lex Bot \\(Get Customer Input\\)\n\nYou 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The authentication token to use to authenticate operations that have the **auth\\_required** flag set.|\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nvar authenticate = <Your authentication code here>; // Authenticate the user\nif (authenticated) {\n\tvar claims = {\n\t\t\"interactionId\":interactionGr.sys_id.toString()\n\t};\n\tvar jwt = new sn_cti_core.AuthHelpers().generateJWT(claims);\n\tresponse.setAuthToken(jwt);\n}\n```\n\n## CTIOperationResponse - setError\\(Object error\\)\n\nSets the error object in the current CTIOperationResponse object.\n\nYou can use the error object in the component to formulate the payload to send to the computer telephony integrator \\(CTI\\) provider.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nresponse.setError(new Error(\"You did not supply a field\"));\n```\n\n## CTIOperationResponse - setInteractionSysId\\(String Id\\)\n\nSets the sys\\_id of the interaction record associated with the operation request on the current CTIOperationResponse object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|sys\\_id|String|The sys\\_id to set for the current interaction.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nresponse.setInteractionSysId('98529cc55380001048e5ddeeff7b120b');\n\n```\n\n## CTIOperationResponse - setMajorVersion\\(Number majorVersion\\)\n\nSets the major version of the computer telephony integrator \\(CTI\\) provider software making the request on the associated CTIOperationResponse object.\n\nUse 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.\n\n<table id=\"table_jlt_pz1_zkb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nmajorVersion\n\n</td><td>\n\nNumber\n\n</td><td>\n\nMajor version of the CTI provider software making the operation request.If this value was not previously set, returns `1`.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar request = new sn_cti_core.CTIOperationResponse();\nrequest.setMajorVersion(2);\n```\n\n## CTIOperationResponse - setMessage\\(String message\\)\n\nSets a text message on the current CTIOperationResponse object.\n\nTypically 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method to obtain the message and pass it back to the computer telephony integration provider.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Message text|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n(function(/*CTIOperationRequest*/ request, /*CTIOperationResponse*/ response, /*Context*/ ctx) {\t\n  var notes = '', lang = request.getLanguage();\n  try { \n\t\t\n    var interactionGr = request.getInteractionRecord();\n\n    var now_GR = new GlideRecord('sys_user');\n    if(interactionGr && now_GR.get(interactionGr.opened_for.toString())) {\t\n    if(now_GR.locked_out == true) {\n        notes += gs.getMessageLang(\"User record found locked. Unlocking the account.\\n\", lang);\n        now_GR.locked_out=false;\n        now_GR.update();\n        response.setStatusCode(200);\n        response.setMessage(gs.getMessageLang(\"Your account has been unlocked.\", lang));\n      } else {\n        notes += gs.getMessageLang(\"User record not locked.\\n\", lang);\n        response.setStatusCode(200);\n        response.setMessage(gs.getMessageLang(\"Your account doesn't seem to be locked.\", lang));\n      }\t\n    } else {\n      notes += gs.getMessageLang(\"User record not found. Transfer to agent\\n\", lang);\n      response.setStatusCode(302);\n      response.setMessage(gs.getMessageLang(\"I am unable to find your record. Let me transfer to someone who can help.\", lang));\n    }\n    if(interactionGr) {\n      interactionGr.work_notes = notes;\n      interactionGr.update();\n    }\n  } catch(e) {\n    ctx.setError(e);\n  }\n})(request, response, ctx);\n```\n\n## CTIOperationResponse - setMinorVersion\\(Number minorVersion\\)\n\nSets the minor version of the computer telephony integrator \\(CTI\\) provider software making the request on the associated CTIOperationResponse object.\n\nUse 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.\n\n<table id=\"table_zqj_52b_zkb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nminorVersion\n\n</td><td>\n\nNumber\n\n</td><td>\n\nMinor version of the CTI provider software making the operation request.If this value was not previously set, returns `0`.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nresponse.setMinorVersion(3);\n```\n\n## CTIOperationResponse - setParameter\\(String key, Object value\\)\n\nSets the specified key-value pair on the associated CTIOperationResponse object.\n\nUsing 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) or [CTIOperationResponse - getSParameters\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method.\n\n**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.\n\nFor example:\n\n```\nvar x = {\n  \"string\": 'abc',\n  \"int\": 123,\n  \"float\": 1.234,\n  \"number\": new Number(3),\n  \"boolean\": true,\n  \"date\": new Date(2006, 0, 2, 15, 4, 5),\n  \"object\": {\n    \"string\": 'abc',\n    \"int\": 123,\n    \"float\": 1.234,\n    \"number\": new Number(3),\n    \"boolean\": true,\n    \"date\": new Date(2006, 0, 2, 15, 4, 5)\n  },\n  \"function\": function(abc) {\n\n  }\n}\nvar stringify = JSON.stringify(x);\ngs.info(stringify);\nvar hydrate = JSON.parse(stringify);\nvar stringify2 = JSON.stringify(hydrate);\ngs.info(stringify2);\n\n```\n\nProduces:\n\n```\n{\"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\"}}\n{\"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\"}}\n\n```\n\n<table id=\"table_ab4_k3r_zkb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nkey\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the key under which to store the associated value.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue to store for the key.Valid data types:\n\n-   string\n-   int\n-   float\n-   number\n-   boolean\n-   date\n-   object\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nresponse.setParameter('contact.phone', '+15552222345');\nresponse.setParameter('contact.okToCall', true);\nresponse.setParameter('contact.address', {\n    street: '1234 Main St'\n    city: 'API City',\n    zip: 91335\n});\n```\n\n## CTIOperationResponse - setSessionAttribute\\(String key, Object value\\)\n\nSets the specified session attribute key-value pair on the associated CTIOperationResponse object.\n\nUsing 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) or [CTIOperationResponse - getSessionAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CTIOperationResponseAPI.md) method.\n\n**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.\n\nFor example:\n\n```\nvar x = {\n  \"string\": 'abc',\n  \"int\": 123,\n  \"float\": 1.234,\n  \"number\": new Number(3),\n  \"boolean\": true,\n  \"date\": new Date(2006, 0, 2, 15, 4, 5),\n  \"object\": {\n    \"string\": 'abc',\n    \"int\": 123,\n    \"float\": 1.234,\n    \"number\": new Number(3),\n    \"boolean\": true,\n    \"date\": new Date(2006, 0, 2, 15, 4, 5)\n  },\n  \"function\": function(abc) {\n\n  }\n}\nvar stringify = JSON.stringify(x);\ngs.info(stringify);\nvar hydrate = JSON.parse(stringify);\nvar stringify2 = JSON.stringify(hydrate);\ngs.info(stringify2);\n\n```\n\nProduces:\n\n```\n{\"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\"}}\n{\"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\"}}\n\n```\n\n<table id=\"table_ihm_rxr_zkb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nkey\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the session attribute key under which to set the associated value.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue to set.Valid data types:\n\n-   string\n-   int\n-   float\n-   number\n-   boolean\n-   date\n-   object\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar response = new sn_cti_core.CTIOperationResponse();\nresponse.setSessionAttribute('contact.phone', '+15552222345');\nresponse.setSessionAttribute('contact.okToCall', true);\nresponse.setSessionAttribute('contact.address', {\n    street: '1234 Main St'\n    city: 'API City',\n    zip: 91335\n});\n```\n\n## CTIOperationResponse - setStatusCode\\(Number statusCode\\)\n\nSets the status code of the current operation request on the CTIOperationResponse object.\n\nYou 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|statusCode|Number|Integer that uniquely identifies the status of the requested operation.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n(function(/*CTIOperationRequest*/ request, /*CTIOperationResponse*/ response, /*Context*/ ctx) {\t\n  var notes = '', lang = request.getLanguage();\n  try { \n\t\t\n    var interactionGr = request.getInteractionRecord();\n\n    var now_GR = new GlideRecord('sys_user');\n    if(interactionGr && now_GR.get(interactionGr.opened_for.toString())) {\t\n    if(now_GR.locked_out == true) {\n        notes += gs.getMessageLang(\"User record found locked. Unlocking the account.\\n\", lang);\n        now_GR.locked_out=false;\n        now_GR.update();\n        response.setStatusCode(200);\n        response.setMessage(gs.getMessageLang(\"Your account has been unlocked.\", lang));\n      } else {\n        notes += gs.getMessageLang(\"User record not locked.\\n\", lang);\n        response.setStatusCode(200);\n        response.setMessage(gs.getMessageLang(\"Your account doesn't seem to be locked.\", lang));\n      }\t\n    } else {\n      notes += gs.getMessageLang(\"User record not found. Transfer to agent\\n\", lang);\n      response.setStatusCode(302);\n      response.setMessage(gs.getMessageLang(\"I am unable to find your record. Let me transfer to someone who can help.\", lang));\n    }\n    if(interactionGr) {\n      interactionGr.work_notes = notes;\n      interactionGr.update();\n    }\n  } catch(e) {\n    ctx.setError(e);\n  }\n})(request, response, ctx);\n```\n\n"}}