我们正在使用Firebase云功能来实现目标,并使用外部rest api来进行原始操作。
我们打算进行一些后续跟踪,看起来像这样
- Create Note
- - Create Note - fallback*
- - - Create Note - fallback - yes
- - - Create Note - fallback - no
* the fallback allows us to capture free text
在我们的网络挂钩中,我实现了以下目标
app.intent("Create Note", (conv) => {
if (!conv.user.storage.note) conv.user.storage.note = {};
conv.ask("Go ahead, talk to Talkatoo!");
});
app.intent("Create Note - fallback", (conv) => {
conv.user.storage.input = conv.input.raw;
let response = conv.user.storage.note
? conv.user.storage.note.body.concat(conv.input.raw)
: conv.user.storage.input;
conv.ask("So far this is what I heard you say, let me know if this is complete. ", response);
});
app.intent("Create Note - fallback - yes", (conv) => {
// based on the conv.user.storage.note object
// either make a call to create a note or update a note
// make call to external api and based on the response
// set the value for conv.user.storage.note
conv.ask("Great news, let me save that for you!");
});
app.intent("Create Note - fallback - no", (conv) => {
// based on the conv.user.storage.note object
// either make a call to create a note or update a note
// make call to external api and based on the response
// set the value for conv.user.storage.note
// Send the user back to Create Note to capture the rest of their input
conv.followup("my_custom_event");
});
问题是当我从API获得响应时,conv.user.storage.note
被设置了,但是随后它被重置为空,因此每次都创建一个新注释。我正在尝试将用户的各种输入附加为一个便笺
答案 0 :(得分:0)
基于...
app.intent("Create Note - fallback - yes", (conv) => {
// based on the conv.user.storage.note object
// either make a call to create a note or update a note
// make call to external api and based on the response
// set the value for conv.user.storage.note
conv.ask("Great news, let me save that for you!");
});
您似乎尚未编写API调用的代码,或者在发布到StackOverflow上之前已删除了该代码。正确吗?
您能否更新问题以显示将HTTP请求发送到外部REST API的位置和方式?
答案 1 :(得分:0)
对于可能最终对您有所帮助的任何人,我发现了一条帖子,并意识到处理异步调用的响应可能需要更多的思考(以解决问题)How to make asynchronous calls from external services to actions on google?
对于我们的用例,我们不需要响应数据,即,我们不需要将任何响应数据传达给用户,因此我们将用户的多个输入保存在user.storage中,并在它们完成时保存我们保存了完整的回复。
app.intent("Intent - fallback", (conv) => {
conv.user.storage.input = conv.user.storage.input
? conv.user.storage.input.concat(conv.input.raw)
: conv.input.raw;
conv.ask("Is that complete or would you like to continue?");
});
app.intent("Intent - fallback - yes", (conv) => {
createNote(conv); <--- makes call to save
conv.ask("Great news, let me save that for you!");
});
app.intent("Intent - fallback - no", (conv) => {
conv.followup("my_custom_event");
});