【发布时间】:2021-03-22 02:30:38
【问题描述】:
我计划为具有 uid 的特定用户将数据保存在“medic_reminder”集合中。但我不知道如何通过我的应用程序传递当前登录的用户 uid。
这里是 Dialogflow 实现的 index.js,这里我已经指定了用户 uid:
async function handlerSaveFromDB(agent){
const medicName = agent.parameters.medicName;
const quantityTime = agent.parameters.quantiy;
const dateEnded = agent.parameters.dateEnded;
const dosage = agent.parameters.dosage;
const timeFormat = agent.parameters.time;
const time = new Date(timeFormat);
const minutes = time.getMinutes();
const hour = time.getHours() -16;
const ref = db.collection('users').doc('wM4uxxxxxxx').collection('medic_reminder').doc('5');
const data = {
dateEnded: new Date(dateEnded),
dosage: dosage,
hour: hour,
howManyTimeDay: 0,
id: '5',
medName: medicName,
min: minutes,
quantityTime: quantityTime,
status: true
};
const res = await ref.set(data);
response.json({
fulfillmentText: `Your reminder was saved`
});
}
这是我的 Dialogflow 请求:
Future<AIResponse> detectIntent(String query) async {
String queryParams = '{"resetContexts": ${this.resetContexts} }';
if (payload.isNotEmpty) {
queryParams =
'{"resetContexts": ${this.resetContexts}, "payload": $payload}';
}
String body =
'{"queryInput":{"audioConfig":{"languageCode":"$language"}},"outputAudioConfig":{"audioEncoding":"OUTPUT_AUDIO_ENCODING_LINEAR_16"}, "inputAudio":"$query","queryParams": $queryParams}';
var response = await authGoogle.post(_getUrl(),
headers: {
HttpHeaders.authorizationHeader: "Bearer ${authGoogle.getToken}"
},
body: body);
return AIResponse(body: json.decode(response.body));
}
}
请帮助我提供有关如何获取登录用户 uid 的任何建议。谢谢
【问题讨论】:
-
您的应用程序中应该有您的用户 ID,该应用程序从 Flutter 与 Dialogflow 进行通信。在detectIntent 请求中,您可以使用QueryParameters 中的
payload字段来发送履行信息。能否分享一下flutter与dialogflow通信的代码? -
谢谢@tlaquetzal,我用 Dialogflow 请求更新了问题。
标签: flutter dialogflow-es dialogflow-es-fulfillment