MS ChatBot - ClientConnector 未授权异常

MS ChatBot - ClientConnector unauthorized exception

我正在尝试使用 ConnectorClient 从 Azure 函数发送主动消息,但尽管使用了正确的 AppIdAppPassword

,我还是收到了授权异常
var connector = new ConnectorClient(new Uri(queueMessage.ChatBotDetails.ServiceUrl), new MicrosoftAppCredentials(appId, appPassword));

await connector.Conversations.SendToConversationAsync((Activity)message);

但这会产生以下异常:

Microsoft.Bot.Connector.ErrorResponseException: Operation returned an invalid status code 'Unauthorized'

我在日志中输出应用程序密码和应用程​​序 ID,它们是正确的。

原来我只需要在调用连接器客户端之前添加这个调用:

MicrosoftAppCredentials.TrustServiceUrl(queueMessage.ChatBotDetails.ServiceUrl);