【问题标题】:"Value cannot be null. (Parameter 'clientSecret')" when calling SendActivityAsync with UserAssignedMSI (teams bot)\“值不能为空。(参数 \'clientSecret\')\” 使用 UserAssignedMSI(团队机器人)调用 SendActivityAsync 时
【发布时间】:2022-11-03 19:05:08
【问题描述】:

我目前正在尝试建立一个新的团队机器人,但无法真正让它工作。

我在 azure 中创建了一个新的 Azure Bot 服务,将其设置为 UserAssignedMSI,并设法将其添加到团队中。如果我向机器人发送一些东西,我还可以看到 OnTurnAsyncOnMessageActivityAsync 这样的方法被触发,所以到目前为止一切看起来都很好。

但是当我尝试发回一些东西时,例如:

    protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        await turnContext.SendActivityAsync(MessageFactory.Text("hello"), cancellationToken);
        await base.OnMessageActivityAsync(turnContext, cancellationToken);
    }

它崩溃了以下内容:

System.ArgumentNullException: Value cannot be null. (Parameter 'clientSecret')
   at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential..ctor(String clientId, String clientSecret)
   at Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.<BuildAuthenticator>b__16_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Microsoft.Bot.Connector.Authentication.AppCredentials.<BuildIAuthenticator>b__36_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Microsoft.Bot.Connector.Authentication.AppCredentials.GetTokenAsync(Boolean forceRefresh)
   at Microsoft.Bot.Connector.Authentication.AppCredentials.ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Bot.Connector.Conversations.ReplyToActivityWithHttpMessagesAsync(String conversationId, String activityId, Activity activity, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at Microsoft.Bot.Connector.ConversationsExtensions.ReplyToActivityAsync(IConversations operations, String conversationId, String activityId, Activity activity, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.TurnContext.<>c__DisplayClass31_0.<<SendActivitiesAsync>g__SendActivitiesThroughAdapter|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(IActivity activity, CancellationToken cancellationToken)
   at iPMC.Autotest.DevOps.Bots.Bots.AutotestBot.OnMessageActivityAsync(ITurnContext`1 turnContext, CancellationToken cancellationToken)

我很清楚为什么。根据文档,当使用用户分配的身份时,我的 appsettings.json 应该足够了(AVALUE 当然是我的真实值):

  "MicrosoftAppType": "UserAssignedMSI",
  "MicrosoftAppId": "AVALUE",
  "MicrosoftAppTenantId": "AVALUE",
  "MicrosoftAppPassword": "",
  "ConnectionName": "AVALUE"

似乎大多数示例也使用密码,所以我真的找不到其他使用过密码的人。

我也尝试在本地进行并部署,但我在两个地方都遇到了同样的异常,所以我已经没有想法接下来应该测试什么了。

是否有其他人将 UserAssignedMSI 与团队机器人一起使用并让它工作?

【问题讨论】:

  • 你的appsettings.json 中有/你的clientSecret 吗?你也需要那个。
  • @IvanGechev我认为我不需要用户用户分配的身份吗?但我只是试图把我的秘密放在 MicrosoftAppPassword 上,现在我得到了这个:Application with identifier 'AVALUE' was not found in the directory '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 may have sent your authentication request to the wrong tenant

标签: c# azure botframework


【解决方案1】:

您需要 generate a client secret 并将其存储在您的 appsettings.json 文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 2019-01-10
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多