简体   繁体   中英

Sending proactive messages to MS Teams

I'm not been able to send proactive messages to MS Teams. You can see the code and errors belows. The error messages are as below: Incorrect conversation creation parameters

When i've put an application log in azure portal where the bot is hosted: I'm seeing the following errors: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Exception caught : One or more errors occurred. (Operation returned an invalid status code 'BadRequest')

2019-09-16T13:32:57 Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (409) Conflict. ---> System.Net.WebException: The remote server returned an error: (409) Conflict.at System.Net.HttpWebRequest.GetResponse()at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](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 policy, OperationContext operationContext)at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.ListBlobsSegmented(String prefix, Boolean useFlatBlobListing, BlobListingDetails blobListingDetails, Nullable`1 maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, 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:The type of a blob in the container is u nrecognized by this version.ErrorCode:FeatureVersionMismatch. Could you please help me? Thank you

 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.


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

V4 bot framework support in teams is beta (last I heard). I wouldn't be surprised if proactive messages are buggy. The version mismatch error may be due to teams expecting V3 payload.

I mentioned this in my email, but am re-posting here for others:

That's because you're not using a Teams UserId. They're formatted like:

29:1I9Is_Sx0O-Iy2rQ7Xz1lcaPKlO9eqmBRTBuW6XzXXXXXXXXMij8BVMdBcL9L_RwWNJyAHFQb0TXXXXXX

I have a bunch of examples of the Teams formatting in this answer .

The easiest way to get all the info is to start a message with a user and set a breakpoint to grab an incoming message.

Alternatively, you can query the roster .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM