如何使用JavaScript在botframework中定时发送主动消息?

huangapple go评论71阅读模式
英文:

How to send proactive message in a cron with botframework using javascript?

问题

无法找到有关 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"}
英文:

Can't find any relevant documentation for CloudAdapter.createConversationAsync.
I can't find what I am doing wrong.

Here is the code I am trying to run:

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,
);

This is the error I have:

{"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"}

答案1

得分: 0

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

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

如果您期望该应用程序已安装,您可能需要提供管理员权限以进行添加。请与资源和应用程序的开发人员联系,以了解适合您租户的正确设置。

您可以请检查一下吗?

CloudAdapter.createConversationAsync文档-https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.cloudadapterbase.createconversationasync?view=botbuilder-dotnet-stable

英文:

As per the above error, this can happen only the resource principal named {name} was not found in the tenant named {tenant}. 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.

If you expect the app to be installed, you may need to provide administrator permissions to add it. Check with the developers of the resource and application to understand what the right setup for your tenant is.

Could you please check once?

Document for CloudAdapter.createConversationAsync-https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.cloudadapterbase.createconversationasync?view=botbuilder-dotnet-stable

答案2

得分: 0

我终于找到了如何使用它的方法!(感谢GitHub搜索)

  • audience 需要为 null
  • 第五个参数需要为 { tenantId, members: [{ id }] }

以下是如何使用该函数的示例:

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

I finally found how to use it! (thanks to github search)

  • audience needed to be null
  • 5th parameters needed to be { tenantId, members: [{ id }] }

Here is how to use the function:

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

huangapple
  • 本文由 发表于 2023年5月24日 17:41:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322137.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定