[英]Respond to a bot call in Microsoft Teams with Graph API
I trying to respond to a call in Teams but actually I'm not getting a respond from the bot. 我试图响应Teams中的呼叫,但实际上我没有收到机器人的响应。
First I get access_token from Graph API. 首先,我从Graph API获得access_token。
Then I have a route that intercept bot calls. 然后我有一条拦截机器人呼叫的路由。
app.post("/api/call", function(req, res) {
if (j === 1) {
j = j + 1;
res.status(204).send();
} else {
var answerbody = {
callbackUri: "https://8a73b7ad.ngrok.io/api/call",
acceptedModalities: ["audio"],
mediaConfig: {
"@odata.type": "#microsoft.graph.serviceHostedMediaConfig",
preFetchMedia: [
{
uri: "https://cdn.contoso.com/beep.wav",
resourceId: "1D6DE2D4-CD51-4309-8DAA-70768651088E"
},
{
uri: "https://cdn.contoso.com/cool.wav",
resourceId: "1D6DE2D4-CD51-4309-8DAA-70768651088F"
}
]
}
};
POST(
"https://graph.microsoft.com/beta/" + req.body.resource + "/answer",
answerbody
)
.then(
data => console.log(data) // I get undefined
)
.catch(function(err) {
console.log("err " + err);
res.status(200).send();
});
}
});
Here's POST function 这是POST功能
function POST(url, BB) {
return new Promise(function(resolve, reject) {
var options = {
url: url,
method: "POST",
headers: {
Accept: "application/json",
Authorization: "Bearer " + token
},
body: BB,
json: true
};
request(options)
.then(function(body) {
resolve(body);
})
.catch(function(err) {
reject(err);
});
});
}
As mentionned in documentation , Server sould first reply 204 in order to get response in Graph API protocol. 如文档中所述 ,服务器首先响应204,以便在Graph API协议中获得响应。
Actually I don't get a response. 其实我没有得到回应。 Bot still ringing until It gets voice message : " You can't talk to the bot just yet , we are working on it".
Bot仍然响起,直到收到语音消息:“您还不能与Bot对话,我们正在研究它”。
As mentioned in Teams API documentation , I should get callback with the ressource id and other information to be able to answer to the call. 如Teams API文档中所述 ,我应该获得带有资源ID和其他信息的回调,以便能够应答呼叫。
So I use my POST
function to answer. 所以我用我的
POST
函数来回答。 but here I don't get any 202 Accepted
response as indicated in docs, instead I get more than one callback with different ressource ids, then after some seconds I get the voice message. 但是在这里我没有得到文档中指示的任何
202 Accepted
响应,而是获得了多个具有不同资源ID的回调,然后几秒钟后我收到了语音消息。
解决方案是将acceptedModalities: ["audio"]
更改为acceptedModalities: ["Audio"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.