i try to send custom payload in Dialogflow from fulfillment(nodejs)
My motive is send link and its text as response to web page.
my sample code for reference:
const response = {
messages: [
{
payload: {
messages: [
{
speech: 'here are some quick links for your convenience.',
linkmessage: [{
message: 'google',
link: 'www.google.com'
}, {
message: 'yahoo',
link: 'www.yahoo.co.in'
}],
button: [{
buttonname: 'more page'
}]
}
]
}
}
]
};
agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));
Here i get the response as:
{
"fulfillment": {
"speech": "",
"messages": [
{
"lang": "en",
"type": 0,
"speech": ""
}
],
"data": {
"null": {
"messages": [
{
"payload": {
"messages": [
{
"speech": "here are some quick links for your convenience.",
"linkmessage": [{
"message": "google",
"link": "www.google.com"
}, {
"message": "yahoo",
"link": "www.yahoo.co.in"
}],
"button": [{
"buttonname": "more page"
}]
}
]
}
}
]
}
}
}
Here you can see in response i am getting "null" object is appended inside the data object in the response.
can any one help me out to remove that null object from dialogflow response, and any other option for sending custom payload from fulfillment nodejs.
function update() {
const response = {
messages: [
{
payload: {
messages: [
{
speech: 'here are some quick links for your convenience.',
linkmessage: [{
message: 'google',
link: 'www.google.com'
}, {
message: 'yahoo',
link: 'www.yahoo.co.in'
}],
button: [{
buttonname: 'more page'
}]
}
]
}
}
]
};
agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));
}
In this function need to add parameter as agent so that you can get non 'null' object
Reference code need to be updated.
function update(agent) {
const response = {
messages: [
{
payload: {
messages: [
{
speech: 'here are some quick links for your convenience.',
linkmessage: [{
message: 'google',
link: 'www.google.com'
}, {
message: 'yahoo',
link: 'www.yahoo.co.in'
}],
button: [{
buttonname: 'more page'
}]
}
]
}
}
]
};
agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));
}