ResponseTemplate - スコープ対象、グローバル
ResponseTemplate スクリプトインクルードは、応答テンプレートを管理するためのメソッドを提供します。
応答テンプレートは、エージェントがケースフォームまたはタスクフォームにコピーできる再利用可能なメッセージです。ユーザーに迅速かつ一貫性のあるメッセージを提供し、要求者には標準のチャット応答メッセージを エージェントチャットで表示します。 このスクリプトインクルードには、デフォルトでアクティブ化され、sn_templated_snip 名前空間内で実行されるテンプレート化された応答プラグイン ( com.sn_templated_snip ) が必要です。
応答テンプレートの詳細については、「 応答テンプレート」を参照してください。
ResponseTemplate:ResponseTemplate()
新しい ResponseTemplate オブジェクトをインスタンス化します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
new sn_templated_snip.ResponseTemplate().query("incident","ef4225a40a0a0b5700d0b8a790747812", "", 0, 0, true, "");
ResponseTemplate - query(String tableName, String recordId, String searchTerm, Number limit, Number offset, Boolean includeEvaluatedBody, String errorFormat, Object opts)
指定されたテーブルから、渡されたクエリクライテリアに一致するすべての応答テンプレートを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| tableName | 文字列 | sn_templated_snip_note_templateテーブルを検索して対応する応答テンプレートを見つけるために使用するテーブルの名前。たとえば、インシデントやsn_hr_core_caseなどです。 |
| recordId | 文字列 | 応答テンプレートで変数をレンダリングするために使用するレコードの Sys ID。 |
| searchTerm | 文字列 | オプション。一致する応答テンプレートのリストをフィルタリングするために使用するテキスト。 このメソッドは、name フィールドと body フィールドでこのテキストの CONTAINS 検索を実行し、短い名前フィールドで STARTS WITH 検索を実行します。たとえば、検索用語が「crash」の場合、このメソッドは、クエリ条件に一致し、名前または本文に crash が含まれているか、短縮名が crash で始まる任意の応答テンプレートを返します。 短い名前と完全に一致する応答テンプレートが、返される結果の最初に表示されます。返された他のすべての応答テンプレートは、名前順にソートされます。 デフォルト:一致するすべての応答テンプレートが返されます。 |
| 補償限度額 | 番号 | オプション。返す応答テンプレートの最大数。 デフォルト:50 |
| オフセット | 番号 | オプション。ページネーションの場合は、検索を開始するインデックス。 デフォルト:0 |
| includeEvaluatedBody | ブール | オプション。テンプレート変数を表示するかどうかを示すフラグ。 有効な値:
デフォルト値:false |
| errorFormat | 文字列 | オプション。エラーに使用する HTML 書式設定。 たとえば、次のようになります:
デフォルト値 |
| オプション | オブジェクト | オプション。sn_templated_snip.response_template 拡張ポイントに渡すパラメーター。これらのパラメーターの形式と内容は、拡張ポイントの実装によって異なります。拡張ポイントの詳細については、「 拡張ポイントを使用してアプリケーション機能を拡張する」を参照してください。 |
| タイプ | 説明 |
|---|---|
| オブジェクト | 指定された検索条件に一致するすべてのテンプレートのアレイ。短い名前と完全に一致する応答テンプレートが、返される結果の最初に表示されます。返された他のすべての応答テンプレートは、名前順にソートされます。 アレイ内の各ノードには、次のパラメーターを含めることができます。
|
この例では、インシデントテーブルに関連付けられた応答テンプレートをクエリする方法を示します。
query("incident","ef4225a40a0a0b5700d0b8a790747812", "", 0, 0, false, "");
成功した応答:
[
{
"sys_id": "5fc1d65993003300a9bc1d1e867ffb9c",
"name": "Incident escalation",
"short_name": "escalation",
"template_body": "<p>Dear ${caller_id.first_name},</p>\r\n<p>Please note that your incident ${number} has been escalated to ${assignment_group}. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>${sys_updated_by}</p>"
}
]
同じクエリでエラー応答があります。
query("incident","fe4225a40a0a0b5700d0b8a790747812", "", 0, 0, false, "");
エラー応答:
[
{
"sys_id": "5fc1d65993003300a9bc1d1e867ffb9c",
"name": "Incident escalation",
"short_name": "escalation",
"template_body": "<p>Dear ${caller.first_name},</p>\r\n<p>Please note that your incident ${number} has been escalated to ${assignment_group}. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>${sys_updated_by}</p>",
"evaluated_response": {
"success": false,
"error": {
"unEvaluatedVariables": "caller.first_name",
"message": "Cannot evaluate following variables: caller.first_name"
},
"evaluated_body": "<p>Dear <span style='color:#ff0000'>${caller.first_name}</span>,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}
}
]
ResponseTemplate - render(文字列 templateId, 文字列 tableName, 文字列 recordId, 文字列 errorFormat, オブジェクト opts)
指定された応答テンプレートの HTML 本文をレンダリングします。
レンダリング中、指定されたテーブルとレコードの情報を使用して、すべての変数が解決されます。変数を解決できない場合、またはレンダリング中にその他の問題が発生した場合、メソッドは結果にエラーメッセージを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| template_id | 文字列 | 表示する応答テンプレートの Sys ID。 |
| tableName | 文字列 | 応答テンプレートで変数をレンダリングするときに使用するテーブルの名前。 |
| recordId | 文字列 | 応答テンプレートで変数をレンダリングするときに使用するレコードの Sys ID。このレコードは、 tableName で指定されたテーブルに含まれている必要があります。 |
| errorFormat | 文字列 | オプション。エラーに使用する HTML 書式設定。 たとえば、次のようになります:
デフォルト値 |
| オプション | オブジェクト | オプション。sn_templated_snip.response_template 拡張ポイントに渡すパラメーター。これらのパラメーターの形式と内容は、拡張ポイントの実装によって異なります。拡張ポイントの詳細については、「 拡張ポイントを使用してアプリケーション機能を拡張する」を参照してください。 |
| タイプ | 説明 |
|---|---|
| オブジェクト | レンダリングの結果。
|
このコード例は、インシデントテーブルのレンダリングされた応答テンプレートを要求する方法を示しています。
render("5fc1d65993003300a9bc1d1e867ffb9c","incident","ef4225a40a0a0b5700d0b8a790747812", "")
成功した応答:
{
"success": true,
"evaluated_body": "<p>Dear Beth,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}
レンダリング要求は同じですが、エラー応答を返します。
render("5fc1d65993003300a9bc1d1e867ffb9c","incident","ef4225a40a0a0b5700d0b8a790747812", "")
エラー応答:
{
"success": false,
"error": {
"unEvaluatedVariables": "caller.first_name",
"message": "Cannot evaluate following variables: caller.first_name"
},
"evaluated_body": "<p>Dear <span style='color:#ff0000'>${caller.first_name}</span>,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}