I'm trying to make a share from the webview of my bot. Here's my code
var messageToShare = {
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"image_aspect_ratio":"square",
"elements":[
{
"title":"Welcome to Peter\'s Hats",
"subtitle":"We\'ve got the right hat for everyone.",
"image_url":"https://pbs.twimg.com/profile_images/735453447718338561/9W-MTtOo_400x400.jpg",
"buttons":[
{
"type":"web_url",
"url": "my share url",
"title":"View Website"
}
]
}
]
}
}
}
MessengerExtensions.beginShareFlow(
function success() {},
function error(errorCode, errorMessage) {},
messageToShare,
"broadcast"
);
The share is working, but it's not posting the image as expected. The "image_aspect_ratio" flag is not respected and the image is displayed with horizontal layout.
But the same JSON displays the image as a square when the share is done thru CURL. Is there something wrong with my share object ? Please help
It was a bug on Messenger platform. I reported about it to Facebook and now it has beed fixed.
https://developers.facebook.com/bugs/391245647960177/
You need to add "sharable":true in your payload:
var messageToShare = {
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"image_aspect_ratio":"square",
"sharable": true,
"elements":[
{
"title":"Welcome to Peter\'s Hats",
"subtitle":"We\'ve got the right hat for everyone.",
"image_url":"https://pbs.twimg.com/profile_images/735453447718338561/9W-MTtOo_400x400.jpg",
"buttons":[
{
"type":"web_url",
"url": "my share url",
"title":"View Website"
}
]
}
]
}
}
}
Related
For Basic Card Issue: We are sending one Button but on assistant we are
seeing two button one without any text.
Here's sample Request to Google:
{
"expectUserResponse": true,
"expectedInputs": [
{
"possibleIntents": [
{
"intent": "actions.intent.TEXT"
}
],
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "<speak>The NAV for Franklin India Bluechip Fund as of 24 Jan 2022 is: \nDirect-Growth: 744.3406 \nDirect-Idcw: 48.0136 \nGrowth: 691.6646 \nIdcw: 42.6334 \n\nFor more information on the historical NAV of Franklin India Bluechip Fund, please visit our website at www.franklintempletonindia.com. Is there anything else, I can help you with?</speak>"
}
},
{
"basicCard": {
"buttons": [
{
"title": "Historical NAV",
"openUrlAction": {
"url": "https://www.franklintempletonindia.com/investor/fund-details/fund-historicalnavs/-4614"
}
}
]
}
}
]
}
}
}
]
}
Here's how it looks on smartphone, with one extra button with no text.
Can any body why is that so, and what's the issue here.
Check The Screenshot Here
I am using Actions SDK and I have different configurations to get the simulator to invoke my custom intent! It seems that the simulator refuses to trigger any action other than MAIN, not even TEXT. Below is my action.json:
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "SHOPPING"
},
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"Talk to stroller shopping expert"
]
}
}
},
{
"description": "Listing strollers for a specified age group",
"name": "SHOPPING",
"fulfillment": {
"conversationName": "SHOPPING"
},
"intent": {
"name": "SHOPPING",
"trigger": {
"queryPatterns": [
"I am looking for a jogging stroller",
"I am shopping for a jogging stroller"
]
}
}
}
],
"conversations": {
"SHOPPING": {
"name": "SHOPPING",
"url": "SOME_URL (I have a valid URL BTW)",
"fulfillmentApiVersion": 2
}
}
}
I am using firebase and in the firebase log I cannot see any logs from my custom or TEXT intent. Here are part of my index.json code:
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
const functions = require('firebase-functions');
const NO_INPUTS = [
'Padon me, I didn\'t hear that.',
'If you\'re still there, would you please say that again.',
'We can stop here. Good luck with your shopping.'
];
const SHOPPING_INTENT = 'SHOPPING';
exports.shopStrollers = functions.https.onRequest((request, response) => {
const app = new ActionsSdkApp({request, response});
function handleMainInput(app) {
console.log('mainIntent is invoked!');
console.log("The input is %s", app.getRawInput());
console.log("It seems that %s is never invoked!", app.StandardIntents.TEXT)
let inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
'I can help with finding strollers. How old is your baby?</speak>', NO_INPUTS);
app.ask(inputPrompt);
}
function handleTextInput(app) {
console.log('TEXT is invoked!');
console.log("The input is %s", app.getRawInput());
console.log("Finally TEXT HANDLER got invoked")
if (app.getRawInput() === 'bye') {
app.tell('Hope you found the service helpful and best of luck with your shopping, please come back again, goodbye!');
} else {
let inputPrompt = app.buildInputPrompt(true, '<speak>Here is a list of top' +
' <say-as interpret-as="ordinal">10</say-as>strollers' +
', say next for the next batch</speak>', NO_INPUTS);
app.ask(inputPrompt);
}
}
let actionMap = new Map();
actionMap.set(SHOPPING_INTENT, handleTextInput);
actionMap.set(app.StandardIntents.MAIN, handleMainInput);
actionMap.set(app.StandardIntents.TEXT, handleTextInput);
app.handleRequest(actionMap);
});
Does anybody have a clue what might be wrong, I would appreciate any help.
Problem solved. I had to enable web history.
I was using a business email and I had to go through a convoluted configuration process to "turn on web history"! Now everything works fine through ngrok and my express app. I would imagine it should work on firebase as well. So, action.json and index.js were good, the issue was with incomplete configuration for the business email!
Here is the steps I followed: https://productforums.google.com/forum/#!msg/apps/-52VibOcvrY/wUow1QOJ3VQJ
I have the problem that the google home/assitant action console simulators response and request tab are not working. At least when I am using a custom action.json.
For me I am not sure if all have this problem or only some. That are using an custom action sdk. Or is it a problem only because something of my action.json is maybe not 100% correct configured.
here is the action.json:
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "testApp"
},
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"open special manager",
"open s p m"
]
}
}
}
],
"types": [],
"conversations": {
"testApp": {
"name": "testApp",
"url": "https://572e66a2.ngrok.io/",
"fulfillmentApiVersion": 2,
"in_dialog_intents": [
{
"name": "actions.intent.NO_INPUT"
},
{
"name": "actions.intent.SIGN_IN"
}
]
}
}
here is a picture of the request:
As you can see it is only the dummy content in request tab anyway if the chat is working.
The response tab is completly empty. But the messages and voice is correctly working. Also on my google home.
Does anybody have an idea? I will add of course more debug informations if necessary. Can it be trouble with the response or request messages from my server?
But actually the messages, they are working...
I'm trying to add a hyperlink in fb messenger. Basically I'm creating a chatbot that replies users questions. However when I want to link the user to a webpage the only way possible is if I type in the whole URL which is really lengthy and ugly.
Fb messenger does not support HTML tags so I can't use the anchor tag to create a hyperlink for my URL to hide the link behind a word..
Is there a way I can type a sentence and hyperlink the URL behind a word in fb messenger?
Been searching tooo long now..
You can use a generic template with a web_url and no image:
{
"recipient":{
"id":"333333333"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Here is the link you asked for",
"default_action": {
"type": "web_url",
"url": "https://www.facebook.com",
"messenger_extensions": true,
"fallback_url": "https://www.facebook.com/"
},
"buttons":[
{
"type":"web_url",
"title": "open link",
"url":"https://www.facebook.com"
}
]
}
]
}
}
}
}
This is the full JSON below, I'm sending using Facebook's Generic Template.
I've checked it line-by-line with the official documentation here -> https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template
But I'm getting a 400 Bad Request Error for the following. What am i missing?
{
"recipient":{
"id":"1347939335300515"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Welcome to Peters Hats",
"image_url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png",
"subtitle":"Weve got the right hat for everyone.",
"default_action":{
"type":"web_url",
"url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png",
"messenger_extensions":true,
"webview_height_ratio":"tall",
"fallback_url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png"
},
"buttons":[
{
"type":"web_url",
"url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png",
"title":"View Website"
},
{
"type":"postback",
"title":"Start Chatting",
"payload":"DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}
}
The default_action is a URL Button and not supposed to be a postback button as in the JSON posted in the question.