Button to open web view on Facebook Messenger keeps opening a browser, on mobile and desktop
I've created Facebook Messenger Bot, created a Test Page and a Test App, currently receiving webhooks from every message on DialogFlow, which respond correctly to the first message, in which i return a DialogFlow card, with a button, this button supposed to open a webview, but keeps opening a browser tab, on mobile and desktop, now, i'm aware for open a webview on desktop the are some modifications to the code that need to be made but mobile should be working by now and that is not the case. I'm following this flow: https://cloud.google.com/dialogflow/docs/images/fulfillment-flow.svg)
This the webhook response sent from my Django instance to DialogFlow:
"fulfillmentMessages": [
{
"card": {
"title": "aaa bbb ccc",
"platform": "facebook",
"subtitle": "card text",
"imageUri": "https://ucarecdn.com/6a3aae10-368b-418f-8afd-ed91ef15e4a4/aaaa_bbb_ccc.png",
"buttons": [
{
"type": "web_url",
"text": "Get Recipe",
"postback": "https://assistant.google.com/",
"webview_height_ratio":"compact",
"messenger_extensions": "true"
}
]
}
}],}
This is the view for responding to postback
button:
@csrf_exempt
def get_recipe(request):
"""
"""
response = render(request, "recipe_item.html")
response['X-Frame-Options'] = 'ALLOW-FROM https://messenger.com/ https://www.facebook.com/ https://l.facebook.com/'
response['Content-Type'] = 'text/html'
return response
And this is the Messenger Extensions SDK
been installed on the HTML for the view corresponding to the webview:
<html>
<head>
<title>Choose your preferences</title>
</head>
<body>
<script>
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.com/en_US/messenger.Extensions.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'Messenger'));
window.extAsyncInit = function() {
// the Messenger Extensions JS SDK is done loading
MessengerExtensions.getSupportedFeatures(function success(result) {
let features = result.supported_features;
if (features.indexOf("context") != -1) {
MessengerExtensions.getContext('375919546670588',
function success(thread_context) {
// success
document.getElementById("psid").value = thread_context.psid;
// More code to follow
},
function error(err) {
console.log(err);
console.log(err.message);
}
);
}
}, function error(err) {
console.log(err.message);
});
};
</script>
...
</body>
</html>
The end result should be a web view been opening when Get Recipe
button is pushed
EDIT: i just try sending this custom payload to DialogFlow and no webview, button keeps opening browser instead.
{
"fulfillmentMessages": [
{
"payload": {
"facebook": {
"attachment": {
"type":"template",
"payload":{
"template_type":"button",
"text":"Try the URL button!",
"buttons":[
{
"type":"web_url",
"url":"https://www.messenger.com/",
"title":"URL Button",
"webview_height_ratio": "full"
}
]
}
}
}}
}]}