/// <summary> /// Initializes a new instance of the <see cref="CompanyCommunicatorBotFilterMiddleware"/> class. /// </summary> /// <param name="configuration">ASP.NET Core <see cref="IConfiguration"/> instance.</param> public CompanyCommunicatorBotFilterMiddleware(IConfiguration configuration, DiscoveryCache discoveryCache, AtWorkRioIdentityOptions atWorkRioIdentityOptions) { this.configuration = configuration; this.discoveryCache = discoveryCache; this.atWorkRioIdentityOptions = atWorkRioIdentityOptions; }
/// <summary> /// Initializes a new instance of the <see cref="CompanyCommunicatorBot"/> class. /// </summary> /// <param name="teamsDataCapture">Teams data capture service.</param> public CompanyCommunicatorBot(TeamsDataCapture teamsDataCapture, DiscoveryCache discoveryCache, AtWorkRioIdentityOptions atWorkRioIdentityOptions) { this.teamsDataCapture = teamsDataCapture; this.discoveryCache = discoveryCache; this.atWorkRioIdentityOptions = atWorkRioIdentityOptions; }
public static async Task <List <SgcpDocumentListDTO> > SearchDocuments(string code, DiscoveryCache discoveryCache, AtWorkRioIdentityOptions atWorkRioIdentityOptions) { var disco = await discoveryCache.GetAsync(); if (disco.IsError) { throw new Exception(disco.Error); } var tokenClient = new HttpClient(); var tokenResponse = await tokenClient.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest { Address = disco.TokenEndpoint, ClientId = atWorkRioIdentityOptions.SgcpTeamsClientId, ClientSecret = atWorkRioIdentityOptions.SgcpTeamsClientSecret, Scope = "https://sgcp-teams.atworkrio.com https://plantra.atworkrio.com" }); if (tokenResponse.IsError) { throw new Exception(tokenResponse.Error); } // call API var apiClient = new HttpClient(); apiClient.SetBearerToken(tokenResponse.AccessToken); try { var json = await apiClient.GetStringAsync( $"{atWorkRioIdentityOptions.SgcpTeamsApiUrl}/teams/docSearch?code={Uri.EscapeUriString(code)}"); var docs = JsonConvert.DeserializeObject <Envelope <List <SgcpDocumentListDTO> > >(json); if (docs.Result != null) { return(docs.Result); } } catch { } return(new List <SgcpDocumentListDTO>()); }