- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些意图需要触发 fulfillment webhook 并且不关心响应。 webhook 响应的时间比超时时间长,因此我希望仅用“感谢聊天”进行响应,然后在实际触发 webhook 时关闭对话。
感觉很简单,但我错过了一些东西。我也是 dialogflow 的新手。
我可以用任何语言做到这一点,但这里有一个 Javascript 的例子:
fdk.handle(function (input) {
// Some code here that takes 20 seconds.
return {'fulfillmentText': 'i can respond but I will never make it here.'}
});
编辑 1 - 尝试异步
当我使用异步函数时,POST 请求永远不会发生。所以在下面的代码中:
fdk.handle(function (input) {
callFlow(input);
return { 'fulfillmentText': 'here is the response from the webhook!!' }
});
async function callFlow(input) {
console.log("input is --> " + input)
var url = "some_url"
console.log("Requesting " + url)
request(url, { json: true, headers: {'Access-Control-Allow-Origin' : '*'} }, (err, res, body) => {
if (err) { return console.log(err); }
console.log("body is...")
console.log(body)
});
}
我在日志中看到了两个 console.log 输出,但请求中没有任何内容。而且请求似乎也没有发生,因为我没有在我的端点看到它。
解决方案
感谢 Prisoner 的提示。似乎我需要通过 callFlow() 和 handle() 函数返回履行 JSON。现在 Google Home 不会超时,并且会生成 HTTP 调用和响应。
const fdk = require('@fnproject/fdk');
const request = require('request');
fdk.handle(function (input) {
return callFlow(input);
});
async function callFlow(input) {
var searchPhrase = input || "cats"
var url = "some url"
return new Promise((resolve, reject) => {
request.post(url, {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body: searchPhrase
},
function (err, resp, body) {
if (err) { return console.log(err) }
r = { 'fulfillmentText': `OK I've triggered the flow function with search term ${searchPhrase}` }
resolve(r)
}
);
});
}
最佳答案
您不能异步触发履行。在对话模型中,预计履行将执行一些决定响应的逻辑。
但是,您可以在返回结果之前未完成的实现中执行异步操作。
如果您使用的是足够现代的节点版本(版本 8 及更高版本),您可以通过将函数声明为 async
函数来实现,但不调用它带有 await
关键字。 (如果您使用 await
调用它,它会在继续之前等待异步操作完成。)
因此,根据您的示例,这样的事情应该可行:
async function doSomethingLong(){
// This takes 20 seconds
}
fdk.handle(function (input) {
doSomethingLong();
return {'fulfillmentText': 'This might respond before doSomethingLong finishes.'}
});
根据您的代码示例更新 1。
您报告说对 request
的调用似乎根本没有完成,这似乎很奇怪,但有一些奇怪的事情可能会导致它。
首先,request
本身不是异步函数。它使用回调模型,async
函数不会自动等待调用这些回调。所以你的 callFlow()
函数调用 console.log()
几次,调用 request()
并在回调被回调之前返回.
您可能应该将 request
替换为类似 request-promise-native 的内容打包并等待您从电话中获得的 promise 。这使得 callFlow()
真正异步(并且您可以在它完成调用时进行记录)。
其次,我要指出您显示的代码没有执行 POST 操作。它默认执行 GET。如果您或您正在调用的 API 期待 POST,那可能是错误的来源。但是,我希望填充 err
参数,并且您的代码看起来确实会检查并记录此内容。
整个设置中的一个未知数,对我来说,是我不知道 fdk
是如何处理异步函数的,而且我粗略地阅读了文档也没有教我。我已经使用其他框架完成了此操作,这不是问题,但我不知道 fdk
处理程序是否超时或执行其他操作以在发送回复后终止调用。
关于dialogflow-es - 从意图异步触发实现 webhook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54497126/
作为后续问题:Laravel Redirect::intended() conditional fallbacks 我遇到了一个问题,在设置了预期的 URL session 后,即使用户决定不登录而是
我面临一个问题,即与任何意图不匹配的单词,它会假设它属于标记最多的话语的意图。 示例:如果 意图 A 由动物等话语组成 意图 B 包含“水果”等话语 意图 C 由诸如昆虫之类的话语组成 意图 D 由诸
拥有什么实际区别 subroutine fillName(person) type(PersonType), intent(inout) :: person person%name = "
我想知道 Dialogflow 中是否有任何商定的意图、事件和上下文的命名约定。 如果没有,那么如果您分享您自己的命名约定,我将不胜感激! 最佳答案 我发现“只要别人容易理解就行”这句话有点矛盾。如果
我正在尝试了解使用队列的用例。 我的理解:队列意味着一对一。唯一的用例(如果不是罕见的话,很少)是:消息仅供一次使用。 但即使在这些情况下,我也可能想使用主题(只是为了将来安全)。唯一需要额外注意的是
我的 Xcode 是 v10,我正在为 SiriKit 开发一个针对 iOS 12 的自定义 intent。 在 Xcode 10 中,自定义意图是在 .intentdefinition 文件中设计的
我有一个设置了 .intentdefinition 文件的 WidgetKit ,我可以在运行我的 WidgetKit 时从我的枚举中进行选择,但我不确定如何在代码中使用这些信息。 我希望能够根据用户
我需要为意图过滤器注册(在运行时)自定义 BroadcastReceiver 可以在 list 中描述为 并在用户通过按应用程序中的某个按钮退出应用程序时取消注册接收
根据 Fortran 标准: The INTENT (OUT) attribute for a nonpointer dummy argument specifies that the dummy a
我正在使用 Twitter Web Intents 来检查是否有人关注我。现在的问题是;我只在事件对象中获取我自己的屏幕名作为回调。 twttr.events.bind('follow', funct
编辑 很抱歉大家,这只是由于意图名称后面缺少逗号。非常抱歉x: 我最近使用 Microsoft Bot Framework (botbuilder v3.14.0)、Node.js (v8.9.4)
我正在开发的产品: RequeSTLy - Chrome 和 Firefox 扩展设置重定向、修改 header 、切换主机、插入用户脚本 ( https://www.requestly.in/ )
有什么方法可以有目的地合并对话框,这样我就不需要多余的代码片段? bot.dialog('whats-your-name', require('./dialogs/whats-your-name')
我是 Dialogflow 的新手,虽然它很容易理解,但我无法使用自定义事件触发 Intent。 我必须实现的任务是,当在后端 Node.js Webhook 中检测到警报时(例如:老板想要做某事),
在 Microsoft Bot Framework 中,我已经开始对话并运行一些意图,假设“登录”,但是当我向用户询问用户名或密码时,他可能会说“取消该”或“取消登录”,我如何获得此意图:“取消”以及
我使用 LUIS 框架构建了一个运行良好的机器人。在研究过程中遇到了以下几点 与 LUIS 意图连接后;机器人无法检查正则表达式意图喜欢 对于我正在尝试设置的对话框.matches('^helpdes
我想知道 URL 是发布到 facebook 的链接。在 Twitter 上,我可以使用“http://twitter.com/intent/tweet?text=”来发推文。虽然我试图寻找一个,但我
通读,http://www.w3schools.com/angular/angular_directives.asp我遇到了一个在评论中调用指令的例子,具体来说: 您可以在 http://www.w
我在 Stack Overflow 上的许多帖子中读到,可分配数组在传递到虚拟参数为 intent(out) 的子例程中时会被释放。 如果我考虑以下代码: program main real, di
API.ai 的预构建包可让您轻松获得长长的意图列表。目前,我正在尝试利用他们的 smalltalk 包,该包有大约 100 个意图,并对每个意图做出响应。 我正在使用api-ai-recognize
我是一名优秀的程序员,十分优秀!