CTIOperationResponse:スコープ、グローバル
CTIOperationResponse スクリプトインクルードは、現在の CTIOperationResponse オブジェクトでデータを設定および取得するためのメソッドを提供します。
CTIOperationResponse オブジェクトを使用して、 ServiceNow 音声アシスト機能 フレームワーク内の操作ハンドラーとメッセージトランスフォーマーの間で情報を渡します。
通常、操作ハンドラーは、関連する要求を処理するときに CTIOperationResponse オブジェクトに値を設定します。次に、メッセージトランスフォーマーは、CTIOperationRequest オブジェクトから値を取得し、コンピューター電話インテグレーター (CTI) プロバイダーに送り返される CTI 固有のペイロードをビルドします。
- Amazon Web サービス (AWS) Lambda プロキシ (AWS Lambda 関数を呼び出す)
- AWS Lex ボット (顧客入力を取得)
次の操作ハンドラースクリプトは、さまざまな CTIOperationResponse メソッドを使用して CTIOperationResponse オブジェクトに値を設定する方法を示しています。
(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);操作ハンドラーの作成の詳細については、「 自動発信者インタラクションの連絡先フローの構成」を参照してください。
次のメッセージトランスフォーマースクリプトは、CTIOperationResponse オブジェクトに設定された値を取得し、CTI 固有のペイロードに格納して、CTI プロバイダーに送り返します。
(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);このスクリプトインクルードは、 sn_cti_core 名前空間で実行されます。CTIOperationRequest スクリプトインクルードにアクセスする前に、ServiceNow 音声アシスト機能 Core (sn_cti_core) プラグインをインストールする必要があります。インストールの詳細については、「 ServiceNow 音声アシスト機能アプリケーションのインストール」を参照してください。
ServiceNow 音声アシスト機能の詳細については、「ServiceNow 音声アシスト機能」を参照してください。
CTIOperationResponse:CTIOperationResponse(文字列作成元)
CTIOperationResponse オブジェクトをインスタンス化します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
var response = new sn_cti_core.CTIOperationResponse();
response.setMinorVersion(3);
CTIOperationResponse:getAuthToken()
CTIOperationResponse オブジェクトに設定された認証トークンを返します。
このトークンは、ハンドラーのauth_requiredフラグが true に設定されている場合、要求された操作ハンドラーを実行する前に現在のServiceNow 音声アシスト機能ユーザーを認証するためにServiceNow 音声アシスト機能フレームワークによって使用されます。auth_requiredフラグは、操作ハンドラー [sn_cti_operation_handler] テーブルのフィールドです。認証トークンの有効期間はコールセッションの有効期間である必要がありますが、CTI プロバイダーによって決定されます。
独自の認証操作ハンドラーを作成することで、実装に必要な認証/承認処理を定義できます。認証トークンの生成方法に関係なく、メッセージ翻訳ツールは CTI ペイロードでトークンを渡す必要があります。さらに、CTI プロバイダーはこの認証トークンをローカルに保存し、認証を必要とする各操作要求で渡す必要があります。
インスタンス提供の認証操作ハンドラーを使用する場合、ハンドラーはユーザーが入力した 4 桁の PIN に基づいて認証トークンの作成を開始します。次に、CTIOperationResponse オブジェクトの sessionAttributes オブジェクトに認証トークンを設定します。関連付けられたメッセージトランスフォーマーは、sessionAttributes オブジェクトを CTI 固有のペイロードに変換し、CTI プロバイダーに送信します。
- Amazon Web サービス (AWS) Lambda プロキシ (AWS Lambda 関数を呼び出す)
- AWS Lex ボット (顧客入力を取得)
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | CTIOperationRequest オブジェクトに以前に設定された認証トークン。設定されていない場合は null を返します。 |
var response = new sn_cti_core.CTIOperationResponse();
var token = response.getAuthToken();
CTIOperationResponse:getError()
現在の CTIOperationResponse オブジェクトに関連付けられたエラーオブジェクトを返します。
この情報を使用して、コンピューター電話統合 (CTI) プロバイダーに返されるペイロードを作成できます。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| オブジェクト | 操作エラー情報。このオブジェクトの形式は、CTI プロバイダーによって決定されます。エラーが存在しない場合は、null を返します。 |
(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()
CTIOperationResponse オブジェクトに設定されたコールセッションに関連付けられたインタラクションレコードのsys_idを返します。
CTIOperationResponse - setInteractionSysId(String Id) メソッドは、このメソッドを呼び出す前に呼び出されている必要があります。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | CTIOperationResponse オブジェクトに設定されたインタラクションレコードのSys_id。 インタラクションレコードsys_idが設定されていない場合、このメソッドは null を返します。 テーブル:インタラクション [interaction] |
var request = new sn_cti_core.CTIOperationResponse();
var interactionId = request.getInteractionSysId();
CTIOperationResponse:getMajorVersion()
現在の CTIOperationResponse オブジェクトに設定されているコンピューター電話インテグレーター (CTI) ソフトウェアのメジャーバージョンを返します。
ServiceNow インスタンスに接続されている CTI プロバイダーが複数のバージョンのソフトウェアを実行している場合は、ソフトウェアバージョンによって異なるペイロードが必要になる可能性があるため、この方法を使用します。ペイロードがソフトウェアのバージョン間でわずかに異なるだけの場合は、メッセージトランスフォーマーを 1 つだけ使用することが理にかなっている場合があります。その後、メッセージトランスフォーマー内で要求を行うソフトウェアのバージョンを確認するだけで、ペイロードの違いを処理できます。必要なペイロードがバージョン間で大きく異なる場合は、複数のメッセージトランスフォーマーを使用する方が効果的な場合があります。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 番号 | CTI ソフトウェアのメジャーバージョン番号。 メジャーバージョンが設定されていない場合は、 1 を返します。 |
var request = new sn_cti_core.CTIOperationResponse();
var majorVersion = response.getMajorVersion();
CTIOperationResponse:getMessage()
現在の CTIOperationResponse オブジェクトに設定されたメッセージ文字列を返します。
通常、これは操作が完了した後にユーザーに読み上げられるメッセージです。この値は、 CTIOperationResponse - setMessage(String message) メソッドを使用して設定できます。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | メッセージテキスト。メッセージが存在しない場合は null を返します。 |
(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()
現在の CTIOperationResponse オブジェクトに設定されているコンピューター電話インテグレーター (CTI) ソフトウェアのマイナーバージョンを返します。
ServiceNow インスタンスに接続されている CTI プロバイダーが複数のバージョンのソフトウェアを実行している場合は、ソフトウェアバージョンによって異なるペイロードが必要になる可能性があるため、この方法を使用します。ペイロードがソフトウェアのバージョン間でわずかに異なるだけの場合は、メッセージトランスフォーマーを 1 つだけ使用することが理にかなっている場合があります。その後、メッセージトランスフォーマー内で要求を行うソフトウェアのバージョンを確認するだけで、ペイロードの違いを処理できます。必要なペイロードがバージョン間で大きく異なる場合は、複数のメッセージトランスフォーマーを使用する方が効果的な場合があります。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 番号 | このインタラクションに関連付けられたペイロードのマイナーバージョン番号。 マイナーバージョンが設定されていない場合は、 0 を返します。 |
var request = new sn_cti_core.CTIOperationResponse();
var minorVersion = request.getMinorVersion();
CTIOperationResponse:getParameter(文字列キー)
現在の CTIOperationResponse オブジェクトに以前に設定された指定されたキーの値を返します。
get/set パラメーターメソッドを使用すると、操作ハンドラーとメッセージトランスフォーマーの間でほぼすべての文字列または数値を渡すことができます。パラメーターオブジェクトには、現在の操作応答に直接関連する 0 個以上のデータのキーと値のペアを含めることができます。操作ハンドラーは、これらの値を生成するときに必要なキー/値ペアを決定します。CTIOperationResponse - setParameter(String key, Object value) メソッドを使用して、現在の CTIOperationResponse オブジェクトにパラメーターを設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| キー | 文字列 | 返すキー値の名前。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 渡されたキーの値。そのようなキーが存在しない場合は、null を返します。 |
var request = new sn_cti_core.CTIOperationResponse();
var parm = request.getParameter('contact.phone');
CTIOperationResponse:getParameters()
現在の CTIOperationResponse オブジェクトで以前に設定されたすべてのパラメーターのキーと値のペアを返します。
get/set パラメーターメソッドを使用すると、操作ハンドラーとメッセージトランスフォーマーの間でほぼすべての文字列または数値を渡すことができます。パラメーターオブジェクトには、現在の操作応答に直接関連する 0 個以上のデータのキーと値のペアを含めることができます。操作ハンドラーは、これらの値を生成するときに必要なキー/値ペアを決定します。CTIOperationResponse - setParameter(String key, Object value) メソッドを使用して、現在の CTIOperationResponse オブジェクトにパラメーターを設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| オブジェクト | CTIOperationResponse オブジェクトに以前に設定されたキーと値のペアのマップ。このキーと値のペアは自由形式で、操作ハンドラーのニーズによって定義されます。戻り値は文字列または数値です。 |
(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(文字列キー)
現在の CTIOperationResponse オブジェクトに設定されている指定されたセッション属性キーの値を返します。
get/set セッション属性メソッドを使用すると、操作ハンドラーとメッセージトランスフォーマーの間でほぼすべての文字列または数値を渡すことができます。セッション属性には、連絡先フロー内でもアクセスできます。sessionAttribute オブジェクトには、コンピューター電話統合プロバイダーによって定義されたセッションの期間中有効な、連絡先の電話番号などのデータのキー/値ペアを 0 個以上含めることができます。操作ハンドラーは、処理中にこれらの値を使用するときに必要なセッション属性キー/値ペアを決定します。通常、操作ハンドラーは CTIOperationResponse - setSessionAttribute(String key, Object value) メソッドを呼び出して CTIOperationResponse オブジェクトにこれらの属性を設定し、メッセージトランスフォーマーはこのメソッドを使用して属性を消費します。
| 名前 | タイプ | 説明 |
|---|---|---|
| キー | 文字列 | 返すキー値の名前。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 渡されたキーの値。そのようなキーが存在しない場合は、null を返します。 |
var response = new sn_cti_core.CTIOperationResponse();
var phoneAttribute = response.getSessionAttribute('contact.phone');
CTIOperationResponse:getSessionAttributes()
現在の CTIOperationResponse オブジェクトに以前に設定されたすべてのセッション属性のキーと値のペアを返します。
get/set セッション属性メソッドを使用すると、操作ハンドラーとメッセージトランスフォーマーの間でほぼすべての文字列または数値を渡すことができます。セッション属性には、連絡先フロー内でもアクセスできます。sessionAttribute オブジェクトには、コンピューター電話統合プロバイダーによって定義されたセッションの期間中有効な、連絡先の電話番号などのデータのキー/値ペアを 0 個以上含めることができます。操作ハンドラーは、処理中にこれらの値を使用するときに必要なセッション属性キー/値ペアを決定します。通常、操作ハンドラーは CTIOperationResponse - setSessionAttribute(String key, Object value) メソッドを呼び出して CTIOperationResponse オブジェクトにこれらの属性を設定し、メッセージトランスフォーマーはこのメソッドを使用して属性を消費します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| オブジェクト | CTIOperationResponse オブジェクトに以前に設定されたキーと値のペアのマップ。このキーと値のペアは自由形式で、操作ハンドラーのニーズによって定義されます。戻り値は文字列または数値です。 |
(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()
現在の CTIOperationResponse オブジェクトに設定されたステータスコードを返します。
これらのステータスコードは、標準の HTTP ステータスコード (成功の場合は 200、認証が必要な場合は 401 など) に対応する必要があります。通常、結果のステータスコードは操作ハンドラーによって決定され、 CTIOperationResponse - setStatusCode(String statusCode) メソッドを使用して CTIOperationResponse オブジェクトに設定されます。次に、メッセージトランスフォーマーはこのメソッドを使用して、コンピューター電話インテグレータープロバイダーに返されるペイロードにステータスコードを含めます。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 番号 | 現在の操作のステータスコード。ステータスコードが設定されていない場合は、-1 を返します。 |
(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(文字列トークン)
現在の CTIOperationResponse オブジェクトに認証トークンを設定します。
このトークンは、ハンドラーのauth_requiredフラグが true に設定されている場合、要求された操作ハンドラーを実行する前に現在のServiceNow 音声アシスト機能ユーザーを認証するためにServiceNow 音声アシスト機能フレームワークによって使用されます。auth_requiredフラグは、操作ハンドラー [sn_cti_operation_handler] テーブルのフィールドです。認証トークンの有効期間はコールセッションの有効期間である必要がありますが、CTI プロバイダーによって決定されます。
独自の認証操作ハンドラーを作成することで、実装に必要な認証/承認処理を定義できます。認証トークンの生成方法に関係なく、メッセージ翻訳ツールは CTI ペイロードでトークンを渡す必要があります。さらに、CTI プロバイダーはこの認証トークンをローカルに保存し、認証を必要とする各操作要求で渡す必要があります。
インスタンス提供の認証操作ハンドラーを使用する場合、ハンドラーはユーザーが入力した 4 桁の PIN に基づいて認証トークンの作成を開始します。次に、CTIOperationResponse オブジェクトの sessionAttributes オブジェクトに認証トークンを設定します。関連付けられたメッセージトランスフォーマーは、sessionAttributes オブジェクトを CTI 固有のペイロードに変換し、CTI プロバイダーに送信します。
- Amazon Web サービス (AWS) Lambda プロキシ (AWS Lambda 関数を呼び出す)
- AWS Lex ボット (顧客入力を取得)
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | auth_requiredフラグが設定されている操作を認証するために使用する認証トークン。 |
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(オブジェクトエラー)
現在の CTIOperationResponse オブジェクトにエラーオブジェクトを設定します。
コンポーネントのエラーオブジェクトを使用して、コンピューター電話インテグレーター (CTI) プロバイダーに送信するペイロードを作成できます。
| 名前 | タイプ | 説明 |
|---|---|---|
| エラー | オブジェクト | 要求された操作の処理中に検出されたエラーに関する情報。このオブジェクトの形式は、CTI プロバイダーによって決定されます。 |
| タイプ | 説明 |
|---|---|
| なし |
var response = new sn_cti_core.CTIOperationResponse();
response.setError(new Error("You did not supply a field"));
CTIOperationResponse:setInteractionSysId(文字列 ID)
現在の CTIOperationResponse オブジェクトの操作要求に関連付けられたインタラクションレコードのsys_idを設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| sys_id | 文字列 | 現在のインタラクションに設定するsys_id。 |
| タイプ | 説明 |
|---|---|
| なし |
var response = new sn_cti_core.CTIOperationResponse();
response.setInteractionSysId('98529cc55380001048e5ddeeff7b120b');
CTIOperationResponse:setMajorVersion(番号 majorVersion)
関連する CTIOperationResponse オブジェクトで要求を行うコンピューター電話インテグレーター (CTI) プロバイダーソフトウェアのメジャーバージョンを設定します。
ServiceNow インスタンスに接続されている CTI プロバイダーが複数のバージョンのソフトウェアを実行している場合は、ソフトウェアバージョンによって異なるペイロードが必要になる可能性があるため、この方法を使用します。ペイロードがソフトウェアのバージョン間でわずかに異なるだけの場合は、メッセージトランスフォーマーを 1 つだけ使用することが理にかなっている場合があります。その後、メッセージトランスフォーマー内で要求を行うソフトウェアのバージョンを確認するだけで、ペイロードの違いを処理できます。必要なペイロードがバージョン間で大きく異なる場合は、複数のメッセージトランスフォーマーを使用する方が効果的な場合があります。
| 名前 | タイプ | 説明 |
|---|---|---|
| majorVersion | 番号 | 操作要求を行う CTI プロバイダーソフトウェアのメジャーバージョン。 この値が以前に設定されていない場合は、 1 を返します。 |
| タイプ | 説明 |
|---|---|
| なし |
var request = new sn_cti_core.CTIOperationResponse();
request.setMajorVersion(2);
CTIOperationResponse:setMessage(文字列メッセージ)
現在の CTIOperationResponse オブジェクトにテキストメッセージを設定します。
通常、これは操作の完了後にユーザーに読み返されるメッセージで、関連付けられた操作ハンドラーによって設定されます。次に、メッセージトランスフォーマーは CTIOperationResponse - getMessage() メソッドを使用してメッセージを取得し、コンピューター電話統合プロバイダーに返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| メッセージ | 文字列 | メッセージテキスト |
| タイプ | 説明 |
|---|---|
| なし |
(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(番号 minorVersion)
関連する CTIOperationResponse オブジェクトで要求を行うコンピューター電話インテグレーター (CTI) プロバイダーソフトウェアのマイナーバージョンを設定します。
ServiceNow インスタンスに接続されている CTI プロバイダーが複数のバージョンのソフトウェアを実行している場合は、ソフトウェアバージョンによって異なるペイロードが必要になる可能性があるため、この方法を使用します。ペイロードがソフトウェアのバージョン間でわずかに異なるだけの場合は、メッセージトランスフォーマーを 1 つだけ使用することが理にかなっている場合があります。その後、メッセージトランスフォーマー内で要求を行うソフトウェアのバージョンを確認するだけで、ペイロードの違いを処理できます。必要なペイロードがバージョン間で大きく異なる場合は、複数のメッセージトランスフォーマーを使用する方が効果的な場合があります。
| 名前 | タイプ | 説明 |
|---|---|---|
| minorVersion | 番号 | 操作要求を行う CTI プロバイダーソフトウェアのマイナーバージョン。 この値が以前に設定されていない場合は、 0 を返します。 |
| タイプ | 説明 |
|---|---|
| なし |
var response = new sn_cti_core.CTIOperationResponse();
response.setMinorVersion(3);
CTIOperationResponse - setParameter(文字列キー, オブジェクト値)
関連する CTIOperationResponse オブジェクトに指定されたキーと値のペアを設定します。
get/set パラメーターメソッドを使用すると、操作ハンドラーとメッセージトランスフォーマーの間でほぼすべての文字列または数値を渡すことができます。パラメーターオブジェクトには、現在の操作要求に直接関連するデータの 0 個以上のキーと値のペアを含めることができます。操作ハンドラーは、これらの値を消費するときに必要なキー/値ペアを決定します。通常、操作ハンドラーはこのメソッドを呼び出して CTIOperationResponse オブジェクトにこれらのパラメーターを設定し、メッセージトランスフォーマーは CTIOperationResponse - getParmeter(String key) または CTIOperationResponse - getSParameters() メソッドを使用してそれらを消費します。
JSON.parse(JSON.stringify(object)) 操作を存続できるオブジェクトのみを格納する必要があります。この基準を満たさないオブジェクトは、操作処理チェーン全体に正しく伝達されない可能性があります。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);
{"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"}}
| 名前 | タイプ | 説明 |
|---|---|---|
| キー | 文字列 | 関連する値を格納するキーの名前。 |
| 値 | オブジェクト | キーに格納する値。 有効なデータタイプ:
|
| タイプ | 説明 |
|---|---|
| なし |
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(文字列キー, オブジェクト値)
関連付けられた CTIOperationResponse オブジェクトに指定されたセッション属性のキーと値のペアを設定します。
get/set セッション属性メソッドを使用すると、操作ハンドラーとメッセージトランスフォーマーの間でほぼすべての文字列または数値を渡すことができます。sessionAttribute オブジェクトには、コンピューター電話統合プロバイダーによって定義されたセッションの期間中有効なキー/値のペアが 0 個以上含められます。セッション属性には、連絡先フロー内でもアクセスできます。操作ハンドラーは、これらの値を消費するときに必要なセッション属性キー/値ペアを決定します。通常、操作ハンドラーはこのメソッドを呼び出して CTIOperationResponse オブジェクトにこれらの属性を設定し、メッセージトランスフォーマーは CTIOperationResponse - getSessionAttribute(String key) または CTIOperationResponse - getSessionAttribute() メソッドを使用して属性を取得します。
JSON.parse(JSON.stringify(object)) 操作を存続できるオブジェクトのみを格納する必要があります。この基準を満たさないオブジェクトは、操作処理チェーン全体に正しく伝達されない可能性があります。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);
{"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"}}
| 名前 | タイプ | 説明 |
|---|---|---|
| キー | 文字列 | 関連する値を設定するセッション属性キーの名前。 |
| 値 | オブジェクト | 設定する値。 有効なデータタイプ:
|
| タイプ | 説明 |
|---|---|
| なし |
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(数値 statusCode)
CTIOperationResponse オブジェクトに現在の操作要求のステータスコードを設定します。
任意の整数値を使用してステータスを定義できますが、200 = Ok/Success、400 = Bad Request、401 = Unauthorized などの HTTP ステータスコードをエミュレートすることをお勧めします。
| 名前 | タイプ | 説明 |
|---|---|---|
| statusCode | 番号 | 要求された操作のステータスを一意に識別する整数。 |
| タイプ | 説明 |
|---|---|
| なし |
(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);