首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Node.js中的TEAMS机器人: CreateConversation方法中的“此请求的授权已被拒绝”

Node.js中的TEAMS机器人: CreateConversation方法中的“此请求的授权已被拒绝”
EN

Stack Overflow用户
提问于 2019-10-17 19:30:11
回答 1查看 1.1K关注 0票数 2

我有一个TEAMS node.js机器人在本地运行(使用ngrok)。我收到来自团队客户端和回显工作的消息

代码语言:javascript
复制
context.sendActivity(`You said '${context.activity.text}'`);

现在,我想向此用户发送一条1to1消息,但收到

代码语言:javascript
复制
Error: Authorization has been denied for this request

创建对话时。

我的代码:

代码语言:javascript
复制
   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机器人中创建对话,它对我有效:

代码语言:javascript
复制
  var parameters = new ConversationParameters
   {
       Members = new[] { new ChannelAccount(sUserId) },
       ChannelData = new TeamsChannelData
       {
            Tenant = new TenantInfo(sTenantId),
       },
   };

   retValue = await connectorClient.Conversations.CreateConversationAsync(parameters);

我的node.js代码出了什么问题?

谢谢,

迭戈

EN

回答 1

Stack Overflow用户

发布于 2019-10-17 20:05:33

您信任该服务吗?根据您的代码,它并不这么认为,在您的情况下,这是401的典型原因。

在node.js中,执行以下操作:

代码语言:javascript
复制
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);

如果您想了解更多详细信息,请查看有关在发送主动消息时获取401的文档here

这也是关于团队和主动消息传递的答案,特别是最后一块。Proactive messaging bot in Teams without mentioning the bot beforehand

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58431605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档