نمایندگان Business Messages از ادغام مستقیم با
- Dialogflow ES: تطبیق قصد و ربات های پرسش و پاسخ
- Dialogflow CX: تطبیق قصد و انتقال عامل زنده
برای ادغام یک نماینده Business Messages با سایر ویژگیهای Dialogflow ES یا Dialogflow CX ، به مستندات هر محصول مراجعه کنید.
هنگامی که یک کاربر پیامی را برای عاملی ارسال می کند که دارای یکپارچه سازی Dialogflow است، Business Messages پیام کاربر را به Dialogflow ارسال می کند و پاسخ Dialogflow را برای عامل در شی dialogflowResponse
پیام ارسال می کند. میتوانید نمایندگان را طوری پیکربندی کنید که پاسخ Dialogflow را بدون هیچ اقدامی به کاربر بهطور خودکار ارسال کنند. برای جزئیات بیشتر به پاسخهای خودکار مراجعه کنید.
یکپارچه سازی Dialogflow
قبل از اینکه بتوانید از اتوماسیون مبتنی بر Dialogflow از طریق Business Messages استفاده کنید، باید یکپارچه سازی Dialogflow را فعال کنید.
پیش نیازها
برای شروع، شما نیاز دارید
- یک نماینده پیام های تجاری
- یک عامل Dialogflow در منطقه جهانی با زبان اصلی انگلیسی (en)
اگر عامل Dialogflow ندارید، یکی ایجاد کنید .
Dialogflow ES
قبل از اینکه بتوانید ادغام Dialogflow ES را فعال کنید، به شناسه پروژه نماینده Dialogflow خود نیاز دارید. برای پیدا کردن شناسه پروژه،
- به کنسول Dialogflow بروید.
- عامل Dialogflow را که می خواهید به Business Messages متصل کنید انتخاب کنید، سپس روی نماد چرخ دنده کلیک کنید
کنار نام نماینده
- در قسمت Google Project ، به مقدار Project ID توجه کنید.
Dialogflow CX
قبل از اینکه بتوانید ادغام Dialogflow CX را فعال کنید، به شناسه پروژه و شناسه عامل Dialogflow agent خود نیاز دارید. برای یافتن این شناسه ها،
- به کنسول Dialogflow CX بروید.
- پروژه Dialogflow خود را انتخاب کنید.
- در انتخابگر عامل، روی منوی سرریز کلیک کنید
در کنار عامل Dialogflow شما.
- روی Copy name کلیک کنید. این نام کامل نماینده شما را در قالب زیر کپی میکند:
projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID
. - به ID پروژه و مقادیر شناسه عامل توجه کنید.
ادغام را ایجاد کنید
ایمیل حساب سرویس Dialogflow شریک را از
dialogflowServiceAccountEmail
دریافت کنید. شناسه شریک خود را جایگزین PARTNER_ID کنید.CURL
# This code gets the partner. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/get # Replace the __PARTNER_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/partners/__PARTNER_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet gets a partner. * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/get * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const PARTNER_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const partnerName = 'partners/' + PARTNER_ID; if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, name: partnerName, }; bcApi.partners.get(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent found console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
پایتون
"""This code gets a partner. Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/get This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( Agent, BusinesscommunicationsPartnersGetRequest, ) # Edit the values below: PARTNER_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) partners_service = BusinesscommunicationsV1.PartnersService(client) partner_name = 'partners/' + PARTNER_ID partner = partners_service.Get(BusinesscommunicationsPartnersGetRequest( name=partner_name )) print(partner)
ایمیل حساب سرویس را کپی کنید. این حساب پیامهای تجاری و نمایندگان Dialogflow شما را به هم متصل میکند.
در Google Cloud Console ، پروژه Dialogflow خود را انتخاب کنید.
به مجوزهای IAM بروید.
روی افزودن کلیک کنید و ایمیل حساب سرویس را برای اعضای جدید وارد کنید.
برای انتخاب نقش ، Dialogflow Console Agent Editor را انتخاب کنید.
روی افزودن نقش دیگری کلیک کنید و Dialogflow API Client را انتخاب کنید.
روی ذخیره کلیک کنید.
پروژه Dialogflow خود را با نماینده Business Messages خود یکپارچه کنید.
AUTO_RESPONSE_STATUS با ENABLED یا DISABLED جایگزین کنید، بسته به اینکه می خواهید Business Messages به طور خودکار با پاسخ های Dialogflow به کاربران پاسخ دهد یا خیر.
Dialogflow ES
CURL
# This code creates a Dialogflow ES integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_es # Replace the __BRAND_ID__, __AGENT_ID__, __DIALOGFLOW_ES_PROJECT_ID__ and __AUTO_RESPONSE_STATUS__ # Make sure a service account key file exists at ./service_account_key.json curl -X POST \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -d '{ "dialogflowEsIntegration": { "dialogflowProjectId": "__DIALOGFLOW_ES_PROJECT_ID__", "autoResponseStatus": "__AUTO_RESPONSE_STATUS__" } }'
Node.js
/** * This code snippet creates a Dialogflow ES integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_es * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const DIALOGFLOW_ES_PROJECT_ID = 'EDIT_HERE' const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const agentName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID; if (authClient) { const integrationObject = { dialogflowEsIntegration: { dialogflowProjectId: DIALOGFLOW_ES_PROJECT_ID, autoResponseStatus: 'ENABLED' } }; // Setup the parameters for the API call const apiParams = { auth: authClient, parent: agentName, resource: integrationObject }; bcApi.brands.agents.integrations.create(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
پایتون
"""This code snippet creates a Dialogflow ES integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_es This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest, DialogflowEsIntegration ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' DIALOGFLOW_ES_PROJECT_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID integration = integrations_service.Create(BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest( integration=DialogflowEsIntegration( autoResponseStatus=DialogflowEsIntegration.AutoResponseStatusValueValuesEnum.ENABLED, dialogflowProjectId=DIALOGFLOW_ES_PROJECT_ID ), parent=agent_name )) print(integration)
Dialogflow CX
CURL
# This code creates a Dialogflow CX integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_cx # Replace the __BRAND_ID__, __AGENT_ID__, __DIALOGFLOW_CX_PROJECT_ID__, __DIALOGFLOW_CX_AGENT_ID__ and __AUTO_RESPONSE_STATUS__ # Make sure a service account key file exists at ./service_account_key.json curl -X POST \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -d '{ "dialogflowCxIntegration": { "dialogflowProjectId": "__DIALOGFLOW_CX_PROJECT_ID__", "dialogflowAgentId": "__DIALOGFLOW_CX_AGENT_ID__", "autoResponseStatus": "__AUTO_RESPONSE_STATUS__" } }'
Node.js
/** * This code snippet creates a Dialogflow CX integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_cx * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const DIALOGFLOW_CX_AGENT_ID = 'EDIT_HERE' const DIALOGFLOW_CX_PROJECT_ID = 'EDIT_HERE' const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const agentName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID; if (authClient) { const integrationObject = { dialogflowCxIntegration: { dialogflowProjectId: DIALOGFLOW_CX_PROJECT_ID, dialogflowAgentId: DIALOGFLOW_CX_AGENT_ID, autoResponseStatus: 'ENABLED' } }; // Setup the parameters for the API call const apiParams = { auth: authClient, parent: agentName, resource: integrationObject }; bcApi.brands.agents.integrations.create(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
پایتون
"""This code snippet creates a Dialogflow CX integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_cx This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest, DialogflowCxIntegration ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' DIALOGFLOW_CX_AGENT_ID = 'EDIT_HERE' DIALOGFLOW_CX_PROJECT_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID integration = integrations_service.Create(BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest( integration=DialogflowCxIntegration( autoResponseStatus=DialogflowCxIntegration.AutoResponseStatusValueValuesEnum.ENABLED, dialogflowAgentId=DIALOGFLOW_CX_AGENT_ID, dialogflowProjectId=DIALOGFLOW_CX_PROJECT_ID ), parent=agent_name )) print(integration)
برای گزینههای قالببندی و مقدار،
Integration
را ببینید.
اتصال Business Messages و Dialogflow حدود دو دقیقه طول می کشد. برای بررسی وضعیت ادغام، OperationInfo
ادغام را دریافت کنید.
ادغام را به روز کنید
برای به روز رسانی تنظیمات پاسخ خودکار عامل خود، دستور زیر را اجرا کنید. بسته به اینکه میخواهید Business Messages به طور خودکار با پاسخهای Dialogflow به کاربران پاسخ دهد یا خیر AUTO_RESPONSE_STATUS با ENABLED یا DISABLED جایگزین کنید.
Dialogflow ES
CURL
# This code updates the Dialogflow association. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/updateDialogflowAssociation # Replace the __BRAND_ID__ and __AGENT_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/dialogflowAssociation?updateMask=enableAutoResponse" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "enableAutoResponse": true }'
Dialogflow CX
CURL
# This code updates the Dialogflow association. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/updateDialogflowAssociation # Replace the __BRAND_ID__ and __AGENT_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/dialogflowAssociation?updateMask=enableAutoResponse" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "enableAutoResponse": true }'
برای گزینههای قالببندی و مقدار، Integration
را ببینید.
بین نسخههای Dialogflow جابهجا شوید
یک نماینده Business Messages میتواند هر بار فقط یک ادغام Dialogflow را پشتیبانی کند. برای جابجایی از یک نسخه Dialogflow به نسخه دیگر، باید ادغام فعلی را قبل از ایجاد نسخه جدید حذف کنید.
ادغام را حذف کنید
اگر می خواهید Dialogflow را از نماینده Business Messages خود حذف کنید، ادغام را با دستور زیر حذف کنید.
CURL
# This code deletes an integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_the_integration # Replace the __BRAND_ID__, __AGENT_ID__ and __INTEGRATION_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X DELETE \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet deletes an integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_the_integration * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const INTEGRATION_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const integrationName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID; if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, name: integrationName, }; bcApi.brands.agents.integrations.delete(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
پایتون
"""This code snippet deletes an integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_the_integration This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' INTEGRATION_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) integration_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID integration = integrations_service.Delete(BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest( name=integration_name )) print(integration)
برای گزینههای قالببندی و مقدار، Integration
را ببینید.
اطلاعات ادغام را دریافت کنید
برای دریافت اطلاعات در مورد یکپارچگی، میتوانید از Business Communications API استفاده کنید، البته تا زمانی که مقدار name
ادغام را داشته باشید.
دریافت اطلاعات برای یک ادغام واحد
برای دریافت اطلاعات یکپارچه سازی، دستور زیر را اجرا کنید.
CURL
# This code gets information about an integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#get_info_for_a_single_integration # Replace the __BRAND_ID__, __AGENT_ID__ and __INTEGRATION_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet gets information about an integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#get_info_for_a_single_integration * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const INTEGRATION_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const integrationName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID; if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, name: integrationName, }; bcApi.brands.agents.integrations.get(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
پایتون
"""This code snippet gets information about an integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#get_info_for_a_single_integration This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' INTEGRATION_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) integration_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID integration = integrations_service.Get(BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest( name=integration_name )) print(integration)
برای گزینههای قالببندی و مقدار، Integration
را ببینید.
همه ادغام های یک عامل را فهرست کنید
اگر نام ادغام را نمیدانید، میتوانید با حذف مقدار INTEGRATION_ID از URL درخواست GET، اطلاعات مربوط به همه ادغامهای مرتبط با یک عامل را دریافت کنید.
CURL
# This code lists all integrations for an agent. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#list_all_integrations_for_an_agent # Replace the __BRAND_ID__ and __AGENT_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet lists all integrations for an agent. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#list_all_integrations_for_an_agent * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, parent: 'brands/' + BRAND_ID + '/agents/' + AGENT_ID, }; bcApi.brands.agents.integrations.list(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
پایتون
"""This code snippet lists all integrations for an agent. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#list_all_integrations_for_an_agent This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsListRequest ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID integration = integrations_service.List( BusinesscommunicationsBrandsAgentsIntegrationsListRequest(parent=agent_name) ) print(integration)
برای گزینههای قالببندی و مقدار، Integration
را ببینید.
تطبیق قصد
پس از فعال کردن ادغام Dialogflow برای یک نماینده Business Messages، نماینده شما می تواند از اهداف پیکربندی شده پروژه Dialogflow شما برای درک و پاسخ به سوالات کاربر بدون نیاز به نوشتن کد استفاده کند. برای کسب اطلاعات بیشتر درباره مقاصد، به مستندات Dialogflow ES و Dialogflow CX مراجعه کنید.
اهداف Dialogflow خود را برای هر گزینه مکالمه ای که قصد دارید از طریق اتوماسیون پشتیبانی کنید، پیکربندی کنید. نمایندگان Business Messages برای درک پیام های کاربر به Dialogflow متکی هستند.
هنگام فراخوانی APIهای Dialogflow، Business Messages بار پیام کاربر را به اهداف و وبکهک تحقق شما منتقل می کند. هنگامی که یک پیام کاربر با یک intent تطبیق داده می شود، می توانید به این بار در قالب Struct
در قسمت business_messages_payload
در QueryParameters
دسترسی داشته باشید.
بارگذاری شامل تمام فیلدهای پیام کاربر به جز DialogflowResponse
است.
برای Dialogflow CX، Business Messages همچنین یک پارامتر جلسه به نام channel
با مقدار google_business_messages
را به اهداف شما ارسال می کند و می توانید آن را در نماینده خود با فرمت زیر ارجاع دهید: $session.params.channel
.
این پارامتر را می توان برای افزودن شرطی به اجرای Dialogflow خود به منظور پشتیبانی از چندین کانال در یک عامل Dialogflow استفاده کرد.
برای اطلاعات بیشتر در مورد پارامترهای پرس و جو، به مراجع Dialogflow ES و Dialogflow CX مراجعه کنید.
پیش نیازها
هنگام ایجاد مدلهای NLU در Dialogflow، میتوانید انواع مختلف پاسخ را برای یک intent پیکربندی کنید. Business Messages از پاسخ پیش فرض پشتیبانی می کند که می تواند شامل موارد زیر باشد:
- متن
- محموله سفارشی
- انتقال عامل زنده (فقط Dialogflow CX)
یک بار سفارشی باید با شیء پاسخ پیام JSON معتبر Business Messages مطابقت داشته باشد. هنگام پیکربندی پاسخهای بار سفارشی برای یک هدف، Business Messages فیلدهای زیر را نادیده میگیرد:
-
name
-
messageId
-
representative
نمونه پاسخ های زیر را ببینید.
پیامک همراه با پیشنهاد
{
"text": "Hello World!",
"fallback": "Hello World!\n\nReply with \"Hello\" or \"Hi!\"",
"suggestions": [
{
"reply": {
"text": "Hello",
"postbackData": "hello-formal"
}
},
{
"reply": {
"text": "Hi!",
"postbackData": "hello-informal"
}
}
]
}
کارت غنی
{
"fallback": "Hello, world!\nSent with Business Messages\n\nReply with \"Suggestion #1\" or \"Suggestion #2\"",
"richCard": {
"standaloneCard": {
"cardContent": {
"title": "Hello, world!",
"description": "Sent with Business Messages.",
"media": {
"height": "TALL",
"contentInfo":{
"altText": "Google logo",
"fileUrl": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
"forceRefresh": "false"
}
},
"suggestions": [
{
"reply": {
"text": "Suggestion #1",
"postbackData": "suggestion_1"
}
},
{
"reply": {
"text": "Suggestion #2",
"postbackData": "suggestion_2"
}
}
]
}
}
}
}
چرخ فلک کارتی غنی
{
"fallback": "Card #1\nThe description for card #1\n\nCard #2\nThe description for card #2\n\nReply with \"Card #1\" or \"Card #2\"",
"richCard": {
"carouselCard": {
"cardWidth": "MEDIUM",
"cardContents": [
{
"title": "Card #1",
"description": "The description for card #1",
"suggestions": [
{
"reply": {
"text": "Card #1",
"postbackData": "card_1"
}
}
],
"media": {
"height": "MEDIUM",
"contentInfo": {
"fileUrl": "https://my.files/cute-dog.jpg",
"forceRefresh": false
}
}
},
{
"title": "Card #2",
"description": "The description for card #2",
"suggestions": [
{
"reply": {
"text": "Card #2",
"postbackData": "card_2"
}
}
],
"media": {
"height": "MEDIUM",
"contentInfo": {
"fileUrl": "https://my.files/elephant.jpg",
"forceRefresh": false
}
}
}
]
}
}
}
انتقال نماینده زنده
{
"metadata": {}
}
ربات های پرسش و پاسخ
پس از فعال کردن یکپارچه سازی Dialogflow ES برای یک نماینده Business Messages، می توانید یک ربات پرسش و پاسخ ایجاد کنید. وقتی سؤال و پاسخها را به عنوان یک سند دانش پشتیبانی شده ارائه میکنید، Business Messages و Dialogflow زیرساخت لازم را برای درک و پاسخ به سؤالات کاربر بدون نیاز به نوشتن کد ایجاد میکنند.
برای مشاهده عملکرد ربات پرسشهای متداول، با ربات پرسشهای متداول پیامهای تجاری گپ بزنید.
پیش نیازها
قبل از ایجاد یک ربات پرسشهای متداول، به سؤالات و پاسخهای خود نیاز دارید که به عنوان یک سند دانش (حداکثر 50 مگابایت) در دسترس باشد: یک فایل HTML در دسترس عموم یا یک فایل CSV.
به طور کلی اسناد دانش
- همانطور که در متن غنی مشخص شده است، می تواند شامل علامت گذاری محدود در پاسخ ها شود.
- حداکثر حجم 50 مگابایت باشد.
- نباید بیش از 2000 جفت سوال/پاسخ باشد.
- از سوالات تکراری با پاسخ های متفاوت پشتیبانی نکنید.
برای فایل های HTML،
- فایلهای URLهای عمومی باید توسط نمایهساز جستجوی Google خزیده شده باشند تا در فهرست جستجو وجود داشته باشند. میتوانید این موضوع را با کنسول جستجوی Google بررسی کنید. توجه داشته باشید که نمایه ساز محتوای شما را تازه نگه نمی دارد. هنگامی که محتوای منبع تغییر می کند، باید به صراحت سند خود را به روز کنید.
- Dialogflow هنگام ایجاد پاسخ، تگ های HTML را از محتوا حذف می کند. به همین دلیل، بهتر است از تگ های HTML اجتناب کنید و در صورت امکان از متن ساده استفاده کنید.
- فایلهای دارای یک جفت سوال/پاسخ پشتیبانی نمیشوند.
برای فایل های CSV،
- فایل ها باید در ستون اول سوالات و در ستون دوم پاسخ ها بدون سربرگ داشته باشند.
- فایل ها باید از کاما به عنوان جداکننده استفاده کنند.
یک ربات پرسش و پاسخ ایجاد کنید
برای ایجاد یک ربات پرسشهای متداول، ابتدا یک پایگاه دانش برای ذخیره تمام دادههای ربات ایجاد میکنید، سپس یک یا چند سند را با جفت پرسش/پاسخ به پایگاه دانش خود اضافه میکنید.
یک پایگاه دانش ایجاد کنید
برای ایجاد پایگاه دانش، دستور زیر را اجرا کنید. BRAND_ID ، AGENT_ID ، و INTEGRATION_ID را با مقادیر یکتا از name
سند جایگزین کنید. KNOWLEDGE_BASE_DISPLAY_NAME را با یک رشته شناسایی انتخابی جایگزین کنید.
پس از ایجاد یک پایگاه دانش، می توانید اسنادی را در آن ایجاد کنید .
CURL
# This code creates a knowledge base. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#create-knowledge-base # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__ and __KNOWLEDGE_BASE_DISPLAY_NAME__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__" } ] } }'
برای گزینههای قالببندی و مقدار، به DialogflowKnowledgebase
مراجعه کنید.
یک سند دانش ایجاد کنید
برای ایجاد یک سند دانش، دستور زیر را اجرا کنید.
سند را به لیست اسناد موجود اضافه کنید، یا اگر هنوز وجود ندارد، فهرست جدیدی ایجاد کنید. فهرستی از اسناد موجود باید شامل مقدار name
سند در درخواست باشد.
فایل HTML عمومی
متغیرهای زیر را جایگزین کنید:
- BRAND_ID ، AGENT_ID ، و INTEGRATION_ID با مقادیر منحصر به فرد از
name
ادغام - KNOWLEDGE_BASE_DISPLAY_NAME و DOCUMENT_DISPLAY_NAME با رشته های شناسایی انتخابی شما
PUBLIC_URL با نشانی اینترنتی عمومی سند دانش
CURL
# This code creates a knowledge base document from an HTML document and adds it to the knowledge base. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#create-document # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__, __KNOWLEDGE_BASE_DISPLAY_NAME__, __DOCUMENT_DISPLAY_NAME__ and __PUBLIC_URL__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__", "documents": [ { "displayName": "__DOCUMENT_DISPLAY_NAME__", "faqUrl": "__PUBLIC_URL__" } ] } ] } }'
فایل CSV محلی
متغیرهای زیر را جایگزین کنید:
- BRAND_ID ، AGENT_ID ، و INTEGRATION_ID با مقادیر منحصر به فرد از
name
ادغام - KNOWLEDGE_BASE_DISPLAY_NAME و DOCUMENT_DISPLAY_NAME با رشته های شناسایی انتخابی شما
CSV_RAW_BYTES با فایل CSV به عنوان رشته کدگذاری شده با base64
CURL
# This code creates a knowledge base document from a CSV document and adds it to the knowledge base. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#create-document # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__, __KNOWLEDGE_BASE_DISPLAY_NAME__, __DOCUMENT_DISPLAY_NAME__ and __CSV_RAW_BYTES__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__", "documents": [ { "displayName": "__DOCUMENT_DISPLAY_NAME__", "rawContent": "__CSV_RAW_BYTES__" } ] } ] } }'
برای گزینههای قالببندی و مقدار، به DialogflowKnowledgebase
مراجعه کنید.
حدود دو دقیقه طول می کشد تا یک سند به پایگاه دانش اضافه شود. برای بررسی وضعیت سند، OperationInfo
ادغام را دریافت کنید.
حذف یک سند دانش
اگر میخواهید جفتهای پرسش/پاسخ را از نماینده پیامهای تجاری خود حذف کنید، سند دانشی را که حاوی آنهاست با دستور زیر حذف کنید.
دستور زیر را برای حذف یک سند موجود اجرا کنید. BRAND_ID ، AGENT_ID ، و INTEGRATION_ID را با مقادیر یکتا از name
سند جایگزین کنید. KNOWLEDGE_BASE_DISPLAY_NAME را با رشته مناسب جایگزین کنید.
CURL
# This code deletes a knowledge base document. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_a_knowledge_document # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__ and __KNOWLEDGE_BASE_DISPLAY_NAME__ # To delete all knowledge bases, set dialogflowKnowledgeBases to an empty list. Otherwise, the list should contain all existing knowledgebases except the one you would like to remove. # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__" } ] } }'
برای گزینههای قالببندی و مقدار، به DialogflowKnowledgebase
مراجعه کنید.
پاسخ های خودکار
اگر در طول ادغام Dialogflow پاسخ خودکار را فعال کنید، Business Messages به طور خودکار از طریق Dialogflow به کاربر پاسخ می دهد. نماینده پیامهای تجاری شما با بالاترین سطح اطمینان پاسخ میدهد. با ادغام Dialogflow ES، اگر هم برای پاسخ پرسشهای متداول و هم برای هدف سفارشی مطابقت داشته باشد، Business Messages با مطابقتی که بالاترین سطح اطمینان را دارد، پاسخ میدهد.
Business Messages همه پیامهای پاسخدهی شده خودکار را بهعنوان دریافتی از نمایندگان BOT
علامتگذاری میکند. اگر نماینده شما از نمایندگان زنده پشتیبانی میکند، Business Messages پاسخهای خودکار را پس از رویدادهای REPRESENTATIVE_JOINED
به حالت تعلیق در میآورد و پاسخهای خودکار را پس از رویدادهای REPRESENTATIVE_LEFT
از سر میگیرد. به انتقال از ربات به عامل زنده مراجعه کنید.
پاسخ خودکار با پاسخ پرسشهای متداول
با ادغام Dialogflow ES، اگر پاسخ پرسشهای متداول دارای بالاترین سطح اطمینان باشد، Business Messages پاسخ را به یک پیام متنی ترسیم میکند. اگر پاسخی مرتبط اما متفاوت در دسترس باشد، پیام پیشنهادی "مشاهده پاسخ دیگری" را نشان می دهد. در غیر این صورت، پیام شامل یک سوال و پاسخهای پیشنهادی میشود که میپرسد آیا پیام درخواست کاربر را برآورده کرده است یا خیر.
پاسخ خودکار با یک پاسخ قصد
پاسخ های قصد می تواند شامل یک یا چند پاسخ زیر باشد.
- Dialogflow ES: متن ، بار سفارشی
- Dialogflow CX: متن ، محموله سفارشی ، انتقال عامل زنده
اگر پاسخ قصد دارای بالاترین سطح اطمینان باشد، موارد زیر اعمال می شود.
- اگر پاسخ حداقل یک مقدار متنی داشته باشد، Business Messages این مقدار را به یک پیام متنی نگاشت می کند.
- اگر پاسخ دارای حداقل یک بار سفارشی با ساختار شیء JSON Business Messages معتبر باشد، Business Messages با استفاده از شی JSON ارائه شده پیامی ایجاد می کند.
- اگر پاسخ حداقل یک پاسخ انتقال نماینده زنده داشته باشد، به پاسخ خودکار با درخواست نماینده زنده مراجعه کنید.
از آنجایی که Dialogflow میتواند شامل چندین پاسخ در یک تطابق با هدف باشد، Business Messages هر پاسخ متنی، بار سفارشی یا انتقال عامل زنده را به عنوان یک پیام جداگانه ارسال میکند. اگر چندین پیام در یک هدف وجود داشته باشد، اما برخی از آنها بدشکل باشند، Business Messages فقط پیامهای معتبر را به عنوان پاسخ خودکار ارسال میکند.
پاسخ خودکار با درخواست نماینده زنده
Dialogflow CX از پاسخ انتقال عامل زنده پشتیبانی می کند. این سیگنال نشان میدهد که مکالمه باید به یک نماینده انسانی واگذار شود و به شما امکان میدهد ابردادههای سفارشی را برای رویه انتقال خود ارسال کنید. اگر یک پاسخ قصد دارای بالاترین سطح اطمینان مطابقت داشته باشد، و شامل انتقال نماینده زنده باشد، Business Messages رویداد درخواست شده توسط نماینده زنده را به وبهوک شما ارسال میکند. برای رسیدگی به این رویداد، انتقال از ربات به عامل زنده را ببینید.
پاسخ خودکار با یک پیام برگشتی
اگر Dialogflow با سطح اطمینان بالایی مطابقت نداشته باشد، Business Messages یک پاسخ بازگشتی ارسال میکند. بازگشت به عقب در Dialogflow ES و Dialogflow CX متفاوت است.
Dialogflow ES
برای رباتهای سؤالات متداول، اگر پاسخ سؤالات متداول مطابقت نداشته باشد، Business Messages یک پیام بازگشتی ارسال میکند که نمیتواند پاسخی را پیدا کند.
برای مقاصد پیکربندی شده، اگر پاسخی با هدف مطابقت نداشته باشد، Business Messages یک پاسخ قصد بازگشتی ارسال میکند. میتوانید از متن بازگشتی ارائه شده توسط Dialogflow استفاده کنید، یا متن بازگشتی را با متن اضافی و بارهای سفارشی پیکربندی کنید.
در اینجا نمونه ای از پاسخ قصد بازگشتی است که وب هوک شما می تواند دریافت کند:
{
"intentResponses": [
{
"intentName": "projects/df-integration/agent/intents/12345",
"intentDisplayName": "Default Fallback Intent",
"intentDetectionConfidence": "1.0",
"fulfillmentMessages": [
{
"text": "One more time?"
}
]
}
]
}
Dialogflow از قبل intent_name
و intent_display_name
را پر می کند.
Dialogflow CX
Dialogflow CX پاسخهای قصد بازگشتی را به عنوان رویدادهای داخلی مدیریت میکند. اگر پاسخی با هدف مطابقت نداشته باشد، Business Messages یک پیام بازگشتی از رویداد پیشفرض No-Match در Dialogflow ارسال میکند. میتوانید از متن بازگشتی ارائهشده توسط Dialogflow استفاده کنید یا نسخه بازگشتی را با متن اضافی، بارهای سفارشی و گزینههای انتقال عامل زنده پیکربندی کنید.
در اینجا نمونه ای از پاسخ قصد بازگشتی است که وب هوک شما می تواند دریافت کند:
{
"intentResponses": [
{
"intentName": "sys.no-match-default",
"intentDisplayName": "Default Fallback Intent",
"intentDetectionConfidence": "0.3",
"fulfillmentMessages": [
{
"text": "I missed that, say that again?"
}
]
}
]
}
پیامهای تجاری، کدهای سخت intent_name
و intent_display_name
وارد میکنند.
فیلدهای خاص جریان گفتگو
پس از اینکه یکپارچه سازی Dialogflow را فعال کردید، پیام های کاربری که نماینده دریافت می کند شامل شی dialogflowResponse
می شود. وبهوک شما برای همه پیامهای کاربر، صرف نظر از اینکه Business Messages بهطور خودکار از طرف شما به پیام پاسخ میدهد یا خیر، دریافت میکند. برای بررسی پاسخ خودکار، مقدار فیلد autoResponded
را ببینید و تصمیم بگیرید که آیا باید به کاربر پاسخ دهید یا خیر.
Dialogflow ES
... "dialogflowResponse": { "queryText": "TEXT", "intentResponse": { "intentName": "INTENT_ID", "intentDisplayName": "INTENT_NAME", "intentDetectionConfidence": "CONFIDENCE_NUMERIC", "fulfillmentMessages": [{ "text": "FULFILLMENT_TEXT", "jsonPayload": "JSON", "error": "ERROR_STATUS", }], "faqResponse": { "userQuestion": "USER_QUESTION", "answers": [{ "faqQuestion": "FAQ_QUESTION", "faqAnswer": "FAQ_ANSWER", "matchConfidenceLevel": "CONFIDENCE_LEVEL", "matchConfidence": "CONFIDENCE_NUMERIC", }], }, "autoResponded": "BOOLEAN", "autoRespondedMessages": [{ "message": "MESSAGE_JSON", "responseSource": "SOURCE", }], }, ...
میدان | توضیحات |
---|---|
queryText | متن پرس و جو مکالمه اصلی. اگر تصحیح املای خودکار برای مدل Dialogflow فعال باشد، queryText حاوی ورودی تصحیح شده کاربر است. |
intentName | شناسه منحصر به فرد هدف منطبق. |
intentDisplayName | نام هدف منطبق. |
intentDetectionConfidence | رتبه بندی اطمینان عددی در تطابق بین queryText و intentName . |
text | یک پاسخ متنی |
jsonPayload | پاسخ محموله سفارشی این رشته با بار سفارشی تعریف شده در Dialogflow مطابقت دارد. اگر محموله دارای ساختار شیء JSON Business Messages معتبر نباشد، error مشکل را توصیف می کند. |
error | شرح یک خطا با پیام تحقق هدف. |
userQuestion | سوالی که کاربر پرسید، همانطور که توسط Dialogflow تجزیه شده است. |
faqQuestion | سؤالی از Dialogflow با سؤال کاربر مطابقت دارد. |
faqAnswer | پاسخی از Dialogflow با سوال کاربر مطابقت دارد. |
matchConfidenceLevel | سطح اطمینان در تطابق بین userQuestion و faqQuestion . |
matchConfidence | رتبه بندی اطمینان عددی در تطابق بین userQuestion و faqQuestion . |
autoResponded | اینکه آیا Business Messages به طور خودکار با پاسخی از Dialogflow به کاربر پاسخ میدهد یا خیر. |
message | بار پاسخ خودکار. |
responseSource | منبع پاسخ خودکار ResponseSource ببینید. |
Dialogflow CX
... "dialogflowResponse": { "queryText": "TEXT", "intentResponse": { "intentName": "INTENT_ID", "intentDisplayName": "INTENT_NAME", "intentDetectionConfidence": "CONFIDENCE_NUMERIC", "fulfillmentMessages": [{ "text": "FULFILLMENT_TEXT", "jsonPayload": "JSON", "error": "ERROR_STATUS", "liveAgentHandoff": { "metadata": {} } }], "autoResponded": "BOOLEAN", "autoRespondedMessages": [{ "message": "MESSAGE_JSON", "responseSource": "SOURCE", }], }, ...
میدان | توضیحات |
---|---|
queryText | متن پرس و جو مکالمه اصلی. اگر تصحیح املای خودکار برای مدل Dialogflow فعال باشد، queryText حاوی ورودی تصحیح شده کاربر است. |
intentName | شناسه منحصر به فرد هدف منطبق. |
intentDisplayName | نام هدف منطبق. |
intentDetectionConfidence | رتبه بندی اطمینان عددی در تطابق بین queryText و intentName . |
text | یک پاسخ متنی |
jsonPayload | پاسخ محموله سفارشی این رشته با بار سفارشی تعریف شده در Dialogflow مطابقت دارد. اگر محموله دارای ساختار شیء JSON Business Messages معتبر نباشد، error مشکل را توصیف می کند. |
error | شرح یک خطا با پیام تحقق هدف. |
liveAgentHandoff | فراداده سفارشی برای رویه انتقال عامل زنده شما. |
autoResponded | آیا Business Messages به طور خودکار با پاسخی از Dialogflow به کاربر پاسخ میدهد یا خیر. |
message | بار پاسخ خودکار. |
responseSource | منبع پاسخ خودکار ResponseSource ببینید. |