我有一个方案,用于从我的 Microsoft 团队自定义选项卡向聊天窗口发送通知。 因此,我正在尝试调用 Microsoft Graph API 以将消息发送到特定的 chatId:Post https://graph.microsoft.com/beta/chats/${chatId}/messages 我可以成功获取 access_token ,但是在调用 post 请求以将通知发送到 chatId 时,出现“401 UnAuthorized”错误。 我的代码有什么问题?
var message = {
"body": {
"content": "Hello World"
}
};
fetch(`https://graph.microsoft.com/beta/${context.userObjectId}/chats/${chatId}/messages`, {
method: "POST",
mode: "cors",
cache: "no-cache",
headers: {
'Content-Type': "application/json;charset=utf-8",
'Authorization': `Bearer ${fetched_accessToken}`
},
body: JSON.stringify(message)
}).then((response) => {
alert(response.statusText);
}).catch((err) => {
alert(err);
});
}
这段代码有什么问题?
答案 0 :(得分:1)
如果您已经有一个 Teams 应用程序,用于您的选项卡,并且您还想在聊天中进行交流,您应该考虑创建一个机器人,并使用主动消息传递。在 https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-messages?tabs=dotnet 和 https://docs.microsoft.com/en-us/graph/teams-proactive-messaging
查看更多答案 1 :(得分:0)