如何使用 javascript 在带有 botframework 的 cron 中发送主动消息?

问题描述 投票:0回答:2

找不到CloudAdapter.createConversationAsync的任何相关文档。 我找不到我做错了什么。

这是我尝试运行的代码:

const {
  CloudAdapter,
  ConfigurationBotFrameworkAuthentication,
  ConfigurationServiceClientCredentialFactory,
} = require('botbuilder');

const adapter = new CloudAdapter(new ConfigurationBotFrameworkAuthentication(
  {},
  new ConfigurationServiceClientCredentialFactory({
    MicrosoftAppId: process.env.MS_BOT_ID,
    MicrosoftAppPassword: process.env.MS_BOT_PASSWORD,
    MicrosoftAppType: 'MultiTenant',
  }),
));

const userId = 'XXXX';
const tenantId = 'YYYY';

adapter.createConversationAsync(
  process.env.MS_BOT_ID,
  'msteams',
  'https://smba.trafficmanager.net/teams/',
  userId, // audience
  {
    isGroup: false,
    bot: {
      id: process.env.MS_BOT_ID,
    },
    members: [{ id: userId }],
    tenantId,
  },
  console.log,
);

这是我的错误:

{"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named XXXX was not found in the tenant named Bot Framework. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: -------\r\nCorrelation ID: -----\r\nTimestamp: 2023-05-24 09:10:35Z","error_codes":[500011],"timestamp":"2023-05-24 09:10:35Z","trace_id":"-------","correlation_id":"-------","error_uri":"https://login.microsoftonline.com/error?code=500011"}
javascript botframework microsoft-teams
2个回答
0
投票

我终于找到如何使用它了! (感谢github搜索)

  • 观众必须为空
  • 第 5 个参数需要是
    { tenantId, members: [{ id }] }

以下是该功能的使用方法:

adapter.createConversationAsync(
  MS_BOT_ID,
  'msteams',
  'https://smba.trafficmanager.net/teams/',
  null,
  {
    members: [{ id: userId }],
    tenantId,
  },
  console.log,
);

0
投票

根据上述错误,只有在名为 {tenant} 的租户中找不到名为 {name} 的资源主体时,才会发生这种情况。如果租户管理员未安装应用程序或租户中的任何用户未同意应用程序,则可能会发生这种情况。

您可能已将身份验证请求发送给了错误的租户。

如果您希望安装该应用程序,您可能需要提供管理员权限才能添加它。请咨询资源和应用程序的开发人员,了解适合您的租户的正确设置。

有关 CloudAdapter.createConversationAsync,请参阅此文档:https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.cloudadapterbase.createconversationasync?view=botbuilder-dotnet-stable

© www.soinside.com 2019 - 2024. All rights reserved.