我制作了Api.Ai机器人并将其与Slack和Facebook Messenger集成。当我写信给它时,它回答了Api.Ai为Slack和Facebook Messenger设置的响应,但在履行部分,当Api.Ai打电话给我的服务时,它在Slack中运行正常,但我得到了Facebook Messenger没有回复。
我从服务中返回的邮件格式:
{
"contextOut": [
{
"lifespan": 2,
"name": "weather",
"parameters": {
"city": "Rome"
}
}
],
"data": {
"facebook": {
"message": {
"text": "Great success!"
},
"recipient": {
"id": "1454102654663349"
}
},
"slack": {
"attachments": [
{
"color": "#00A399",
"title": "Hello world!",
"title_link": "https://www.mywebsite.se"
}
],
"text": "Horray! Great success! :)"
}
},
"displayText": "Whatever!!",
"followupEvent": {
"followupEvent": {
"data": {
"parameter": "<parameter_value>"
},
"name": "<event_name>"
}
},
"source": "mywebsite.se",
"speech": "Whatever!?"
}
Facebook收件人ID来自对我服务的请求。
request.result.contexts[0].parameters.Facebook_sender_id
我已经在Facebook应用中的产品设置标签下验证了我的webhook
我已使用我的页面访问令牌将我的应用订阅到该页面
我在webhooks下检查了以下事件:messages,messaging_postbacks
在Facebook上尝试使用僵尸程序时,我以应用程序的管理员用户身份登录。
我没有想法,必须有一些我错过的东西?
编辑: 我已将Azure功能设置为我的webhook用于测试目的。
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var request = await req.Content.ReadAsAsync<ApiAiMessage>();
log.Info($"Incoming: {JsonConvert.SerializeObject(request)}");
var slack_message = new {
text = $"Horray! Great success! :)",
attachments = new[] {
new {
title = "Hello world!",
title_link = "https://www.mywebsite.se",
color = "#00A399"
}
}
};
var facebook_message = new {
recipient = new {
id = $"{request.result.contexts[0].parameters.Facebook_sender_id}"
},
message = new {
text = "Great success!"
}
};
var response = new
{
data = new
{
facebook = facebook_message,
slack = slack_message
},
speech = "Whatever!?",
displayText = "Whatever!!",
contextOut = new[] {
new {
name = "weather",
lifespan = 2,
parameters = new {
city = "Rome"
}
}
},
source = "mywebsite.se",
followupEvent = new {
followupEvent = new {
name = "<event_name>",
data = new {
parameter = "<parameter_value>"
}
}
}
};
log.Info($"Outgoing: {JsonConvert.SerializeObject(response)}");
return req.CreateResponse(HttpStatusCode.OK, response, new MediaTypeHeaderValue("application/json"));
}
答案 0 :(得分:0)
您实际上将API.ai回复发送回Facebook Messenger?这需要一些FB细节,如“页面标记”和#39;而且它对Slack起作用的事实,但不是FB让我相信它只是像这样简单的东西。以下是javascript中调用内容的示例
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);
}
});
}
&#13;