1

Here is the code. Added hardcoded values for testing.

Axios added to package.json Enabled fulfillment in Intent.

   
      
  function workerHandler(agent) {
    const {
      name, phone, date
    } = agent.parameters;
   
    const data = [{
      name: "Akash",
      phone: "1234567891",
      date: "5 July"
    }];
    
    axios.post = ('https://sheet.best/api/sheets/------', data);
  }
 
  
  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('saveData', workerHandler);
  // intentMap.set('your intent name here', yourFunctionHandler);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);
});

Please Help.

Prisoner
  • 49,922
  • 7
  • 53
  • 105

1 Answers1

0

There are a number of issues with your code.

First, you seem to be doing assignment to axios.post rather than trying to call it, although the syntax doesn't look right either. It should be something like

axios.post( url, data );

You also need to return the Promise that it (and its then/catch) chain returns so Dialogflow's handler dispatcher knows to wait for the Promise to complete. So that might look something more like

return axios.post( url, data );

but since you want error handling, and you should be sending a response to the user, this might look something more like

return axios.post( url, data )
  .then( () => {
    agent.add( "Saved" );
  })
  .catch( err => {
    console.error( err );
    agent.add( "Something went wrong" );
  });
Prisoner
  • 49,922
  • 7
  • 53
  • 105