我尝试从实现(nodejs)在Dialogflow中发送自定义有效载荷
我的动机是发送链接及其文本作为对网页的响应。
我的示例代码供参考:
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}));
我在这里得到的答复是:
{
"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"
}]
}
]
}
}
]
}
}
}
在这里您可以看到响应,我在响应中的数据对象内附加了“ 空”对象。
有谁能帮助我从对话框流响应中删除该空对象,以及从实现节点js发送自定义有效负载的其他任何选项。
答案 0 :(得分:1)
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}));
}
在此函数中,需要添加参数作为代理,以便获取非“空”对象
参考代码需要更新。
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}));
}