I am trying to send Quick Replies to Facebook users through Dialogflow Fulfillment and I have not been able to achieve that I have tried a lot and have not succeeded Is there any help
Codes i have tried:
#1 :
function QuickReplies(agent) {
agent.add(“Select one”);
agent.add(new Suggestion(“Quick Reply”));
agent.add(new Suggestion(“Suggestion”));
}
#2 :
function QuickReplies(agent)
{
const quickReplies1 = new Suggestion({
title: "What do you want to do?",
reply: "Next",
platform: 'FACEBOOK'
})
quickReplies1.addReply_("Cancel");
agent.add(quickReplies1);
}
So, the first step is to import the Suggestion module as:
const {Suggestion} = require('dialogflow-fulfillment')
Then you can do something like your first function (I do not see any problem in your code).
Finally, you have to associate it with one of your intents:
let intentMap = new Map();
intentMap.set('Your intent's name', QuickReplies);
agent.handleRequest(intentMap);
Keep in mind that even if your intent has other components (text, cards) you can still append quick replies to it.
Related
I am new to google Dialogflow and trying to add cards in Dialogflow messenger.
Below is my code to display the cards on Dialogflow messenger. Please help me out.
Cards are not showing up in the messenger.
I have created an intent to call the cards as well.
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
// // Uncomment and edit to make your own intent handler
// // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
// // below to get this function to be run when a Dialogflow intent is matched
function cards(agent) {
agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
agent.add(new Card({
title: 'Title: this is a card title',
imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
text: 'This is the body text of a card. You can even use line\n breaks and emoji! 💁',
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', cards);
//intentMap.set('Dialogflow Cards', cards);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
Cards are a Google Assistant element and will only show on devices or platforms that support Google Assistant. The web simulator of Dialogflow only supports text based responses.
If you want to see the card response, you should integrate your project with Google Assistant via the integrations tab and test your bot in the Google Assistant simulator or on a real Google Assistant device.
So I have the Dialogflow Messenger embedded in a website and want to add some Suggestion chips. It's easy through the Custom Payload Response type and they show up just fine.
But how do I add them through fulfillment?
I currently have a custom webhook setup and the idea is to have something like this:
if (x) {
agent.add('blablabla');
agent.add(new Suggestion('One');
} else {
agent.add('blablabla');
agent.add(new Suggestion('Two');
}
new Suggestion doesn't work though, so is there another way of doing this?
I was thinking about something like this:
agent.add(new Payload(
"richContent": [
[
{
"options": [
{
"text": "One"
},
{
"text": "Two"
}
],
"type": "chips"
}
]
]));
Essentially trying to insert the Custom Payload directly into the response JSON, if that makes any sense. But yeah no idea how to actually do it. Anyone know how?
It is unclear to me what you exactly mean by new Suggestion() doesn't work. You mean the suggestion chips do not show in Dialogflow Messenger? Do they show in Dialogflow itself?
Let me share a few points:
As far as I know the structure agent.add(new Suggestion(“One”)); should work. I tried a simple example and it is working fine in Dialogflow UI, with the code:
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
function welcome(agent){
agent.add("What is your favorite animal?");
agent.add(new Suggestion("Dog"));
agent.add(new Suggestion("Cat"));
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
agent.handleRequest(intentMap);
});
If suggestions chips are not rendered even in Dialogflow UI I would suggest trying the previous code to discard any potential issues with your Dialogflow setup. You may need to upgrade some dependencies e.g. "dialogflow-fulfillment": "^0.6.1".
Some integrations, like Google Assistant use the Suggestions library from actions-on-google. See for example official Google Assistant code example. You may try to follow a similar behavior if it fits your use case although I do not think it is the case. As a reference you can check this github issue.
probably the most basic question, but the docs (?) suck.
I want to send a basic text response from an agent.
something like:
router.post('/api/webhook', async (request, response) => {
const agent = new WebhookClient({ request, response })
agent.add('hello world')
// now how do i tell dialogflow to handle the response? none of these work:
response.send(agent)
agent.resolve()
this pretty dumb code seemed to work but now has problems
let intentMap = new Map()
intentMap.set('reply', () => {
agent.add('hello world')
})
agent.intent = 'reply'
agent.handleRequest(intentMap)
I don't want to use the intentMap.set or ideally agent.handleRequest(intentMap)
And I certainly don't want to use google cloud funcs, plain express is fine.
can't really find any docs that aren't shoving google cloud functions down your throat.
abstract docs, no example code
https://dialogflow.com/docs/reference/fulfillment-library/webhook-client#new_webhookclientoptions
client libs - no use
https://github.com/googleapis/nodejs-dialogflow
answer:
https://blog.dialogflow.com/post/fulfillment-library-beta/
function intentHandler(agent) {
agent.add('This message is from Dialogflow\'s Cloud Functions for Firebase editor!');
agent.add(new Card({
title: 'Title: this is a card title',
imageUrl: 'https://developers.google.com/actions/assistant.png',
text: 'This is the body text of a card. You can even use line\n breaks and emoji! 💁',
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);
agent.add(new Suggestion('Quick Reply'));
agent.add(new Suggestion('Suggestion'));
}
agent.handleRequest(intentHandler);
I found one way of doing it which is not too verbose, posting in case anyone finds this
Note it's important to also remove replies for Default Fallback from your GUI code in DF
function intentHandler(agent) {
agent.add('Hello World');
}
agent.handleRequest(intentHandler);
After trying and trying countless times, I ask for your help to call a Dialogflow event (GoogleHome) with a specific GoogleHome device.
Through nodeJS I managed to successfully call a Dialogflow event and I get the fullfillment response. All perfect, only I have to let my GoogleHome device speak with fullfillment, I do not need a text-only answer.
My goal is to let my GoogleHome device speak first, without the word "Ok, Google" and wait for a response from the user.
I did not find anything on the web, my attempts stop to invoke the Dialogflow event and have a console response.
This is the code i have tried for fullfillment
test: async function () {
console.log("[funcGHTalk|test] CALLED");
const projectId = "[[projectid]]";
const LANGUAGE_CODE = 'it-IT';
let eventName = "[[eventname]]";
const sessionId = uuid.v4();
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
event: {
name: eventName,
languageCode: LANGUAGE_CODE
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(result);
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
}
The code you have written is using the Dialogflow Detect Intent API. This is meant to run on consoles and servers to send a message to Dialogflow, which will parse it, determine which Intent it matches, call fulfillment with that information, and return all the results.
You don't need to run this on a Google Home, since the Google Assistant does all this for you.
What I think you're looking for is to develop fulfillment with Actions on Google and the Dialogflow Fulfillment API. This handles things on the other end - after Dialogflow determines what Intent matches what the user has said, and if that Intent has fulfillment enabled, it will send the information to your webhook which is running on a cloud server somewhere. You would then process it, send a reply (either using the actions-on-google library or the dialogflow-fulfillment library is easiest), and it would send it back to the Assistant.
You indicated that you want the Action to "let my GoogleHome device speak first, without the word "Ok, Google" and wait for a response from the user". This is much more complicated, and not really possible to do with the Google Home device right now. Most Actions have the user initiating the conversation with "Ok Google, talk to my test app" or whatever the name of the Action is.
You don't indicate how you expect to trigger the Home to begin talking, but you may wish to look into notifications to see if those fit your model, however notifications don't work with the Home right now, just the Assistant on mobile devices.
I'm trying to create custom fallbacks for intents that contain confirmations. Here is the code:
const functions = require('firebase-functions');
const {
dialogflow,
Confirmation
} = require('actions-on-google');
const app = dialogflow({
debug: true,
});
app.intent('vitals-confirmation', (conv, input, confirmation) => {
conv.ask(new Confirmation(`Great! Have you fainted recently?`));
});
app.intent('vitals-confirmation-fallback', (conv, input, confirmation) => {
conv.ask(new Confirmation(`Sorry I didn't understand what you said. Did you faint?`));
})
app.intent('S1-confirmation', (conv, input, confirmation) => {
if (confirmation) {
conv.ask(new Confirmation(`I have recorded that you have fainted. Have your feet been hurting?`));
} else {
conv.ask(new Confirmation(`I have recorded that you have not fainted. Have your feet been hurting?`));
}
});
My app asks the user if they have fainted in "vitals-confirmation" and the user is expected to answer with a yes or no type answer that will be identified by the confirmation helper, if they do this correctly they will go to "S1-confirmation" and will be asked the next question.
However the following is outputted when I respond with an answer that is not a yes/no type answer (for example: "red"):
Sorry, Great! Have you fainted recently?
It seems as though there is a default fallback that responds with "Sorry, [repeats previous text output]" and does not go to a custom fallback intent which I have created (which is my desired result).
Take a look at the documentation for Confirmation helper of Actions SDK for Node.js.
You have to setup an intent with the actions_intent_CONFIRMATION event in DialogFlow in order to retrieve the user response. My advice is to check how you configured your intents and use this method, otherwise be sure to create the follow-up intents with the desired context lifespan.
Example from documentation:
app.intent('Default Welcome Intent', conv => {
conv.ask(new Confirmation('Are you sure you want to do that?'))
})
// Create a Dialogflow intent with the `actions_intent_CONFIRMATION` event
app.intent('Get Confirmation', (conv, input, confirmation) => {
if (confirmation) {
conv.close(`Great! I'm glad you want to do it!`)
} else {
conv.close(`That's okay. Let's not do it now.`)
}
})