在对话流中的请求和欢乐的问题 [英] problems with request and cheerio in dialogflow

查看:45
本文介绍了在对话流中的请求和欢乐的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是能够在对话框流Webhook中使用request-promise-native和cheerio来从网站上抓取一些文章,我尝试了几种方法,但始终无法解决。

What I'm trying to do is to be able to use request-promise-native and cheerio in my dialogflow webhook to scrape some articles from a website, I've tried several ways but never been able to work it out.

我最后一次尝试是按照帖子,但我无法使其正常工作。

My last attempt was doing as suggested in this post, but i could not make it work.

如果您想看一下我的代码,这里是我的代码写道,并带有一些解释: https://github.com/Vaelthur/webscraping- with-dialogflow-incomplete

If you want to have a look at my code, here it is the code i wrote, with a bit of explanation: https://github.com/Vaelthur/webscraping-with-dialogflow-incomplete

推荐答案

问题出在注册到 scrpwb的函数中意向。

您正在呼叫 prova_promise ,这将返回一个Promise(正确) !),但本身不会返回Promise。因此,该函数不返回任何内容,该值将由处理程序立即处理,而不是等待Promise完成。

You are calling prova_promise, which returns a Promise (which is correct!), but does not itself return a Promise. So the function returns nothing, which is handled immediately by the handler rather than waiting for the Promise to complete.

解决方案很简单-确保它返回一个Promise,您可以可以做类似的事情

The solution is simple - make sure it returns a Promise which you can do with something like

  return prova_promise().then((message) => {

,其余部分完全相同。

这篇关于在对话流中的请求和欢乐的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆