public static async Task <string> GetFolderId([ActivityTrigger] RequestData requestData, TraceWriter log) { httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); var response = await httpClient.GetAsync($"https://graph.microsoft.com/v1.0/users/{requestData.UserId}/mailFolders?$filter=displayName eq 'Conversation History'&$select=id"); if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { token = await AccessTokenService.FetchToken(); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); response = await httpClient.GetAsync($"https://graph.microsoft.com/v1.0/users/{requestData.UserId}/mailFolders?$filter=displayName eq 'Conversation History'&$select=id"); } response.EnsureSuccessStatusCode(); var responseData = JsonConvert.DeserializeObject <ResponseData>(await response.Content.ReadAsStringAsync()); if (responseData.Value.Length == 1) { return(responseData.Value[0].id); } else { response = await httpClient.GetAsync($"https://graph.microsoft.com/v1.0/users/{requestData.UserId}/mailFolders?$filter=displayName eq '会話の履歴'&$select=id"); response.EnsureSuccessStatusCode(); responseData = JsonConvert.DeserializeObject <ResponseData>(await response.Content.ReadAsStringAsync()); return(responseData.Value[0].id); } }
public static async Task <List <String> > GetUsers([ActivityTrigger] DurableActivityContext context, TraceWriter log) { var token = await AccessTokenService.FetchToken(); var ids = await UserService.FetchUsers(token); return(ids); }
public static async Task <List <ConversationHistoryTableStorage> > GetMessages([ActivityTrigger] RequestData requestData, TraceWriter log) { var list = new List <ConversationHistoryTableStorage>(); string endpoint = $"https://graph.microsoft.com/v1.0/users/{requestData.UserId}/mailFolders/{requestData.ConversationHistoryId}/messages?$select=id,body,sender,from,toRecipients"; ResponseData responseData; do { httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); var response = await httpClient.GetAsync(endpoint); if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { token = await AccessTokenService.FetchToken(); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); response = await httpClient.GetAsync(endpoint); } response.EnsureSuccessStatusCode(); responseData = JsonConvert.DeserializeObject <ResponseData>(await response.Content.ReadAsStringAsync()); foreach (var data in responseData.Value) { foreach (var to in data.toRecipients) { var fromAddress = data.from.emailAddress.name; var toAddress = to.emailAddress.name; if (fromAddress.Equals(toAddress) == false) { var domain = data.from.emailAddress.address.Split('@')[1]; list.Add(new ConversationHistoryTableStorage { PartitionKey = domain, RowKey = Guid.NewGuid().ToString(), From = fromAddress, To = toAddress }); } } } } while (String.IsNullOrEmpty(endpoint = responseData.odatanextLink) == false); return(list); }