private async Task <IEnumerable <ChannelDto> > GetSlackConversationsByIds(IEnumerable <string> channelIds)
        {
            var conversations = await _slackFacade.GetConversations();

            var relevantConversations = conversations.Channels.Where(c => channelIds.Contains(c.Id));


            return(relevantConversations);
        }
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = new CancellationToken())
        {
            GetConversationsResponse result;

            try
            {
                result = await _slackFacade.GetConversations();
            }
            catch (Exception exception)
            {
                return(HealthCheckResult.Degraded("Unable to get expected response from Slack"));
            }

            if (result.Ok)
            {
                return(HealthCheckResult.Healthy("Slack is capable of returning an response from their API"));
            }

            return(HealthCheckResult.Degraded("Unable to get expected response from Slack"));
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteConnection(
            [FromQuery] string clientType,
            [FromQuery] string clientId,
            [FromQuery] string channelType,
            [FromQuery] string channelId)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                return(BadRequest(new { message = "ClientId ID is required." }));
            }

            ClientType  clientTypeValueObject;
            ChannelType channelTypeValueObject;

            try
            {
                clientTypeValueObject  = string.IsNullOrEmpty(clientType) ? null : (ClientType)clientType;
                channelTypeValueObject = string.IsNullOrEmpty(channelType) ? null : (ChannelType)channelType;
            }
            catch (ValidationException validationException)
            {
                return(StatusCode(
                           (int)HttpStatusCode.UnprocessableEntity,
                           new { message = validationException.MessageToUser }
                           ));
            }

            var getMatchedConnectionsQuery = new FindConnectionsByClientTypeClientIdChannelTypeChannelId(
                clientTypeValueObject,
                (ClientId)clientId,
                channelTypeValueObject,
                (ChannelId)channelId);

            var matchedConnections =
                await _findConnectionsByClientTypeClientIdChannelTypeChannelIdQueryHandler.HandleAsync(
                    getMatchedConnectionsQuery);

            foreach (var connection in matchedConnections)
            {
                await _slackFacade.LeaveChannel(connection.ChannelId.ToString());

                var getAllChannelConnectionsQuery = new FindConnectionsByClientTypeClientIdChannelTypeChannelId(
                    null,
                    null,
                    connection.ChannelType,
                    connection.ChannelId);

                var allChannelConnections =
                    await _findConnectionsByClientTypeClientIdChannelTypeChannelIdQueryHandler.HandleAsync(
                        getAllChannelConnectionsQuery);

                var capability = Capability.Create(Guid.Parse(connection.ClientId), connection.ClientName,
                                                   connection.ChannelId, "");
                await _capabilityRepository.Remove(capability);

                if (allChannelConnections.All(c => c.ClientId.ToString().Equals(clientId)))
                {
                    var channelsAll = await _slackFacade.GetConversations();

                    var channelsWhereConnectionIdAndChannelCreatorMatches = channelsAll.Channels.Where(ch =>
                                                                                                       ch.Creator.Equals(_slackFacade.GetBotUserId())
                                                                                                       &&
                                                                                                       ch.Id.Equals(connection.ChannelId));

                    if (channelsWhereConnectionIdAndChannelCreatorMatches.Any())
                    {
                        await _slackFacade.ArchiveChannel(connection.ChannelId.ToString());
                    }
                }
            }

            return(Accepted());
        }