ビルド済みエージェントは、Dialogflow が提供する一般的なユースケース向けのエージェントの集合です。Dialogflow ES のビルド済みエージェントと同様に、これらのエージェントを使用して会話を構築できます。Dialogflow CX では、通信、金融サービス、医療、小売、旅行など、さまざまな業界で一般的なユースケースが確認されます。
ビルド済みエージェントには、ユースケースのインテントとエンティティが含まれますが、サンプルのルートグループとフルフィルメントを変更する必要があります(該当する場合)。
ビルド済みエージェントをインポートする
ビルド済みエージェントをプロジェクトにインポートするには:
- Dialogflow CX コンソールに移動
- ビルド済みエージェントをインポートするプロジェクトをクリックします。
- [Use pre-built agents] をクリックします。
- 関心のあるエージェントをクリックし、[インポート] をクリックします。
- 目的のロケーションを選択し、[作成] をクリックします。
- テストとカスタマイズを開始します。
インポートしたビルド済みエージェントをカスタマイズする
- シミュレータを使用してエージェントのテストを行い、ユーザーの目的達成に役立つ内容を把握します。
- ユースケースに関係のないフローをすべて削除します。
- ビジネスのニーズに合わせて、エージェント ダイアログとカスタム エンティティを編集します。
- Webhook ソースコードがある場合は、Webhook コードの変更をご覧ください。
Webhook コードの変更
ビルド済みエージェントにより Webhook が使用されます。元の Webhook ソースコードは Node.js を使用し、Google の内部 Cloud Functions プロジェクトでホストされています。
このコードを独自の Cloud Functions プロジェクトで使用して変更するには、次の手順を行います。
- Dialogflow CX コンソールに移動
- ビルド済みエージェントをインポートするプロジェクトをクリックします。
- [Use pre-built agents] をクリックします。
関心のあるエージェントをクリックし、[Documentation link] をクリックします。これにより、このドキュメントの関連するビルド済みエージェント セクションに移動します。
ビルド済みエージェントの [Webhook] サブセクションを参照して、ソースコードをコピーします。
Google Cloud Console に移動し、左側のパネルで [Cloud Functions] を選択します。
ソースコードをインポートするプロジェクトをクリックします。
[関数を作成] をクリックします。 詳しい手順については、Cloud Functions の関数を作成するドキュメントをご覧ください。
[ソースコード] セクションで [インライン エディタ] を選択し、コピーしたソースコードを貼り付けます。
ビジネスルールに基づいてロジックを変更するには、[ソース] をクリックしてから [編集] をクリックします。完了したら、[デプロイ] をクリックします。
[トリガー] をクリックして、[トリガー URL] をコピーします。
[管理] > [Webhook] に移動し、新しい URL を貼り付ける Webhook を選択して、そのトリガー URL をエージェントに置き換えます。トリガー URL を Webhook URL というラベルのフィールドに貼り付けます。[Save] をクリックします。
Webhook ドキュメントを使用して、フルフィルメントをテストします。
医療エージェント
このテンプレートは、エンドユーザーが要求、メリットを確認し、医師の検索を行うのに役立ちます。
発話例
- 共同負担とは何ですか?
- 医師を探してくれますか?
- 気分が悪いです。
- 自己負担額はいくらですか?
注文とアカウント マネジメント エージェント
このテンプレートは、エンドユーザーが商品を購入または返品し、注文を追跡して、ポイント、住所、パスワードなどのアカウント設定を管理する場合に役立ちます。
発話例
- 注文した商品が届きませんが、現在どこにありますか?
- 新しいスマートフォンを買いたいです。
- パスワードを忘れました。
- 私の所有ポイント数を教えてもらえますか?
- 引越ししたので住所を更新する必要があります。
支払い計画エージェント
このテンプレートは、エンドユーザーが 2 回の分割払い計画を設定する、または支払い期限を延長するのに役立ちます。
発話例
- アカウントが停止されました。
- 料金の支払いが期日までに間に合いません。
- 支払い期限を延長する必要があります。
- COVID-19(新型コロナウイルス感染症)により失業しました。
Webhook
この Cloud Functions を使用する Webhook は次のアクションを実行します。
- 未払い額と最大延長期間のサンプルを提供します。
- 合計残高と最初の分割払いの差額に基づいて、2 回目の分割払い額を計算します。
- リクエストされた延長期日が最大延長期日を超えていないことを検証します。
package.json
{ "name": "sample-http", "version": "0.0.1", "dependencies": { "moment": "2.27.0" } }
index.js
const moment = require('moment'); function getRandomAmount(min, max) { return Math.random() * (max - min) + min; } function formatCurrency(amount) { return Number(amount).toFixed(2); } function formatUserDate(dateObject) { if (!dateObject) { console.log('dateObject error. dateObject passed to formatUserDate is:', dateObject); console.log('dateObject requires day, month, year properties:'); // return false if the dates are not valid // returning false prevents the if/else block from running, which causes the function to crash. return false; } console.log('formatUserDate date set.'); const { day, year, month } = dateObject; return `${year}-${month}-${day}`; } /** * Responds to any HTTP request. * * @param {!express:Request} req HTTP request context. * @param {!express:Response} res HTTP response context. */ exports.cxPrebuiltAgentsPaymentArrangement = (req, res) => { var tag = req.body.fulfillmentInfo.tag; var first_payment; var amount_due_1; //var adjust_due_date; var max_date_1; var maxDate1; var max_date_2; var maxDate2; var current_due_date; var max_extension_date; var maxExtensionDate; var amount_due; var payment_amount_2; var dateFromUser; var valid_payment; var valid_date; if (!!tag) { switch (tag) { //Initialize Dynamic parameters case 'setDynamicParams': console.log(tag + ' was triggered.'); max_date_1 = moment().add(15, 'days').calendar(); max_date_2 = moment().add(25, 'days').calendar(); current_due_date = moment().add(10, 'days').calendar(); max_extension_date = moment().add(30, 'days').calendar(); amount_due = formatCurrency(getRandomAmount(200, 400)); res.status(200).send({ sessionInfo: { parameters: { max_date_1: max_date_1, max_date_2: max_date_2, current_due_date: current_due_date, max_extension_date: max_extension_date, amount_due: amount_due, } } }); break; //Initialize Static parameters case 'setStaticParams': console.log(tag + ' was triggered.'); user_id = req.body.sessionInfo.parameters.user_id; if (user_id == '1001') { max_date_1 = "2021-01-15"; max_date_2 = "2021-01-30"; current_due_date = "2021-01-01"; max_extension_date = "2021-02-15"; amount_due = '225.00'; } else if (user_id == '2002') { max_date_1 = "2021-03-15"; max_date_2 = "2021-03-30"; current_due_date = "2021-03-01"; max_extension_date = "2021-04-15"; amount_due = '333.00'; } else if (user_id == '3003') { max_date_1 = "2021-05-15"; max_date_2 = "2021-05-30"; current_due_date = "2021-05-01"; max_extension_date = "2021-06-15"; amount_due = '189.00'; } else { max_date_1 = moment().add(15, 'days').calendar(); max_date_2 = moment().add(25, 'days').calendar(); current_due_date = moment().add(10, 'days').calendar(); max_extension_date = moment().add(30, 'days').calendar(); amount_due = formatCurrency(getRandomAmount(200, 400)); } res.status(200).send({ sessionInfo: { parameters: { max_date_1: max_date_1, max_date_2: max_date_2, current_due_date: current_due_date, max_extension_date: max_extension_date, amount_due: formatCurrency(amount_due), } } }); break; //Automatically set second payment based on first payment amount case 'secondPayment': console.log(tag + ' was triggered.'); first_payment = req.body.sessionInfo.parameters.payment_amount_1.amount; amount_due_1 = req.body.sessionInfo.parameters.amount_due; payment_amount_2 = formatCurrency(amount_due_1 - formatCurrency(first_payment)); res.status(200).send({ sessionInfo: { parameters: { payment_amount_2: payment_amount_2 } } }); break; //BEGIN validatePayment case 'validatePayment': console.log(tag + ' was triggered.'); first_payment = req.body.sessionInfo.parameters.payment_amount_1.amount; amount_due_1 = req.body.sessionInfo.parameters.amount_due; if ((formatCurrency(first_payment) >= '100.00') && (formatCurrency(first_payment) < amount_due_1)) { valid_payment = "True"; } else { valid_payment = "False" } res.status(200).send({ sessionInfo: { parameters: { valid_payment: valid_payment, } } }); break; //BEGIN validateDate case 'validateDate': // Log when the cloud function for the validateDate tag is triggered console.log(tag + ' was triggered.'); // Log ALL of the session parameters passed to the cloud function console.log('validateDate sessionInfo parameters', req.body.sessionInfo.parameters); // Log ONLY max_extension_date and adjust_due_date values from session parameters. console.log('sessionInfo >>> max_extension_date', req.body.sessionInfo.parameters.max_extension_date); console.log('sessionInfo >>> adjust_due_date', req.body.sessionInfo.parameters.adjust_due_date); // If the formatUserDate function succeeds running, then the date will be a string formatted as yyyy-mm-dd. // If the session params dateObject is not fomatted correctly the formatUserDate function returns the boolean value false. // formatUserDate returns false to prevent the Moment function from running (see 3 conditions below). dateFromUser = formatUserDate(req.body.sessionInfo.parameters.adjust_due_date); maxExtensionDate = req.body.sessionInfo.parameters.max_extension_date; // Set valid_date to false. We do this so the cloud function does not crash and always returns a value to Dialogflow valid_date = "False" // Only set valid_date to true when // 1) dateFromUser is a date string and not set to false by the formatUserDate function // 2) maxExtensionDate is string and not set to false by the formatUserDate function // 3) if Moment determines the dateFromUser is before maxExtensionDate if (dateFromUser && maxExtensionDate && moment(dateFromUser).isSameOrBefore(maxExtensionDate)) { valid_date = "True"; } res.status(200).send({ sessionInfo: { parameters: { valid_date: valid_date, // You will see the debug property in the Dialogflow UI // if formatUserDate failed for eitehr date you will // see 'false' in the UI. // Otherwise, you will see the string formatted date debug: {dateFromUser, maxExtensionDate} } } }); break; case 'validateDate1': // Log when the cloud function for the validateDate tag is triggered console.log(tag + ' was triggered.'); // Log ALL of the session parameters passed to the cloud function console.log('validateDate sessionInfo parameters', req.body.sessionInfo.parameters); // Log ONLY max_date_1 and payment_date_1 values from session parameters. console.log('sessionInfo >>> max_date_1', req.body.sessionInfo.parameters.max_date_1); console.log('sessionInfo >>> payment_date_1', req.body.sessionInfo.parameters.payment_date_1); // If the formatUserDate function succeeds running, then the date will be a string formatted as yyyy-mm-dd. // If the session params dateObject is not fomatted correctly the formatUserDate function returns the boolean value false. // formatUserDate returns false to prevent the Moment function from running (see 3 conditions below). dateFromUser = formatUserDate(req.body.sessionInfo.parameters.payment_date_1); //maxExtensionDate = formatUserDate(req.body.sessionInfo.parameters.max_extension_date); maxDate1 = req.body.sessionInfo.parameters.max_date_1; // Set valid_date to false. We do this so the cloud function does not crash and always returns a value to Dialogflow valid_date = "False" // Only set valid_date to true when // 1) dateFromUser is a date string and not set to false by the formatUserDate function // 2) maxExtensionDate is string and not set to false by the formatUserDate function // 3) if Moment determines the dateFromUser is before maxExtensionDate if (dateFromUser && maxDate1 && moment(dateFromUser).isSameOrBefore(maxDate1)) { valid_date = "True"; } res.status(200).send({ sessionInfo: { parameters: { valid_date: valid_date, // You will see the debug property in the Dialogflow UI // if formatUserDate failed for eitehr date you will // see 'false' in the UI. // Otherwise, you will see the string formatted date debug: {dateFromUser, maxDate1} } } }); break; case 'validateDate2': // Log when the cloud function for the validateDate tag is triggered console.log(tag + ' was triggered.'); // Log ALL of the session parameters passed to the cloud function console.log('validateDate sessionInfo parameters', req.body.sessionInfo.parameters); // Log ONLY max_date_2 and payment_date_2 values from session parameters. console.log('sessionInfo >>> max_extension_date', req.body.sessionInfo.parameters.max_date_2); console.log('sessionInfo >>> adjust_due_date', req.body.sessionInfo.parameters.payment_date_2); // If the formatUserDate function succeeds running, then the date will be a string formatted as yyyy-mm-dd. // If the session params dateObject is not fomatted correctly the formatUserDate function returns the boolean value false. // formatUserDate returns false to prevent the Moment function from running (see 3 conditions below). dateFromUser = formatUserDate(req.body.sessionInfo.parameters.payment_date_2); //maxExtensionDate = formatUserDate(req.body.sessionInfo.parameters.max_extension_date); maxDate2 = req.body.sessionInfo.parameters.max_date_2; // Set valid_date to false. We do this so the cloud function does not crash and always returns a value to Dialogflow valid_date = "False" // Only set valid_date to true when // 1) dateFromUser is a date string and not set to false by the formatUserDate function // 2) maxExtensionDate is string and not set to false by the formatUserDate function // 3) if Moment determines the dateFromUser is before maxExtensionDate if (dateFromUser && maxDate2 && moment(dateFromUser).isSameOrBefore(maxDate2)) { valid_date = "True"; } res.status(200).send({ sessionInfo: { parameters: { valid_date: valid_date, // You will see the debug property in the Dialogflow UI // if formatUserDate failed for eitehr date you will // see 'false' in the UI. // Otherwise, you will see the string formatted date debug: {dateFromUser, maxDate2} } } }); break; default: break; } } };
通信エージェント
このテンプレートは、エンドユーザーが支払いや計画の疑問を解決し、トラブルシューティングして、旅行やクルーズの計画を追加するのに役立ちます。
発話例
- 料金を抑えるにはどうすればよいですか?
- テキスト メッセージが送信されません。
- プラン A にアップグレードした場合、追加料金はどのくらいかかりますか?
- ジャマイカ旅行のためのデータ カバレッジが必要です。
Webhook
Cloud Functions を使用する Webhook は次のアクションを実行します。
- 旅行の目的地と期間に基づいたプラン費用の比較
- エンドユーザーの電話番号に基づいた請求異常の識別
package.json
{ "name": "sample-http", "version": "0.0.1", "dependencies": { "moment": "2.24.0" } }
index.js
/** * Responds to any HTTP request. * * @param {!express:Request} req HTTP request context. * @param {!express:Response} res HTTP response context. */ const helpers = require('./helpers.js') exports.cxPrebuiltAgentsTelecom = (req, res) => { console.log('Cloud Function:', 'Invoked cloud function from Dialogflow'); let tag = req.body.fulfillmentInfo.tag; if (!!tag) { switch (tag) { //BEGIN detectCustomerAnomaly case 'detectCustomerAnomaly': console.log(tag + ' was triggered.'); let phone_number = req.body.sessionInfo.parameters.phone_number; let bill_month = req.body.sessionInfo.parameters.bill_state; let parameters = req.body.sessionInfo.parameters; let bill_amount; let product_line; let anomaly_detect = "false" let purchase = "The Godfather" let purchase_amount = 9.99 let total_bill_amount = 64.33 let bill_without_purchase = 54.34 let updated_parameters = {} let [month_name, first_of_month, last_month_name] = helpers.get_date_details(bill_month) console.log(month_name, first_of_month, last_month_name) // Getting the month name based on the bill state - current or previous // For example, if the current month is December, we get the values as // December, December 1st, November // Only 999999 will have anomaly detection if (phone_number.toString() == '999999') { anomaly_detect = "true" product_line = "phone" purchase = "device protection" updated_parameters["product_line"] = product_line updated_parameters["bill_month"] = month_name updated_parameters["last_month"] = last_month_name } // If bill hike amount is given - we just add it to the total bill if ('bill_amount' in parameters) { bill_amount = parameters['bill_amount'] purchase_amount = bill_amount['amount'] total_bill_amount = 54.34 + purchase_amount } // Adding the updated session parameters to the new parameters json updated_parameters["anomaly_detect"] = anomaly_detect updated_parameters["purchase"] = purchase updated_parameters["purchase_amount"] = purchase_amount updated_parameters["bill_without_purchase"] = bill_without_purchase updated_parameters["total_bill"] = total_bill_amount updated_parameters["first_month"] = first_of_month res.status(200).send({ sessionInfo: { parameters: updated_parameters } }); break; // BEGIN validatePhoneLine case 'validatePhoneLine': console.log(tag + ' was triggered.'); let phone = req.body.sessionInfo.parameters.phone_number; let phone_line_verified; let line_index; let domestic_coverage; let covered_lines = ['5555555555', '5105105100', '1231231234', '9999999999']; // Loop over the covered lines array covered_lines.forEach((line, index) => { // For each phone line in the array, check if the last 4 digits are // included in the string. when true, update the line_index variable if (line.includes(phone)) { line_index = index; console.log('This is the index ' + line_index); } }); // Only 9999 will fail; if (line_index === 3) { phone_line_verified = 'false'; } else { phone_line_verified = 'true'; } // Only 1234 will have domestic coverage. if (line_index === 2) { domestic_coverage = 'true'; } else { domestic_coverage = 'false'; } res.status(200).send({ sessionInfo: { parameters: { phone_line_verified: phone_line_verified, domestic_coverage: domestic_coverage } } }); break; // BEGIN cruisePlanCoverage case 'cruisePlanCoverage': console.log(tag + ' was triggered.'); let port = req.body.sessionInfo.parameters.destination; let port_is_covered; // Sample list of covered cruise ports. let covered_ports = [ 'mexico', 'canada', 'anguilla', ]; if (covered_ports.includes(port.toLowerCase())) { port_is_covered = 'true'; } else { port_is_covered = 'false'; } res.status(200).send( { sessionInfo: { parameters: { port_is_covered: port_is_covered } } }); break; // BEGIN internationalCoverage case 'internationalCoverage': console.log(tag + ' was triggered.'); let destination = req.body.sessionInfo.parameters.destination; let coverage; // Sample list of covered international monthly destinations. let covered_by_monthly = [ 'anguilla', 'australia', 'brazil', 'canada', 'chile', 'england', 'france', 'india', 'japan', 'mexico', 'russia', 'singapore', ]; // Sample list of covered international daily destinations. let covered_by_daily = [ 'anguilla', 'australia', 'brazil', 'canada', 'chile', 'england', 'france', 'india', 'japan', 'mexico', 'singapore' ]; if (covered_by_monthly.includes(destination.toLowerCase()) && covered_by_daily.includes(destination.toLowerCase())) { coverage = 'both'; } else if ( covered_by_monthly.includes(destination.toLowerCase()) && !covered_by_daily.includes(destination.toLowerCase())) { coverage = 'monthly_only'; } else if ( !covered_by_monthly.includes(destination.toLowerCase()) && !covered_by_daily.includes(destination.toLowerCase())) { coverage = 'neither'; } else { // This should never happen, because covered_by_daily is a subset of // covered_by_monthly coverage = 'daily_only'; } res.status(200).send({ sessionInfo: { parameters: { coverage: coverage } } }); break; // BEGIN cheapestPlan case 'cheapestPlan': console.log(tag + ' was triggered.'); let trip_duration = req.body.sessionInfo.parameters.trip_duration; let monthly_cost; let daily_cost; let suggested_plan; // Can only suggest cheapest if both are valid for location. // When trip is longer than 30 days, calculate per-month cost (example $ // amounts). Suggest monthly plan. if (trip_duration > 30) { monthly_cost = (Math.floor(trip_duration / 30)) * 70; daily_cost = trip_duration * 10; suggested_plan = 'monthly'; } // When trip is <= 30 days, but greater than 6 days, calculate monthly // plan cost and daily plan cost. Suggest monthly b/c it is the cheaper // one. else if (trip_duration <= 30 && trip_duration > 6) { monthly_cost = 70; daily_cost = trip_duration * 10; suggested_plan = 'monthly'; } // When trip is <= 6 days, calculate daily plan cost. Suggest daily // plan. else if (trip_duration <= 6 && trip_duration > 0) { monthly_cost = (Math.floor(trip_duration / 30)) * 70; daily_cost = trip_duration * 10; suggested_plan = 'daily'; } else { // This should never happen b/c trip_duration would have to be // negative suggested_plan = 'null'; } res.status(200).send({ sessionInfo: { parameters: { monthly_cost: monthly_cost, daily_cost: daily_cost, suggested_plan: suggested_plan } } }); break; default: console.log('default case called'); res.status(200).end(); break; } } };
旅行: レンタカー エージェント
このテンプレートは、エンドユーザーが新しいレンタカー予約を開始するのに役立ちます。
発話例
- ワゴン車を予約する必要があります。
- 週末にロサンゼルスに出張するため、現地にいる間は車をレンタルする必要があります。
- SUV の予約について教えてください。
旅行: フライト情報エージェント
このテンプレートは、エンドユーザーがチケットの予約や変更、フライト情報の検索、払い戻しのリクエストを行う場合に役立ちます。
発話例
- フライト XX4597 を変更する必要があります。サポートをお願いできますか?
- フライトの新しい出発時刻を教えていただけますか?
- キャンセルしたフライトのアカウントのクレジットはどうなりますか?
- 来月のサンフランシスコ行きのフライトを予約できますか?
- 2020 年 8 月 10 日午前 10 時発のサンフランシスコ空港からマイアミ国際空港への片道チケットを予約します。