我有一个TEAMS node.js机器人在本地运行(使用ngrok)。我收到来自团队客户端和回显工作的消息
context.sendActivity(`You said '${context.activity.text}'`);现在,我想向此用户发送一条1to1消息,但收到
Error: Authorization has been denied for this request创建对话时。
我的代码:
var sUserId = "29:1shb_5I6CkkerBVq4qPqcv5dGwDfkXx11Jbjc1UnGCIv"
var sServiceUrl = "https://smba.trafficmanager.net/emea/";
var sTenantId = "942369d2-208e-438b-894c-0d0e1510cf61";
var credentials = new BotConnector.MicrosoftAppCredentials({
appId: "xxxxxxx",
appPassword: "yyyyyyyy"
});
var connectorClient = new BotConnector.ConnectorClient(credentials, { baseUri: sServiceUrl });
const parameters = {
members: [ { id: sUserId } ],
isGroup: false,
channelData:
{
tenant: {
id: sTenantId
}
}
};
var conversationResource = await connectorClient.conversations.createConversation(parameters);
// I get the error here, next is not executed
await connectorClient.conversations.sendToConversation(conversationResource.id, {
type: "message",
from: { id: "xxxxxxx" },
recipient: { id: sUserId },
text: 'This a message from Bot Connector Client (NodeJS)'
});appId和appPassword是有效的(从.env文件),如果它们是错误的,我无法从团队客户端接收消息
我有相同的代码在.NET机器人中创建对话,它对我有效:
var parameters = new ConversationParameters
{
Members = new[] { new ChannelAccount(sUserId) },
ChannelData = new TeamsChannelData
{
Tenant = new TenantInfo(sTenantId),
},
};
retValue = await connectorClient.Conversations.CreateConversationAsync(parameters);我的node.js代码出了什么问题?
谢谢,
迭戈
发布于 2019-10-17 20:05:33
您信任该服务吗?根据您的代码,它并不这么认为,在您的情况下,这是401的典型原因。
在node.js中,执行以下操作:
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);如果您想了解更多详细信息,请查看有关在发送主动消息时获取401的文档here
这也是关于团队和主动消息传递的答案,特别是最后一块。Proactive messaging bot in Teams without mentioning the bot beforehand
https://stackoverflow.com/questions/58431605
复制相似问题