botframework-sdk: [Skype] Can not receive attachment?

Bot Info

  • SDK Platform: .NET
  • SDK Version: 3.8.0.0
  • Active Channels: Skype
  • Deployment Environment: Azure App Service

Issue Description

When I sent a attachment to bot, in my bot I want to get the contents of the attachment. I used the following code to get it. But has been returning 500 errors.

Code Example

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            var message = await argument;

            if (message.Attachments != null && message.Attachments.Any())
            {
                using (var connectorClient = new ConnectorClient(new Uri(message.ServiceUrl)))
                {
                    var token = await (connectorClient.Credentials as MicrosoftAppCredentials).GetTokenAsync();
                    var uri = new Uri(message.Attachments[0].ContentUrl);
                    using (var httpClient = new HttpClient())
                    {
                        await context.PostAsync(message.Attachments[0].ContentUrl);
                        await context.PostAsync(uri.Host);
                        //if (uri.Host.EndsWith("skype.com") && uri.Scheme == "https")
                        //{
                        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
                        //}

                        try
                        {
                            var data = await httpClient.GetByteArrayAsync(uri);
                            await context.PostAsync(data.Length.ToString());
                        }
                        catch(Exception ex)
                        {
                            if (ex.InnerException!= null)
                            {
                                await context.PostAsync(ex.Message + ":" + ex.InnerException.Message);
                            }
                            else
                            {
                                await context.PostAsync(ex.Message);
                            }   
                        }   
                    }
                }
            }
            
            context.Wait(this.MessageReceivedAsync);
        }

Code Description

  1. await context.PostAsync(message.Attachments[0].ContentUrl); output: https://smba.trafficmanager.net/apis/v3/attachments/0-sa-d1-abd6e64b01d2f5e06ef698e7f05a8bb2/views/original
  2. await context.PostAsync(uri.Host); output: smba.trafficmanager.net
  3. var data = await httpClient.GetByteArrayAsync(uri); throw exception: Response status code does not indicate success: 500 (Internal Server Error).

Does anyone have an idea of how I can work around this?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Same problem here - accessing https://smba.trafficmanager.net/df-apis/v3/attachments/0-neu-d5-<omitted>/views/original with Bearer token, using Postman and getting 500 Internal Server Error…

@ZhengKevin25 Thank you for reporting. I will need your bot id and approximate date/ time when the problem was observed. Thank you!