problems with request and cheerio in dialogflow

折月煮酒 提交于 2019-12-24 02:17:40

问题


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:


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.



来源:https://stackoverflow.com/questions/50446759/problems-with-request-and-cheerio-in-dialogflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!