在node.js:'中的团队机器人已拒绝对CreateConversation方法中的此请求进行授权 [英] TEAMS bot in node.js: 'Authorization has been denied for this request' in CreateConversation method

查看:17
本文介绍了在node.js:'中的团队机器人已拒绝对CreateConversation方法中的此请求进行授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Teams node.js bot在本地运行(使用ngrok)。我收到来自团队客户端的消息,ECHO工作正常

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代码有什么问题?

谢谢,

迭戈

推荐答案

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

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

MicrosoftAppCredentials.trustServiceUrl(serviceUrl);

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

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

这篇关于在node.js:'中的团队机器人已拒绝对CreateConversation方法中的此请求进行授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆