title: Bigquery ML in dialogflow with node.js
body: <p>I am a noob in javascript. I don't understand the syntax of promises in dialogflow.</p>
  
  <p>I am trying to make work simple BigQuery call, without success. </p>
  
  <p>It returns the right info at some point in the console, but not in the flow</p>
  
  <p>The example initially comes from this tutorial  "<a href="https://codelabs.developers.google.com/codelabs/cloud-dialogflow-bqml/index.html?index=..%2F..cloudai#4" rel="nofollow noreferrer">https://codelabs.developers.google.com/codelabs/cloud-dialogflow-bqml/index.html?index=..%2F..cloudai#4</a>". I changed a bit the code as i wanted to make it work with "app.intent": <code>exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)</code> instead of "<code>agent.handleRequest(intentMap)</code>"</p>
  
  <p>I have tried to use <code>return new Promise((resolve,reject) =&gt; {</code> and <code>resolve</code>. I spent hours in stackoverflow trying several combinations of code, but none worked.</p>
  
  <pre><code>const ticketCollection=(conv,EMAIL,CATEGORY) =&gt; {
  
    // The SQL Query to Run
    const SQLQUERY = `WITH pred_table AS (SELECT 5 as seniority, "3-Advanced" as experience,
            "${CATEGORY}" as category, "Request" as type)
            SELECT cast(predicted_label as INT64) as predicted_label
            FROM ML.PREDICT(MODEL helpdesk.predict_eta,  TABLE pred_table)`;
  
    const OPTIONS = {
      query: SQLQUERY,
      // Location must match that of the dataset(s) referenced in the query.
      location: "US",
      params: {
        category: CATEGORY
      }
    };
    console.log("options",OPTIONS);
    return new Promise((resolve,reject) =&gt; {
      BIGQUERY_CLIENT.query(OPTIONS)
        .then(results =&gt; {
          //Capture results from the Query
          console.log(JSON.stringify(results[0]));
          const QUERY_RESULT = results[0];
          const ETA_PREDICTION = QUERY_RESULT[0].predicted_label;
          console.log("results",QUERY_RESULT);
          console.log("eta",ETA_PREDICTION);
          resolve();
          reply(conv,`Thanks a lot, we will get back to you in ${ETA_PREDICTION} minutes`);
        });
    });
  };
  
  
  app.intent('Submit Ticket', (conv) =&gt; {
    console.log("Parameters", conv.parameters);
    const EMAIL = conv.parameters.email;
    const CATEGORY = conv.parameters.category;
    ticketCollection(conv,EMAIL,CATEGORY);
  });
  
  </code></pre>
  
  <p>I want the chatbot to return the expected time. Again, I am a noob in javascript. Any suggestions or obervations would be much appreciated ! Thank you so much in advance !</p>