我们不能使用来自 webhook 响应的 displayText 以外的任何东西吗
Can't we use anything other than displayText from webhook response
我是 api.ai 的新手,我正在执行 webhook 实现。我注意到只有来自 webhook 响应的 "speech" 或 "displayText" 会显示给用户。是否有任何技术可以使用响应中的任何其他参数?
如果有人告诉我如何设置响应文本的格式,如加粗、更改字体等,我会很高兴。
谢谢!
请注意,如果您要将响应发送到的客户端(例如 Facebook Messenger)不支持特殊格式,例如粗体,则这是徒劳的。
也就是说,除了纯文本之外,您还可以发送许多更丰富的回复类型,如果您想以编程方式执行此操作而不是在 API.ai 中构建丰富的回复,我建议您注入您的自定义客户端和 API.ai 之间的服务器端解决方案,而不是在流程结束时使用它。
换句话说:
客户端界面 <-> 自定义解决方案 <-> API.ai
而不是
客户端 <-> API.ai <-> 自定义实现
这为您提供了更多自定义和实现选项,包括构建完全自定义的 response/prompt 逻辑,甚至无需触及 API.ai 端点,或在 API returns 之后进一步编辑 API returns被处理,例如将数据库查询结果附加到 API.ai 履行的文本。
假设您有这样的设置,在 node.js 中,向 Facebook Messenger 发送比文本更高级的有效负载的解决方案如下所示:
//Send gif or image reply
function sendGifMessage(recipientId) {
var messageData = {
recipient: {
id: recipientId
},
message: {
attachment: {
type: "image",
payload: {
url: config.SERVER_URL + "FILE LOCATION"
}
}
}
};
callSendAPI(messageData);
}
// Send custom payload buttons
function sendButtonMessage(recipientId, text, buttons) {
var messageData = {
recipient: {
id: recipientId
},
message: {
attachment: {
type: "template",
payload: {
template_type: "button",
text: text,
buttons: buttons
}
}
}
};
callSendAPI(messageData);
}
// Send quickReply buttons
function sendQuickReply(recipientId, text, replies, metadata) {
var messageData = {
recipient: {
id: recipientId
},
message: {
text: text,
metadata: isDefined(metadata)?metadata:'',
quick_replies: replies
}
};
callSendAPI(messageData);
}
function callSendAPI(messageData) {
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: {
access_token: config.FB_PAGE_TOKEN
},
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
if (messageId) {
console.log("Successfully sent message with id %s to recipient %s",
messageId, recipientId);
} else {
console.log("Successfully called Send API for recipient %s",
recipientId);
}
} else {
console.error("Failed calling Send API", response.statusCode, response.statusMessage, body.error);
}
});
}
希望对您有所帮助
我是 api.ai 的新手,我正在执行 webhook 实现。我注意到只有来自 webhook 响应的 "speech" 或 "displayText" 会显示给用户。是否有任何技术可以使用响应中的任何其他参数?
如果有人告诉我如何设置响应文本的格式,如加粗、更改字体等,我会很高兴。
谢谢!
请注意,如果您要将响应发送到的客户端(例如 Facebook Messenger)不支持特殊格式,例如粗体,则这是徒劳的。
也就是说,除了纯文本之外,您还可以发送许多更丰富的回复类型,如果您想以编程方式执行此操作而不是在 API.ai 中构建丰富的回复,我建议您注入您的自定义客户端和 API.ai 之间的服务器端解决方案,而不是在流程结束时使用它。
换句话说: 客户端界面 <-> 自定义解决方案 <-> API.ai 而不是 客户端 <-> API.ai <-> 自定义实现
这为您提供了更多自定义和实现选项,包括构建完全自定义的 response/prompt 逻辑,甚至无需触及 API.ai 端点,或在 API returns 之后进一步编辑 API returns被处理,例如将数据库查询结果附加到 API.ai 履行的文本。
假设您有这样的设置,在 node.js 中,向 Facebook Messenger 发送比文本更高级的有效负载的解决方案如下所示:
//Send gif or image reply
function sendGifMessage(recipientId) {
var messageData = {
recipient: {
id: recipientId
},
message: {
attachment: {
type: "image",
payload: {
url: config.SERVER_URL + "FILE LOCATION"
}
}
}
};
callSendAPI(messageData);
}
// Send custom payload buttons
function sendButtonMessage(recipientId, text, buttons) {
var messageData = {
recipient: {
id: recipientId
},
message: {
attachment: {
type: "template",
payload: {
template_type: "button",
text: text,
buttons: buttons
}
}
}
};
callSendAPI(messageData);
}
// Send quickReply buttons
function sendQuickReply(recipientId, text, replies, metadata) {
var messageData = {
recipient: {
id: recipientId
},
message: {
text: text,
metadata: isDefined(metadata)?metadata:'',
quick_replies: replies
}
};
callSendAPI(messageData);
}
function callSendAPI(messageData) {
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: {
access_token: config.FB_PAGE_TOKEN
},
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
if (messageId) {
console.log("Successfully sent message with id %s to recipient %s",
messageId, recipientId);
} else {
console.log("Successfully called Send API for recipient %s",
recipientId);
}
} else {
console.error("Failed calling Send API", response.statusCode, response.statusMessage, body.error);
}
});
}
希望对您有所帮助