I am using the function below in the inline fulfillment section to write the parameters to Google spreadsheet using axios function. But I am getting the error - Dialogflow fulfillment error : Webhook call failed. Error: UNAVAILABLE, State: URL_UNREACHABLE, Reason: UNREACHABLE_5xx, HTTP status code: 500. I have shared the google spreadsheet with the service account connected with Dialogflow Project. The webhook url is a HTTP trigger configured with the same service account. Why am I getting the error?
function ProjectdetailYesIntentHandler(agent){
const {
State,District,Client,Road_Category,Package,Road_Name_or_No,Length_Km,Proposed_Width_m,Existing_width_m,Project_Related_Remark
} = agent.contexts[1].parameters;
const mobile_number = whatsAppno;
const d = new Date();
const SamplerAccessAllowed = agent.contexts[0].parameters.SamplerAccessAllowed ;
const ProjectId = agent.contexts[0].parameters.ProjectId;
const samplingactivity = "Project_details";
const data = [{
Timestamp : d,
mobile_number: mobile_number,
ProjectId : ProjectId,
State :State,
District : District,
Client : Client,
Road_Category : Road_Category,
Package : Package,
Road_Name_or_No : Road_Name_or_No,
Length_Km : Length_Km,
Proposed_Width_m : Proposed_Width_m,
Existing_width_m : Existing_width_m,
Project_Related_Remark : Project_Related_Remark,
ProfileName : ProfileName,
MessageSid : MessageSid,
SmsMessageSid : SmsMessageSid,
SmsSid : SmsSid,
samplingactivity: samplingactivity
}];
const apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const url = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const headers = {'Content-Type': 'application/json','Authorization': `Bearer ${apiKey}`};
axios.post(url, {data: data}, {headers: headers})
.then(response => {console.log(response);})
.catch(error => {console.log(error);});
}
I have checked the webhook url in a node js code and it worked well with axios function. The webhook url is an HTTP trigger of a google cloud function and it writes the parameters (passed to it in the json object) into the google spreadsheet. In fact it did not need the API Key. Only sharing the sheet with the service account was enough. But the same webhook url did not work with axios function in the Dialogflow inline fulfillment code. Then I added the API Key thinking that API Key might be needed in case of invocation from Dialogflow. But even that did not solve the problem.
I will be grateful to receive help in solving this problem i.e. making the webhook url to work to write into the google spreadsheet.