如果您的 Action 每天为用户提供价值,请通过配置每日更新来提醒用户使用该 Action。当用户订阅您的 Action 的每日更新时,他们会收到一条推送通知,并可点按该通知来调用您的 Action 的其中一个 intent。
这些更新的用户体验如下:
- 用户调用您已配置为每日更新的 Action 的某个 intent。
- 用户按照提示订阅每日更新。此提示会在对话过程中提供,或在对话结束时作为建议条状标签提供。
- 用户安排在一天中的什么时间接收每日动态,向 Google 助理注册您的更新。
- 用户会在每天的预定时间在移动设备上收到 Google 助理通知。
- 当用户打开此通知时,他们会调用您配置为每日更新的 intent 并与您的 Action 互动。
默认情况下,当用户成功退出您的 Action 时,每日更新注册提示会以建议条状标签的形式显示。您还可以添加对话过程中的注册提示,或对用户的更新进行个性化设置。
用例
每日更新是一款实用的互动工具,但不应纳入每项 Action 中。在决定是否为 Action 添加每日更新订阅时,请考虑以下提示:
- 确保每日更新将导致用户每天看到不同且有用的信息。如果点按每日更新后每次都得到相同的提示,那么用户很有可能在几天后退订。
- 如果用户直接跳转到每日更新的意图,请确保对话框对他们有意义。您的用户不一定会从对话一开始就开始对话,因此不应该为其提供太多上下文。
- 在提示用户注册每日更新之前,展示您的 Action 的优势。当用户看到订阅选项时,应该想到“我想每天都想看”这个内容。
- 不要重复建议注册,让用户感到无所适从。在向用户显示他们订阅的内容后立即提供每日更新订阅,并避免在其他情境中重复提供优惠。
- 在更新 intent 触发后保持对话较短。大多数每日更新只应包含一个响应,然后关闭,无需用户输入。
设置每日动态
在 Dialogflow 中探索
点击继续,将我们的每日更新示例导入 Dialogflow 中。然后,按照以下步骤部署和测试该示例:
- 输入代理名称并为示例创建新的 Dialogflow 代理。
- 代理导入完成后,点击转至代理 (Go to agent)。
- 在主导航菜单中,前往 Fulfillment。
- 启用内嵌编辑器,然后点击部署。编辑器包含示例代码。
- 在主导航菜单中,点击 Integrations(集成),然后点击 Google Assistant。
- 在显示的模态窗口中,启用 Auto-preview changes,然后点击 Test 打开 Actions 模拟器。
- 在模拟器中,输入
Talk to my test app
以测试示例!
如需为您的 Action 的某个 intent 配置每日更新,请按照以下说明操作:
1. 准备更新 intent
将您的 Action 的某个 intent 配置为触发 intent。此 intent 支持向用户发送每日更新;当用户打开每日更新通知时,此 intent 会触发,对话将从此处继续。
如需在 Dialogflow 中定义触发 intent,请执行以下操作:
- 在 Dialogflow 控制台中,点击集成。
- 在 Google 助理部分下,点击集成设置。
- 在发现 > 隐式调用下,点击添加意图并选择您的触发意图(如果系统尚不存在)。
- 启用自动预览更改(如果尚未启用)。
- 点击关闭。
在 Actions SDK 中,将更新 intent 定义为 Action 软件包中的触发 intent。
2. 启用更新
如需为您的触发意图开启每日更新,请执行以下操作:
- 在 Actions 控制台中,前往 Develop > Actions。
- 选择您的触发意图。如果您的 intent 未显示在列表中,请确保已将其配置为触发 intent,并且 Dialogflow 的 Google 助理集成已设置为自动预览更改。
- 向下滚动到用户互动部分,然后启用您希望为用户提供每日更新。
- 输入内容标题。
- 点击保存。
现在,您已将 Action 配置为为 intent 提供每日更新订阅。您现在可以在自己的移动设备上测试每日更新。
自定义更新注册(可选)
除了建议条状标签和由 Google 助理处理的每日更新注册流程之外,您还可以使用自己的对话框和注册提示为用户订阅每日更新。
如需查看用于处理可选每日更新功能的完整 Action 示例,请参阅 Actions on Google 用户互动示例(Node.js 和 Java)。
如需向您的对话添加自定义每日更新注册提示,请按照以下说明操作:
1. 添加注册提示
当您想要提示用户订阅每日更新时,请向对话中添加对话框和建议条状标签。在用户与您的更新 intent 互动后提供这些提示,以便用户了解每日更新的内容。
以下示例代码会提示用户订阅提供每天最低预期温度的每日更新:
app.intent('Daily Lowest Temperature', (conv, params) => { const today = DAYS[new Date().getDay()]; const lowestTemperature = lowestTemperatures[today]; conv.ask(`The lowest temperature for today is ${lowestTemperature}`); conv.ask('I can send you daily updates with the lowest temperature' + ' of the day. Would you like that?'); conv.ask(new Suggestions('Send daily updates')); });
@ForIntent("Daily Lowest Temperature") public ActionResponse dailyLowestTemperature(ActionRequest request) { ResponseBuilder responseBuilder = getResponseBuilder(request); Integer lowestTemperature = LOWEST_TEMPERATURES.get(LocalDate.now().getDayOfWeek()); responseBuilder .add("The lowest temperature for today is " + lowestTemperature + " degrees Fahrenheit.") .add("I can send you daily updates with the lowest temperature of " + "the day. Would you like that?") .addSuggestions(new String[] { "Send daily updates" }); return responseBuilder.build(); }
请注意,以下 JSON 描述了 webhook 响应。
{ "payload": { "google": { "expectUserResponse": true, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "The lowest temperature for today is 75 degrees Fahrenheit" } }, { "simpleResponse": { "textToSpeech": "I can send you daily updates with the lowest temperature of the day. Would you like that?" } } ], "suggestions": [ { "title": "Send daily updates" } ] } } } }
请注意,以下 JSON 描述了 webhook 响应。
{ "expectUserResponse": true, "expectedInputs": [ { "possibleIntents": [ { "intent": "actions.intent.TEXT" } ], "inputPrompt": { "richInitialPrompt": { "items": [ { "simpleResponse": { "textToSpeech": "The lowest temperature for today is 75 degrees Fahrenheit" } }, { "simpleResponse": { "textToSpeech": "I can send you daily updates with the lowest temperature of the day. Would you like that?" } } ], "suggestions": [ { "title": "Send daily updates" } ] } } } ] }
2. 处理更新注册
设置一个在用户遵循注册提示时触发的新 intent。在这个新 intent 的执行方式中,使用以下参数触发 actions_intent_CONFIGURE_UPDATES
内置 intent:
intent
- 设置为您配置的更新 intent。frequency
- 设置为“DAILY”。
以下代码会注册“每日最低温度” intent 的每日更新:
app.intent('Subscribe to Daily Updates', (conv) => { conv.ask(new RegisterUpdate({ intent: 'Daily Lowest Temperature', frequency: 'DAILY', })); });
conv.ask(new RegisterUpdate({ intent: 'Daily Lowest Temperature', frequency: 'DAILY', }));
@ForIntent("Subscribe to Daily Updates") public ActionResponse subscribeToDailyUpdates(ActionRequest request) { ResponseBuilder responseBuilder = getResponseBuilder(request); return responseBuilder.add(new RegisterUpdate() .setIntent("Daily Lowest Temperature") .setFrequency("DAILY")) .build(); }
ResponseBuilder responseBuilder = getResponseBuilder(request); return responseBuilder.add(new RegisterUpdate() .setIntent("Daily Lowest Temperature") .setFrequency("DAILY")) .build();
{ "payload": { "google": { "expectUserResponse": true, "systemIntent": { "intent": "actions.intent.REGISTER_UPDATE", "data": { "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec", "intent": "Daily Lowest Temperature", "triggerContext": { "timeContext": { "frequency": "DAILY" } } } } } } }
{ "expectUserResponse": true, "expectedInputs": [ { "possibleIntents": [ { "intent": "actions.intent.REGISTER_UPDATE", "inputValueData": { "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec", "intent": "Daily Lowest Temperature", "triggerContext": { "timeContext": { "frequency": "DAILY" } } } } ] } ] }
3. 处理结果
Google 助理会接管您的对话,并引导用户完成其余的每日更新配置。注册完成后,Google 助理会触发一个 intent,其中包含一个用于表明注册是否成功的参数。
此步骤的说明有所不同,具体取决于您使用的是 Dialogflow 还是 Actions SDK 进行开发。
请按照以下步骤创建用于处理注册结果的 intent:
- 在 Dialogflow 控制台中,创建一个新的意图。
- 添加
actions_intent_REGISTER_UPDATE
事件。 - 为该 intent 启用 webhook 执行方式。
- 点击保存。
registered
参数,并相应地转换对话。
app.intent('Confirm Daily Updates Subscription', (conv, params, registered) => { if (registered && registered.status === 'OK') { conv.close(`Ok, I'll start giving you daily updates.`); } else { conv.close(`Ok, I won't give you daily updates.`); } });
@ForIntent("Confirm Daily Updates Subscription") public ActionResponse confirmDailyUpdatesSubscription(ActionRequest request) { ResponseBuilder responseBuilder = getResponseBuilder(request); if (request.isUpdateRegistered()) { responseBuilder.add("Ok, I'll start giving you daily updates."); } else { responseBuilder.add("Ok, I won't give you daily updates."); } return responseBuilder.endConversation().build(); }
{ "payload": { "google": { "expectUserResponse": false, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "Ok, I'll start giving you daily updates." } } ] } } } }
在您的执行方式代码中,添加对 actions.intent.REGISTER.UPDATE
内置 intent 的处理。请检查 registered
参数获取结果,并相应地透视对话。
app.intent('actions.intent.REGISTER_UPDATE', (conv, params, registered) => { if (registered && registered.status === 'OK') { conv.close(`Ok, I'll start giving you daily updates.`); } else { conv.close(`Ok, I won't give you daily updates.`); } });
@ForIntent("actions.intent.REGISTER_UPDATE") public ActionResponse confirmDailyUpdatesSubscription(ActionRequest request) { ResponseBuilder responseBuilder = getResponseBuilder(request); if (request.isUpdateRegistered()) { responseBuilder.add("Ok, I'll start giving you daily updates."); } else { responseBuilder.add("Ok, I won't give you daily updates."); } return responseBuilder.endConversation().build(); }
{ "expectUserResponse": false, "finalResponse": { "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "Ok, I'll start giving you daily updates." } } ] } } }
对最新动态进行个性化设置(可选)
如需对您的更新 intent 进行个性化设置,请在用户注册每日更新时添加自定义参数。当您执行更新 intent 时,请引用这些参数来为该用户自定义每日更新。
此功能的说明会有所不同,具体取决于您使用的是 Dialogflow 还是 Actions SDK 进行开发。
定义一个 Dialogflow 实体来处理更新的自定义参数,然后将该参数的值作为更新 intent 的参数进行传递。如需在 Dialogflow 中设置个性化更新,请执行以下步骤:
- 在 Dialogflow 控制台中,创建一个新实体。
- 添加一些与您的参数相关的条目和同义词。
- 点击 Save,然后打开更新 intent。
- 在操作和参数部分,将
actions.intent.CONFIGURE_UPDATES
设置为事件。在同一部分中,添加一个与新实体具有相同类型的参数。 - 打开处理
CONFIGURE_UPDATES
内置 intent 的“更新注册” intent。 - 在操作和参数部分,添加必需参数并将其类型设置为之前创建的实体。
- 更新注册 intent 的执行方式代码,以添加一个包含以下内容的
arguments
对象:name
- Dialogflow 中配置的参数名称。textValue
- 您的参数值。
以下代码会读取该参数的值,并在更新注册请求中使用该值:
app.intent('setup_update', (conv) => { conv.ask(new RegisterUpdate({ intent: 'update_of_the_day', arguments: [ { name: 'category', textValue: 'Daily_lowest_temperature', }, ], frequency: 'DAILY', })); });
@ForIntent("setup_update") public ActionResponse setupUpdate2(ActionRequest request) { List<Argument> args = Arrays.asList( new Argument() .setName("category") .setTextValue(request.getParameter("category").toString())); return getResponseBuilder(request) .add(new RegisterUpdate().setIntent("intent_name").setArguments(args).setFrequency("DAILY")) .build(); }
{ "payload": { "google": { "expectUserResponse": true, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "PLACEHOLDER" } } ] }, "userStorage": "{\"data\":{}}", "systemIntent": { "intent": "actions.intent.REGISTER_UPDATE", "data": { "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec", "intent": "update_of_the_day", "arguments": [ { "name": "category", "textValue": "Daily_lowest_temperature" } ], "triggerContext": { "timeContext": { "frequency": "DAILY" } } } } } }, "outputContexts": [ { "name": "/contexts/_actions_on_google", "lifespanCount": 99, "parameters": { "data": "{}" } } ] }
在 intent 执行方式中向用户请求其他信息,然后将这些信息作为更新 intent 的参数进行传递。 如需在 Actions SDK 中设置个性化更新,请按以下步骤操作:
- 提示用户输入您希望用于个性化的信息。
- 在处理
CONFIGURE UPDATES
的“更新注册”intent 的执行方式代码中,添加一个包含以下内容的arguments
对象:name
- 参数的名称。textValue
- 以参数形式传递的用户信息。
以下代码通过更新注册请求发送参数:
app.intent('actions.intent.TEXT', (conv) => { if (conv.input.raw === 'Send daily') { conv.ask(new RegisterUpdate({ intent: 'update_of_the_day', arguments: [ { name: 'category', textValue: 'Daily_lowest_temperature', }, ], frequency: 'DAILY', })); } });
@ForIntent("actions.intent.CONFIGURE_UPDATES") public ActionResponse configureUpdatesActionsSdk(ActionRequest request) { List<Argument> args = Arrays.asList( new Argument() .setName("category") .setTextValue(request.getParameter("category").toString())); return getResponseBuilder(request) .add(new RegisterUpdate().setIntent("intent_name").setArguments(args).setFrequency("DAILY")) .build(); } @ForIntent("actions.intent.TEXT") public ActionResponse text(ActionRequest request) { ResponseBuilder rb = getResponseBuilder(request); String input = request.getRawInput().getQuery(); if (input.equals("DAILY_NOTIFICATION_SUGGESTION")) { rb.add("For which category do you want to receive daily updates?"); } else { rb.add("Sorry, I didn't get that. Please try again later").endConversation(); } return rb.build(); }
{ "expectUserResponse": true, "expectedInputs": [ { "inputPrompt": { "richInitialPrompt": { "items": [ { "simpleResponse": { "textToSpeech": "PLACEHOLDER" } } ] } }, "possibleIntents": [ { "intent": "actions.intent.REGISTER_UPDATE", "inputValueData": { "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec", "intent": "update_of_the_day", "arguments": [ { "name": "category", "textValue": "Daily_lowest_temperature" } ], "triggerContext": { "timeContext": { "frequency": "DAILY" } } } } ] } ], "conversationToken": "{\"data\":{}}", "userStorage": "{\"data\":{}}" }
当用户调用您的每日更新时,您的更新 intent 现在包含的参数包含用户在注册期间提供的值。使用这些值可为每个用户个性化更新。
测试每日更新
使用安装了 Google 助理的移动设备,使用您构建 Action 时所用的 Google 帐号来测试每日更新。调用您的 Action 并订阅每日更新,然后在更新时间前后查看设备的通知。