Last active
August 13, 2016 09:15
-
-
Save jfversluis/23e6bfef80e2b93af60be649dcc1bb91 to your computer and use it in GitHub Desktop.
Bot Framework code to get bytes from Attachment on Skype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte[] imageBytes = null; | |
// For Skype we need to get an OAuth token to access the content url | |
if (activity.ChannelId.ToLower() == "skype") | |
{ | |
using (var httpClient = new HttpClient()) | |
{ | |
// Request OAuth token | |
var formValues = new KeyValuePair<string, string>[] | |
{ | |
new KeyValuePair<string, string>("client_id", ConfigurationManager.AppSettings["MicrosoftAppId"]), | |
new KeyValuePair<string, string>("client_secret", ConfigurationManager.AppSettings["MicrosoftAppPassword"]), | |
new KeyValuePair<string, string>("grant_type", "client_credentials"), | |
new KeyValuePair<string, string>("scope", "https://graph.microsoft.com/.default") | |
}; | |
// Anonymous definition for return object | |
var definition = new { access_token = "" }; | |
var tokenJson = await httpClient.PostAsync("https://login.microsoftonline.com/common/oauth2/v2.0/token", | |
new FormUrlEncodedContent(formValues)); | |
var token = JsonConvert.DeserializeAnonymousType(await tokenJson.Content.ReadAsStringAsync(), definition); | |
// Set Bearer: <token> header for the request | |
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); | |
imageBytes = await httpClient.GetByteArrayAsync(attachment.ContentUrl); | |
} | |
} | |
else | |
imageBytes = BotHelper.ConvertContentToByteArray(attachment.ContentUrl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment