向MS团队发送主动消息

时间:2019-09-16 13:57:09

标签: c# botframework

我无法向MS Team发送主动消息。 您可以在下面看到代码和错误。 错误消息如下: 错误的会话创建参数

当我将应用程序日志放到托管机器人的Azure门户中时: 我看到以下错误: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: 捕获到异常:发生一个或多个错误。 (操作返回了无效的状态码“ BadRequest”)

  

2019-09-16T13:32:57   Microsoft.WindowsAzure.Storage.StorageException:   远程服务器返回错误:(409)冲突。 ---> System.Net.WebException:远程服务器返回错误:(409)Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [T](在System.Net.HttpWebRequest.GetResponse()处为Conflict.at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.ListBlobsSegmented(String prefix,Boolean useFlatBlobListing,BlobListingDetails blobListingDetails,Nullable`1 maxResults,BlobContinuationToken操作,RESTCommand 1 cmd, IRetryPolicy policy, OperationContext operationContext)--- End of inner exception stack trace ---at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand 1 cmd,IRetryPolicy策略,OperationContext operationContext) )at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.CleanupOldBlobLogs(Object state)Request InformationRequestID:a8f8929d-001e-0005-4693-6ccae9000000RequestDate:Mon,16 Sep 2019 13:32:57 GMTStatusMessage:容器中Blob的类型此版本无法识别。ErrorCode:FeatureVersionMismatch。   请你帮助我好吗?   谢谢

 MicrosoftAppCredentials.TrustServiceUrl(turnContext.Activity.ServiceUrl);
            var teamConversationData = turnContext.Activity.GetChannelData<TeamsChannelData>();
            var connectorClient = new ConnectorClient(new Uri(turnContext.Activity.ServiceUrl), _credentialProvider.AppId, _credentialProvider.Password);

            var userId = "28:2c988176-cea6-4aaa-9a69-8ace544a43e3";
            var tenantId = teamConversationData.Tenant.Id;
            var parameters = new ConversationParameters
            {
                Members = new[] { new ChannelAccount(userId) },
                ChannelData = new TeamsChannelData
                {
                    Tenant = new TenantInfo(tenantId),
                },
            };

            var conversationResource = await connectorClient.Conversations.CreateConversationAsync(parameters);
            var message = Activity.CreateMessageActivity();
            message.Text = "This is a proactive message1.";
            await connectorClient.Conversations.SendToConversationAsync(conversationResource.Id, (Activity)message);

            // Save any state changes that might have occured during the turn.


2 个答案:

答案 0 :(得分:0)

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-create

团队中的

V4 bot框架支持为beta(我上次听说)。如果主动消息有错误,我不会感到惊讶。版本不匹配错误可能是由于团队期望V3有效负载。

答案 1 :(得分:0)

我在电子邮件中提到了此内容,但正在此处重新张贴给其他人:

那是因为您没有使用Teams用户ID。它们的格式如下:

29:1I9Is_Sx0O-Iy2rQ7Xz1lcaPKlO9eqmBRTBuW6XzXXXXXXXXMij8BVMdBcL9L_RwWNJyAHFQb0TXXXXXX

我有很多this answer中的Teams格式示例。

获取所有信息的最简单方法是与用户启动一条消息,并设置一个断点以捕获传入的消息。

或者,您可以query the roster