根据用户位置每日更新
Daily update based on user location
在使用 dialogflow 的 Google Actions 应用程序中,我正在努力设置每日更新,目标是根据用户位置提取数据。我假设要做到这一点,我需要征求用户的许可才能访问他们的位置信息。
这些意图中的哪一个是询问用户位置的正确位置?
// what is the best place to ask a user for access to their location in this scenario?
function locateUser(conv) {
conv.ask(new Permission({
context: 'To locate you',
permissions: 'DEVICE_PRECISE_LOCATION'
}));
}
// initial invocation: "i want the daily weather forecast"
app.intent('daily_weather_updates', (conv) => {
conv.ask(new Suggestions('Send daily weather forecast.'));
});
app.intent('daily_weather_updates.update', (conv) => {
const intent = conv.arguments.get('UPDATE_INTENT');
conv.ask(new RegisterUpdate({
intent: 'get_daily_weather',
frequency: 'DAILY'
}));
});
app.intent('daily_weather_updates.finish', (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.`);
}
});
app.intent('get_daily_weather', (conv) => {
Weather.getDailyWeather().then((response) => {
conv.close(response);
});
});
这取决于您认为用户会想要什么样的天气。他们设置通知时所在位置的单个特定位置的天气,或他们确认通知时所在位置的天气。
如果您希望在同一地点发生这种情况,您可能希望在以下两个地方之一进行:
- 在触发 "daily_weather_updates" Intent 之前。
- 作为对 "daily_weather_updates.finish" 意图的响应的一部分。
您不想在任何中间人处执行此操作,因为他们被问到与设置通知相关的问题。我会倾向于第一个,因为如果他们拒绝许可,您就不需要完成通知设置。在这些处理程序中的任何一个中,您都希望存储返回的位置,因为它仅在他们响应权限时才向您发送信息。
如果您想在他们响应通知时在 "current" 位置报告他们的天气,您将希望在处理程序中为他们确认通知时设置的任何 Intent 执行此操作。您目前已将此设置为 "get_daily_weather",但您需要一个不同的 Intent 来请求许可,然后在获得它后需要一个报告天气。在这种情况下,您只需保存会话的位置,因为您希望它发生变化。
请记住,除非您提出要求,否则 Google 助理不会为您提供位置信息。因此,如果您确实想在以后的对话中使用它(因为您只是请求一次,或者您想将其用作以后的默认设置),则需要存储它。
在使用 dialogflow 的 Google Actions 应用程序中,我正在努力设置每日更新,目标是根据用户位置提取数据。我假设要做到这一点,我需要征求用户的许可才能访问他们的位置信息。
这些意图中的哪一个是询问用户位置的正确位置?
// what is the best place to ask a user for access to their location in this scenario?
function locateUser(conv) {
conv.ask(new Permission({
context: 'To locate you',
permissions: 'DEVICE_PRECISE_LOCATION'
}));
}
// initial invocation: "i want the daily weather forecast"
app.intent('daily_weather_updates', (conv) => {
conv.ask(new Suggestions('Send daily weather forecast.'));
});
app.intent('daily_weather_updates.update', (conv) => {
const intent = conv.arguments.get('UPDATE_INTENT');
conv.ask(new RegisterUpdate({
intent: 'get_daily_weather',
frequency: 'DAILY'
}));
});
app.intent('daily_weather_updates.finish', (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.`);
}
});
app.intent('get_daily_weather', (conv) => {
Weather.getDailyWeather().then((response) => {
conv.close(response);
});
});
这取决于您认为用户会想要什么样的天气。他们设置通知时所在位置的单个特定位置的天气,或他们确认通知时所在位置的天气。
如果您希望在同一地点发生这种情况,您可能希望在以下两个地方之一进行:
- 在触发 "daily_weather_updates" Intent 之前。
- 作为对 "daily_weather_updates.finish" 意图的响应的一部分。
您不想在任何中间人处执行此操作,因为他们被问到与设置通知相关的问题。我会倾向于第一个,因为如果他们拒绝许可,您就不需要完成通知设置。在这些处理程序中的任何一个中,您都希望存储返回的位置,因为它仅在他们响应权限时才向您发送信息。
如果您想在他们响应通知时在 "current" 位置报告他们的天气,您将希望在处理程序中为他们确认通知时设置的任何 Intent 执行此操作。您目前已将此设置为 "get_daily_weather",但您需要一个不同的 Intent 来请求许可,然后在获得它后需要一个报告天气。在这种情况下,您只需保存会话的位置,因为您希望它发生变化。
请记住,除非您提出要求,否则 Google 助理不会为您提供位置信息。因此,如果您确实想在以后的对话中使用它(因为您只是请求一次,或者您想将其用作以后的默认设置),则需要存储它。