Below is my API code
// Import required dependencies
const express = require('express'); const bodyParser = require('body-parser'); const axios = require('axios');
Create Express app
// Import required dependencies
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
// Create Express app
const app = express();
// Configure app to use JSON body parser
app.use(bodyParser.json());
// Define endpoint to handle webhook requests from DialogFlow
app.post('/webhook', async (req, res) => {
try {
// Extract order ID from webhook request
const orderId = req.body.orderId;
// Make POST request to order status API with order ID
const response = await axios.post('https://orderstatusapi-dot-organization-project-311520.uc.r.appspot.com/api/getOrderStatus', {
orderId: orderId
});
// Extract shipment date from API response
const shipmentDate = response.data.shipmentDate;
// Convert shipment date to human-readable format (optional)
const formattedShipmentDate = new Date(shipmentDate).toLocaleDateString('en-US', {
weekday: 'long',
day: 'numeric',
month: 'short',
year: 'numeric'
});
// Construct webhook response
const fulfillmentMessages = `The shipment date for order ID ${orderId} is ${formattedShipmentDate}.`;
const responseJson = {
fulfillmentMessages: fulfillmentMessages
};
// Send webhook response
res.json(responseJson);
} catch (error) {
console.error('Error handling webhook request:', error);
// Send error response
res.status(500).json({ error: 'Internal Server Error' });
}
});
// Start Express app on port 3000
app.listen(3000, () => {
console.log('Server running on port 3000');
});
Now when I'm testing my ngrok API in postman with inputs
{ "orderId":"31313" }
It is giving me the output I'm expecting to give me which is below
{ "fulfillmentMessages": "The shipment date for order ID 31313 is Thursday, Apr 20, 2023." }
But when I'm using this https://074a-111-92-140-57.ap.ngrok.io/webhook API in my DialogFlow ES agent it is not giving me the above expected output
My User Inputs in DialogFlow ES Chatbot Agent are as follows:
User: Hi
Chatbot: Hi, How can I help you?
User: Can I check my order status?
Chatbot: What is your Order ID?
User: My Order ID is "31313"
Chatbot: No Response or Not available
Expected Response: The shipment date for order ID 31313 is Thursday, Apr 20, 2023
Can someone tell me what I am doing wrong???
Above is my DialogFlow ES settings.
Thank you all