简体   繁体   English

在 Dialogflow CX 的 webhooks 中使用异步/等待功能不起作用

[英]Using async/wait functions in webhooks for Dialogflow CX not working

I have linked a function as a webhook to a page on Dialogflow CX and the agent writes out the output of the function correctly.我已将 function 作为 Webhook 链接到 Dialogflow CX 上的页面,代理正确写出 function 的 output。

However, when making the function "async" the chat agent does not write out any text at all.但是,当使 function “异步”时,聊天代理根本不会写出任何文本。 What is the issue here?这里的问题是什么?

So this node.js code functions well:所以这个 node.js 代码运行良好:

function serve_hello_world(){
    const answer = "hello world";
    return answer
}

But when running this asynchrous code as the webhook function nothing is written at Dialogflow CX.但是,当将此异步代码作为 webhook function 运行时,Dialogflow CX 中没有任何内容。

async function serve_hello_world(){
    const answer = await "hello world";
    return answer
}

My guess is that the webhook waits too long, and therefore Dialogflow CX chat agent does not write out anything?我的猜测是 webhook 等待时间过长,因此 Dialogflow CX 聊天代理不会写出任何内容?

I found the error.我发现了错误。 The webhook function calling serve_hello_world() also needs to use async/await.调用 serve_hello_world() 的 webhook function 也需要使用 async/await。

So, firstly the webhook function needs to be assigned to be "async" and secondly there needs to be an "await" before the function call.因此,首先需要将 webhook function 分配为“异步”,其次需要在 function 调用之前进行“等待”。

Hopefully this helps someone else with the same error:)希望这可以帮助遇到同样错误的其他人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM