首页 > 解决方案 > 擦除/删除/清除要替换的简单响应文本(非连接)

问题描述

在 google library 上的 nodejs 操作中,调用.add(text),.ask(text).close(text)on the conversation 将其连接text到简单的文本响应中,即

conv.add('hello');
conv.close('world');
// yields text response "hello world"

这通常很好。但是,我遇到了一个情况,我需要清除添加到简单响应文本中的所有内容,以用一些错误处理响应替换它,即

conv.add('hello');
// something went wrong, need to clear "hello" and replace
conv.ask('sorry, could you repeat your command?');
// yields text reponse "sorry, could you repeat your command?"
// *does not* yield "hello sorry, could you repeat your command?"

我在对话对象上找不到实现此行为的函数。有没有办法我可以手动清除响应以便用新的东西替换它们?

标签: dialogflow-esactions-on-google

解决方案


看起来我可以手动访问Response[]对话对象上的数组并用空数组将其清除。所以,在我的例子中,我可以这样做:

conv.add('hello');
conv.responses = []; // clears out the previously added "hello"
conv.ask('sorry, could you repeat your command?');
// yields text response "sorry, could you repeat your command?"

推荐阅读