Karthik.M
Karthik.M

Reputation: 57

C# Skype Bot download attachment

I am developing a Skype bot in C# with Bot Framework and I would like to download the attachment sent by the users, I am using webclient to download the file, Its working fine with local BOT emulator, But can't working via skype BOT, getting below exception,

System.Net.WebException: The remote server returned an error: (401) Unauthorized.

Even i tried with webclient credentials too.

My code snippet:

var webclient = new WebClient()

webclient.Credentials = new System.Net.NetworkCredential(userName, passWord);
webclient.DownloadFile(remoteFileUrl, localFileName);

Apart from Credentials, anything need to specify? Please Help.

Upvotes: 1

Views: 302

Answers (2)

ranusharao
ranusharao

Reputation: 1854

Adding to the above answer, the Skype and Microsoft Teams attachment URLs are secured by JwtToken and you should set the JwtToken of your bot as the authorization header for the HTTP GET request your bot initiates to fetch content. You should be careful when you send the bot's JwtToken to a third party server and should always make sure to send it to trusted parties.

To download the actual attachment:

 using (var webClient = new WebClient())
    {
        if (!string.IsNullOrWhiteSpace(channelToken))
        {
            webClient.DefaultRequestHeaders.Authorization = 
                new AuthenticationHeaderValue("Bearer", channelToken);
        }

        webClient.DownloadFile(remoteFileUrl, localFileName);
    }

Upvotes: 1

Suyash Gaur
Suyash Gaur

Reputation: 2861

Assuming the file was sent from skype client, the file resides on skype server.

To use the file you'll need skype authenticated token that you can get from the request sent by skype.

Please refer to following: How to read attachment content from bot framework C#?

Upvotes: 1

Related Questions