I am stuck here. I am trying to get a postback from a Webview opened in a Facebook Messenger chatbot that I am developing with DialoFlow's fulfillment library using NodeJS.
I am able to send a payload that opens a specific URL like below:
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "So you want to open the webview huh?",
"buttons": [{
"type": "web_url",
"url": "https://somewebsiteurlwithdataiwanttoget.como",
"title": "Open Website",
"messenger_extensions": true // To get psid and close window event
}]
}
}
}
}
In my webview I am able to submit a form and get the data from that form using jQuery Ajax:
let jqxhr = $.ajax({
url: '/webhook', // Fires my webhook
data: { var1: 'Hello', var2: 'World' }, // Sent to my webhook
dataType: 'json'
});
In my webook, I initialize my agent and send this data back to the Messenger Bot using a custom event (PS: I am using Express).
// The webhook that receives post data from the form in my webview
router.post('/', function (req, res, next) {
// Initialize Agent
const agent = new WebhookClient({ request: req, response: res })
// Handle the intent
let intentMap = new Map()
// Set default handle if there are no intents
intentMap.set(null, handle)
// Handle stuff from the form
agent.handleRequest(intentMap)
function handle (agent) {
agent.add(`Just a test to see if this message gets to messenger`)
}
})
However, I get an error in my console saying "This request is not a valid Dialogflow request
". I am not sure what I am doing wrong and I hope someone can help me out there.
Thank you.