Kebijakan ParseDialogflowRequest

Kebijakan yang dapat diperluas

Halaman ini berlaku untuk Apigee dan Apigee hybrid.

Lihat dokumentasi Apigee Edge.

Kebijakan ParseDialogflowRequest memfasilitasi integrasi Dialogflow dengan Apigee. Untuk mengetahui informasi selengkapnya, lihat Mengintegrasikan Apigee dengan Contact Center AI.

Kebijakan ini adalah Extensible policy dan penggunaan kebijakan ini mungkin memiliki implikasi biaya atau penggunaan, bergantung pada lisensi Apigee Anda. Untuk mengetahui informasi tentang jenis kebijakan dan implikasi penggunaannya, lihat Jenis kebijakan.

Kebijakan ParseDialogflowRequest memproses WebhookRequest dari agen Dialogflow sebelum mengirim data permintaan ke sistem backend Anda. Kebijakan ini mengekstrak data dari WebhookRequest ke dalam variabel alur yang tersedia untuk Anda selama durasi seluruh panggilan API. Anda dapat menggunakan variabel dalam info, pencarian, atau logika teratur berikutnya. Kebijakan ini sangat berguna jika Anda ingin agen Dialogflow berinteraksi dengan sistem backend lama Anda. Sebelum mengirim data agen ke sistem backend, Anda dapat mem-parsing data dan menyusunnya sedemikian rupa sehingga dapat digunakan oleh sistem backend Anda.

Jika Anda adalah integrator layanan backend, Anda tidak perlu meluangkan waktu untuk memahami format WebhookRequest Dialogflow. Kebijakan ParseDialogflowRequest siap pakai menangani pemrosesan data permintaan dengan lancar.

Untuk mengakses WebhookRequest agen Dialogflow di Apigee, Anda harus menyetel URL Webhook (fulfillment) agen ke ProxyEndPoint yang telah Anda konfigurasi di Apigee. ProxyEndPoint harus dapat diakses secara publik. Untuk mengetahui informasi selengkapnya, lihat Persyaratan layanan webhook.

<ParseDialogflowRequest>

Menentukan kebijakan ParseDialogflowRequest.

Nilai Default T/A
Wajib? Wajib
Jenis Objek kompleks
Elemen Induk T/A
Elemen Turunan <DialogflowVersion>
<DisplayName>
<VariablePrefix>

Tabel berikut memberikan deskripsi umum elemen turunan yang khusus untuk kebijakan ParseDialogflowRequest:

Elemen Turunan Wajib? Deskripsi
<VariablePrefix> Opsional Menentukan awalan kustom untuk variabel alur.
<DialogflowVersion> Opsional Menentukan versi Dialogflow.

Contoh

Contoh berikut menunjukkan contoh permintaan webhook, kebijakan ParseDialogflowRequest yang sesuai, dan variabel alur yang dihasilkan setelah menerapkan kebijakan:

Sintaksis

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ParseDialogflowRequest continueOnError="false" enabled="true"
        name="POLICY_NAME">
    <!-- The display name for this policy -->
    <DisplayName>DISPLAY_NAME</DisplayName>
    <!-- The optional prefix to be added to all variables created from the
         Dialogflow Webhook request. Note that all variables created from the
         WebhookRequest object will be within a container named
         "google.dialogflow" -->
    <VariablePrefix>CUSTOM_PREFIX</VariablePrefix>
    <!-- The version of Dialogflow for which this request policy is written up.
         This policy supports only the CX version. This element is optional and
         defaults to CX if unspecified -->
    <DialogflowVersion>DIALOGFLOW_VERSION</DialogflowVersion>
</ParseDialogflowRequest>

Permintaan webhook

Contoh berikut menunjukkan permintaan webhook (dalam format JSON) dari agen Dialogflow.

{
    "fulfillmentInfo": {
        "tag": "check-claim-status"
    },
    "sessionInfo": {
        "session": "projects/apigee-test/locations/global/agents/ea45003d-3f5c-46ba-ac6b-f4c6dc8db707/sessions/5ea2e8-7c1-cf4-2cf-8e4d89e72",
        "parameters": {
            "claimId": "1234",
            "policyId": "abcd"
        }
    },
    "sentimentAnalysisResult": {
      "score": -0.7,
      "magnitude": 0.7
  }
}

Untuk melihat berbagai kolom yang dapat Anda konfigurasi dalam permintaan, lihat WebhookRequest.

Buka contoh berikutnya untuk melihat konfigurasi kebijakan ParseDialogflowRequest.

Kebijakan ParseDialogflowRequest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ParseDialogflowRequest continueOnError="false" enabled="true"
        name="DialogflowRequest-InsuranceAgent">
    <DisplayName>Insurance Agent Webhook Request Policy</DisplayName>
    <VariablePrefix>my-prefix</VariablePrefix>
    <DialogflowVersion>CX</DialogflowVersion>
</ParseDialogflowRequest>

Lanjutkan ke contoh berikutnya untuk melihat variabel alur yang dibuat oleh kebijakan.

Variabel alur

google.dialogflow.my-prefix.fulfillment.tag = "check-claim-status"
google.dialogflow.my-prefix.session.id = "5ea2e8-7c1-cf4-2cf-8e4d89e72"
google.dialogflow.my-prefix.session.project.id = "apigee-test"
google.dialogflow.my-prefix.session.agent.id = "ea45003d-3f5c-46ba-ac6b-f4c6dc8db707"
google.dialogflow.my-prefix.session.parameters.claimId = "1234"
google.dialogflow.my-prefix.session.parameters.policyId = "abcd"
google.dialogflow.my-prefix.sentimentAnalysisResultScore = -0.7
google.dialogflow.my-prefix.sentimentAnalysisResultMagnitude = 0.7

Semua variabel flow yang dihasilkan dimulai dengan google.dialogflow, diikuti dengan awalan (my-prefix) seperti yang ditentukan dalam elemen <VariablePrefix>.

Elemen ini memiliki atribut berikut yang umum untuk semua kebijakan:

Atribut Default Wajib? Deskripsi
name T/A Wajib

Nama internal kebijakan. Nilai atribut name dapat berisi huruf, angka, spasi, tanda hubung, garis bawah, dan titik. Nilai ini tidak boleh melebihi 255 karakter.

Secara opsional, gunakan elemen <DisplayName> untuk memberi label pada kebijakan di editor proxy UI pengelolaan dengan nama bahasa alami yang berbeda.

continueOnError false Opsional Tetapkan ke false untuk menampilkan error saat kebijakan gagal. Perilaku ini wajar terjadi untuk sebagian besar kebijakan. Tetapkan ke true agar eksekusi alur berlanjut meskipun setelah kebijakan gagal. Lihat juga:
enabled benar Opsional Tetapkan ke true untuk menerapkan kebijakan. Tetapkan ke false untuk menonaktifkan kebijakan. Kebijakan tidak akan diterapkan meskipun tetap terlampir ke alur.
async   false Tidak digunakan lagi Atribut ini tidak digunakan lagi.

Referensi elemen turunan

Bagian ini menjelaskan elemen turunan <ParseDialogflowRequest>.

<DisplayName>

Gunakan selain atribut name untuk memberi label pada kebijakan di editor proxy UI pengelolaan dengan nama yang berbeda dan lebih terdengar alami.

Elemen <DisplayName> umum untuk semua kebijakan.

Nilai Default T/A
Wajib? Opsional. Jika Anda menghilangkan <DisplayName>, nilai atribut name kebijakan akan digunakan.
Jenis String
Elemen Induk <PolicyElement>
Elemen Turunan Tidak ada

Elemen <DisplayName> menggunakan sintaksis berikut:

Sintaks

<PolicyElement>
  <DisplayName>POLICY_DISPLAY_NAME</DisplayName>
  ...
</PolicyElement>

Contoh

<PolicyElement>
  <DisplayName>My Validation Policy</DisplayName>
</PolicyElement>

Elemen <DisplayName> tidak memiliki atribut atau elemen turunan.

<VariablePrefix>

Menentukan awalan kustom untuk variabel alur. Nilai yang ditentukan dalam elemen ini ditambahkan sebagai awalan ke semua nama variabel yang dihasilkan oleh kebijakan ParseDialogflowRequest. Secara default, semua variabel yang dihasilkan oleh kebijakan diberi awalan google.dialogflow. Jika Anda telah menentukan elemen VariablePrefix, awalan kustom Anda akan ditambahkan setelah google.dialogflow. Oleh karena itu, nama variabel dimulai dengan google.dialogflow.CUSTOM_PREFIX.

Jika Anda tidak menentukan elemen VariablePrefix, nama variabel hanya diawali dengan google.dialogflow.

Nilai Default T/A
Wajib? Opsional
Jenis String
Elemen Induk <ParseDialogflowRequest>
Elemen Turunan Tidak ada
Elemen <VariablePrefix> menggunakan sintaksis berikut:

Sintaksis

<VariablePrefix>VARIABLE_PREFIX</VariablePrefix>

Contoh

Contoh berikut menetapkan VariablePrefix ke my-prefix:

<VariablePrefix>my-custom-prefix</VariablePrefix>

Sesuai konfigurasi ini, semua nama variabel dimulai dengan google.dialogflow.my-custom-prefix.

<DialogflowVersion>

Menentukan versi Dialogflow. Kebijakan ParseDialogflowRequest hanya mendukung versi CX. Jika Anda tidak menentukan elemen ini dalam kebijakan, versi defaultnya adalah CX.

Nilai Default T/A
Wajib? Opsional
Jenis String
Elemen Induk T/A
Elemen Turunan Tidak ada
Elemen <DialogflowVersion> menggunakan sintaksis berikut:

Sintaksis

<DialogflowVersion>DIALOGFLOW_VERSION</DialogflowVersion>

Contoh

Contoh berikut menetapkan DialogflowVersion ke CX:

<DialogflowVersion>CX</DialogflowVersion>

Kode error

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause Fix
steps.parsedialogflowrequest.InvalidSessionInfo 500 This error occurs if there is an invalid sessionInfo.session field in a Dialogflow request. A Webhook can use this field to identify a session. For information about the supported session format, see Class SessionInfo.
steps.parsedialogflowrequest.MalformedInput 500 This error occurs when the JSON provided to this policy is invalid or malformed.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause Fix
UnsupportedOperation This error occurs if you have specified unsupported Dialogflow version in the DialogflowVersion element. The ParseDialogflowRequest policy supports only CX version.

Fault variables

Whenever there are execution errors in a policy, Apigee generates error messages. You can view these error messages in the error response. Many a time, system generated error messages might not be relevant in the context of your product. You might want to customize the error messages based on the type of error to make the messages more meaningful.

To customize the error messages, you can use either fault rules or the RaiseFault policy. For information about differences between fault rules and the RaiseFault policy, see FaultRules vs. the RaiseFault policy. You must check for conditions using the Condition element in both the fault rules and the RaiseFault policy. Apigee provides fault variables unique to each policy and the values of the fault variables are set when a policy triggers runtime errors. By using these variables, you can check for specific error conditions and take appropriate actions. For more information about checking error conditions, see Building conditions.

The following table describes the fault variables specific to this policy.

Variables Where Example
fault.name="FAULT_NAME" FAULT_NAME is the name of the fault, as listed in the Runtime errors table. The fault name is the last part of the fault code. fault.name Matches "UnresolvedVariable"
ParseDialogflowRequest.POLICY_NAME.failed POLICY_NAME is the user-specified name of the policy that threw the fault. ParseDialogflowRequest.My-Parse-Dialogflow-Req.failed = true
For more information about policy errors, see What you need to know about policy errors.

Topik terkait

Implementasi referensi proxy Apigee dan alur bersama yang menunjukkan penggunaan kebijakan ParseDialogflowRequest tersedia di GitHub Apigee. Untuk mengetahui informasi selengkapnya, lihat Implementasi Referensi AI Percakapan.