0

I am trying to use Request-Promise-Native or Axios but getting error during execution. I am sharing my code. I am using dialogflow inline editior. I also try with post api but not working. I guess somewhere i am doing minor mistake. Please explain also it will help me to learn.

'use strict';
const axios = require('axios'); 
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const request = require('request-promise-native');
 
// this is GET api using axios
 function Login(agent) {
    const email = agent.parameters.email;
    const password = agent.parameters.password;
    const baseurl = 'http://demoapi:3000/login/buyerlogin';
    var data = {"email" : email,"password": password};

       return axios.get(baseurl, { params: 
                                  data})
      .then(result => {
            console.log(result.data);
            console.log(`statusCode: ${result.statusCode}`);
            agent.add(result.data);
          }) }

// This Get API using Request promise native
 function Login(agent) {
    const email = agent.parameters.email;
    const password = agent.parameters.password;
    const baseurl = 'http://demoapi:3000/login/buyerlogin';
    var data = {"email" : email,"password": password};
    var sdata = JSON.stringify(data);
    const options = {
          method: 'GET',
          uri: baseurl,
          body: JSON.parse(sdata),
          json: true
          };
       return request(options)
      .then(result => {
            console.log(result.data);
            console.log(`statusCode: ${result.statusCode}`);
            agent.add(result.data);
          });
}

Package.json file

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "10"
  },
  "scripts": {
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^1.2.0",
    "dialogflow-fulfillment": "^0.6.1",
    "request": "^2.88.2",
    "request-promise-native": "^1.0.9",
    "axios": "^0.21.1"
  }
}

Please help me out. Is anything required please let me. Thank You

  • What's the error you're getting? Anyway, you probably don't want to be returning the axios request, since that will be you returning the promise, not the results. You'll want to put your return inside the `then` block. – samuei Mar 07 '21 at 15:59
  • Hi @samuei Not taking parameter in get api – subhajit saha Mar 07 '21 at 16:18
  • Please state the error you are getting. It'll likely be a good indication of the problem ;) – Teresa Mar 08 '21 at 14:28

0 Answers0