在与 Business Messages 代理对话时,欢迎辞会设置 互动的基调它还让用户知道代理可以执行哪些操作 决定用户的问题和期望。
每次用户打开对话时,代理都会发送欢迎辞。通过 客服人员还可以展示对话开场白 以引导用户找到已知或常见的路径。
如果用户尝试在代理的营业时间外发起对话, 代理显示离线消息 您可以据此分享备选频道或建议后续步骤。利用 这些设置可以提高代理的可靠性和易用性。
代理级设置和营业地点级设置
您可以在代理或位置级别指定对话设置。
客服人员级别: 这些对话设置适用于 代理
代理级别的欢迎辞可能会以“感谢您联系”开头 “Bridgepoint Runners...”对话开场白可以侧重于 公司级的操作或信息。
营业地点级别:这些设置会覆盖代理级别的设置,并且 仅适用于
PLACESHEET
和MAPS
入口点。营业地点级欢迎辞可能会以“感谢您联系”开头 Bridgepoint Runners on Amphitheatre Pkwy...”开场白可以集中注意力 提供基于位置的任务或信息。离线信息可能会提及该营业地点下次营业的时间。
语言区域
代理和营业地点可以针对其支持的任意语言区域指定单独的设置。例如,客服人员可能会为以下客户指定英语欢迎辞 “en”并且对“es”有相同的西班牙语欢迎辞语言区域。 Business Messages 解析用户设备报告的语言区域与 代理或营业地点使用了任何对话设置的语言区域。
系统会在每封邮件的resolvedLocale
字段。您
可以指定代理或营业地点的 defaultLocale
(权重已解析)
语言区域匹配。请参阅本地化和语言区域。
Business Messages 使用经过解析的语言区域来确定哪个对话 要应用的设置。
欢迎辞
代理与用户间对话的第一条信息是代理的欢迎辞。欢迎辞会在用户发起新对话后自动显示。良好的欢迎辞可为用户设定针对与代理互动的预期。如需修改欢迎辞,请参阅更新对话设置。
对话开场白
良好的欢迎辞可高度概括代理的功能,并采用开放式形式,而良好的对话开场白可引导用户查看常见问题或已知功能。
对话开场白显示为垂直堆叠的建议回复,并且紧随欢迎辞显示。当用户点按对话开场白时,代理会收到您在指定开场白时设置的预定义内容和回传数据。
如果代理支持特定请求的自动化功能,对话开场白可能会映射到这些请求,让您可以依靠已知输入内容实现自动化,并将任意格式的用户问题发送给可随时解答问题的人工客服。
一个代理最多可有 5 种对话开场白,而每种开场白最多能包含 35 个字符。
如需添加或修改对话开场白,请参阅更新对话设置。
离线信息
如果用户在代理的工作时间(由 MessagingAvailability
定义)之外发起与代理的对话,该用户会收到代理的离线信息。仅人工代表
系统在触发离线邮件时会考虑库存状况。仅
让聊天机器人代表始终发送欢迎辞。良好的离线信息
- 会分享代理无法提供服务的原因
- 会告知用户适当的后续步骤或备选联系渠道
- 与欢迎辞和对话开场白的口吻相符
不好的离线信息
“很抱歉,我们已经停止服务。”
良好的离线信息
“我们现在已经停止服务,但我们会从明天早上 8 点开始继续提供服务。如果您需要紧急协助,请拨打 +12223334444 或发送电子邮件至 support@gtb.com 与支持团队联系。”
如需修改离线信息,请参阅更新对话设置。
更新对话设置
如需管理欢迎辞或对话开场白,您可以使用 Business Communications API 发出 PATCH 请求,以更新代理或营业地点的 conversationalSettings
字段。
更新 conversationalSettings
字段时,您必须在 ConversationalSetting
对象中包含所有字段的值。更新请求会覆盖您修改的所有字段的内容,包括所有子字段。例如,如果您发出修改欢迎辞(但不包含对话开场白)的请求,该请求会移除之前的所有对话开场白。
前提条件
在更新对话设置之前,您需要掌握以下信息:
- 开发机器上的 GCP 项目的服务账号密钥的路径
- 要为其更新设置的语言区域
对于代理级设置,代理
name
(例如“brands/12345/agents/67890”)如果您不知道代理的
name
,请参阅列出品牌的所有代理。对于营业地点级设置,营业地点
name
(例如“brands/12345/locations/67890”)如果您不知道营业地点的
name
,请参阅列出品牌的所有营业地点。要更新的语言区域,以两个字符的 ISO 639-1 语言代码表示
新的欢迎辞
隐私权政策网址
(可选)对话开场白的文本
(可选)对话开场白的回传数据
(可选)新的离线信息
如果您不知道当前的 conversationalSettings
值,请参阅获取代理信息和获取营业地点信息。
发送更新请求
如需更新代理或营业地点,请运行以下命令。将变量替换为您在前提条件中确定的值。
如果您不想使用对话开场白,请忽略 conversationStarters
及其所有子字段。
代理级设置
cURL
# This code updates the conversational settings of a Business Messages agent. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/patch # Replace the __BRAND_ID__, __AGENT_ID__ and __LOCALE__ # 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__?updateMask=businessMessagesAgent.conversationalSettings.__LOCALE__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "businessMessagesAgent": { "conversationalSettings": { "__LOCALE__": { "welcomeMessage": { "text": "My first welcome message" }, "offlineMessage": { "text": "My first offline message" }, "privacyPolicy": { "url": "https://www.your-company-website.com/privacy" }, "conversationStarters": [ { "suggestion": { "reply": { "text": "Suggestion 1", "postbackData": "post_back_suggestion_1" } } } ] } } } }'
Node.js
/** * This code snippet updates the conversationalSettings of a Business Messages agent. * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/patch * * 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 LOCALE = 'en'; 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 agentName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID; if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, name: agentName, updateMask: 'businessMessagesAgent.conversationalSettings.' + LOCALE, resource: { businessMessagesAgent: { conversationalSettings: { [LOCALE]: { privacyPolicy: { url: 'https://www.your-company-website.com/privacy' }, welcomeMessage: { text: 'My updated welcome message' }, offlineMessage: { text: 'My updated offline message' }, conversationStarters: [ { suggestion: { reply: { 'text': 'Suggestion 2', 'postbackData': 'post_back_suggestion_2', }, }, } ], }, } } } }; bcApi.brands.agents.patch(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();
Java
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.HttpTransport; import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.businesscommunications.v1.BusinessCommunications; import com.google.api.services.businesscommunications.v1.model.*; import com.google.common.collect.ImmutableMap; import java.io.FileInputStream; import java.util.Arrays; class Main { /** * Initializes credentials used by the Business Communications API. */ private static BusinessCommunications.Builder getBusinessCommunicationsBuilder() { BusinessCommunications.Builder builder = null; try { GoogleCredential credential = GoogleCredential .fromStream(new FileInputStream("PATH_TO_SERVICE_ACCOUNT_KEY")); credential = credential.createScoped(Arrays.asList( "https://www.googleapis.com/auth/businesscommunications")); credential.refreshToken(); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance(); // Create instance of the Business Communications API builder = new BusinessCommunications .Builder(httpTransport, jsonFactory, null) .setApplicationName(credential.getServiceAccountProjectId()); // Set the API credentials and endpoint builder.setHttpRequestInitializer(credential); } catch (Exception e) { e.printStackTrace(); } return builder; } public static void main(String args[]) { try { // Create client library reference BusinessCommunications.Builder builder = getBusinessCommunicationsBuilder(); String agentName = "brands/BRAND_ID/agents/AGENT_ID"; Agent agent = new Agent().setBusinessMessagesAgent( new BusinessMessagesAgent().setConversationalSettings(ImmutableMap.of("LOCALE", new ConversationalSetting() .setPrivacyPolicy(new PrivacyPolicy().setUrl("PRIVACY_POLICY_URL")) .setWelcomeMessage(new WelcomeMessage().setText("WELCOME_MESSAGE")) .setOfflineMessage(new OfflineMessage().setText("OFFLINE_MESSAGE")) .setConversationStarters(Arrays.asList( new ConversationStarters().setSuggestion(new Suggestion() .setReply(new SuggestedReply() .setText("REPLY_TEXT") .setPostbackData("POSTBACK_DATA"))), ))))); BusinessCommunications.Brands.Agents.Patch request = builder .build().brands().agents().patch(agentName, agent); request.setUpdateMask("businessMessagesAgent.conversationalSettings.LOCALE"); Agent updatedAgent = request.execute(); System.out.println(updatedAgent.toPrettyString()); } catch (Exception e) { e.printStackTrace(); } } }
Python
"""This code updates the conversational settings of a Business Messages agent. Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/patch 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, BusinessMessagesAgent, ConversationStarters, ConversationalSetting, OfflineMessage, PrivacyPolicy, WelcomeMessage, NegativeBotFeedbackMessage, BusinesscommunicationsBrandsAgentsPatchRequest, ) # 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) agents_service = BusinesscommunicationsV1.BrandsAgentsService(client) agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID agent=Agent( businessMessagesAgent=BusinessMessagesAgent( conversationalSettings=BusinessMessagesAgent.ConversationalSettingsValue( additionalProperties=[BusinessMessagesAgent.ConversationalSettingsValue.AdditionalProperty( key='en', value=ConversationalSetting( privacyPolicy=PrivacyPolicy(url='https://www.your-company-website.com/privacy'), welcomeMessage=WelcomeMessage(text='Welcome to Business Messages'), offlineMessage=OfflineMessage(text='This is an offline message'), conversationStarters=[ ConversationStarters( suggestion=Suggestion( reply=SuggestedReply(text='Option 1', postbackData='option_1') ) )] ) ) ] ) ) ) updated_agent = agents_service.Patch( BusinesscommunicationsBrandsAgentsPatchRequest( agent=agent, name=agent_name, updateMask='businessMessagesAgent.conversationalSettings.en' ) ) print(updated_agent)
营业地点级设置
# This code updates the agent interaction of a bot and human representatives. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/patch # Replace the __BRAND_ID__, __AGENT_ID__, __LOCATION_ID__, __LOCALE__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/locations/__LOCATION_ID__?updateMask=conversationalSettings.__LOCALE__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "conversationalSettings": { "__LOCALE__": { "welcomeMessage": { "text": "My second welcome message" }, "offlineMessage": { "text": "My second offline message" }, "privacyPolicy": { "url": "https://www.your-company-website.com/privacy" }, "conversationStarters": [ { "suggestion": { "reply": { "text": "Suggestion 2", "postbackData": "post_back_suggestion_2" } } } ] } } }'
如需了解格式设置和值信息,请参阅 brands.agents.patch
、brands.locations.patch
和 ConversationalSetting
。
示例
代理级设置
curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/BRAND_ID/agents/AGENT_ID?updateMask=businessMessagesAgent.conversationalSettings.en" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY businesscommunications)" \ -d "{ 'businessMessagesAgent': { 'conversationalSettings': { 'en': { 'welcomeMessage': { 'text': 'Thanks for contacting Growing Tree Bank. What can I help with today?', }, 'offlineMessage': { 'text': 'We\'re closed for the night. Please reach out to us again tomorrow.', }, 'privacyPolicy': { 'url': 'https://www.growingtreebank.com/privacy', }, 'conversationStarters': [ { 'suggestion': { 'reply': { 'text': 'Set up an account', 'postbackData': 'new-account', }, }, }, { 'suggestion': { 'reply': { 'text': 'Look up account information', 'postbackData': 'account-lookup', }, }, }, ], }, }, }, }"
营业地点级设置
curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/12345/locations/67890?updateMask=conversationalSettings.en" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json /path/to/service/account/key businesscommunications)" \ -d "{ 'conversationalSettings': { 'en': { 'welcomeMessage': { 'text': 'Thanks for contacting Growing Tree Bank on Amphitheatre Pkwy. What can I help with today?', }, 'offlineMessage': { 'text': 'We\'re closed for the night. Please reach out to us again tomorrow.', }, 'privacyPolicy': { 'url': 'https://www.growingtreebank.com/privacy', }, 'conversationStarters': [ { 'suggestion': { 'reply': { 'text': 'What are your hours?', 'postbackData': 'hours', }, }, }, { 'suggestion': { 'reply': { 'text': 'Set up an account', 'postbackData': 'new-account', }, }, }, { 'suggestion': { 'reply': { 'text': 'Look up account information', 'postbackData': 'account-lookup', }, }, }, { 'suggestion': { 'action': { 'text': 'Call us', 'postbackData': 'call', 'dialAction': { 'phoneNumber': '+12223334444', }, }, }, }, ], }, }, }"