problems with request and cheerio in dialogflow

2019-07-11 07:02发布

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.

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

1条回答
贼婆χ
2楼-- · 2019-07-11 07:28

The problem is in the function registered to the scrpwb intent.

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.

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

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

and the rest being exactly the same.

查看更多
登录 后发表回答