The fetch method does not work when scraping with cheerio-httpcli in actions on google

Asked 1 years ago, Updated 1 years ago, 91 views

This is my first time to ask a question.
At Google Home, I'm creating an app that tells you which characters are disadvantageous to the characters in a match game.
It is being processed through Dialogflow's Webhook (firebase).

In index.js, when you enter a voice at <Character Name > Counter,

located on this statistics site (http://jp.op.gg/champion/<Character name>/statistics/) Scrap the character name at the top of the Weakagainst column and return it to Google Assistant.

I use a module called cheerio-httpcli for scraping.

However, it seems that the fetch method, which is the part of the scraping process, is not being processed.
The app.ask in the fetch method is not working and the variable name is undefined.
Note that the firebase deploy --only functions command has no errors.

I did well when I extracted only the scraping part and console it out in a separate file.
It doesn't work when combined with actions on google or firebase.
Please teach me.

index.js

'use strict';

process.env.DEBUG='actions-on-google:*';
const {DialogflowApp} = require('actions-on-google');
const functions = require('firebase-functions');

exports.yourAction=functions.https.onRequest(request,response)=> 
{
  const app = new DialogflowApp({request, response});

  const WELCOME_INTENT = 'input.welcome';
  constUNKNOWN_INTENT = 'input.unknown';
  constEND_INTENT = 'default_end_intent';
  const CHAMPION_COUNTER = 'Champion_Counter';

  varclient=require('cheerio-httpcli');

  console.log('Request headers:' + JSON.stringify(request.headers)));
  console.log('Request body:'+JSON.stringify(request.body)));

  // Fulfill action business logic
  function responseHandler(app){
    // Complete your fulfillment logic and send a response
    let intent=app.getIntent();

    switch(intent){
        caseWELCOME_INTENT:
            app.ask('Welcome to LoLSmartCall');
            break;

        caseUNKNOWN_INTENT:
            app.ask('Please do it again'');
            break;

        case END_INTENT:
            app.tell('Thank you');
            break;

        caseCHAMPION_COUNTER:
            let requestChampionName=app.getArgument('LOL-Champions'); // Contains the name of the voice-entered character (champion)
            let name = counterResearch(requestChampionName);
            The champion who is not good at app.ask(requestChampionName+' is '+name+'.');

            break;

    }
  }

  app.handleRequest (responseHandler);

  function counterResearch(requestName){
      varurl='http://jp.op.gg/champion/'+requestName+'/statistics/';
      // I've confirmed that it's working up to here

      // TODO ここ Does not move from here
      client.fetch(url,{}, function(err,$,res,body){

          $('.SideContent').each(function(idx){
              // console.log('Weakagainst');
              app.ask('It's working'); // Not moving
              varchampionName=$(this).find('.ChampionName') .eq(0).text();
          });
          return championshipName;
      });
  }
});

simulator

node.js firebase web-scraping

2022-09-30 19:35

2 Answers

Are Firebase plans charged or flat-rate?
The free plan, Cloud Functions, is limited to external communications on non-Google networks.

https://firebase.google.com/pricing/

There is a free quota for the pay-as-you-go plan, so I'll switch to that one.
Communicate via another Google product, such as AppEngine.


2022-09-30 19:35

I managed to understand something with the help on Google translate.
I'm currently working on a project where the focus is the same, that is scraping some information from a partial website and make google assistant tell them in your Action.
I have the same problem and didn't manage to find a solution, even with pricing enabled and everything set right. If you have managed to do it, please let me know, if you haven't, I will link you a project on GitHub where this guy managed to do it, but for not yet. Here you are and Lemme know!
https://github.com/fgandiya/virtual-jo

Japanese translation:

I tried to understand the question using Google translation.
I am working on a similar project now.In other words, I'm trying to script the information from a particular website and get Action to Google Assistant.
I encountered the same problem, and I paid for it and set it up correctly, but it didn't solve it.Please let me know if you have solved the problem.Also, if you don't know, I'll link the project on GitHub that someone says they've solved.However, I don't know why he was able to solve this problem...
This is the project!
https://github.com/fgandiya/virtual-jo


2022-09-30 19:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.