Ejemplo n.º 1
0
        /// <summary>
        /// Used to add channel manually by command "add channel channelname". - JJ
        /// </summary>
        /// <param name="slackChannelName">slack channel name from which message is send</param>
        /// <param name="slackChannelId">slack channel id from which message is send</param>
        /// <param name="slackUserId">slack user id of interacting user</param>
        /// <returns>status message</returns>
        public async Task <string> AddChannelManuallyAsync(string slackChannelName, string slackChannelId, string slackUserId)
        {
            //Checks whether channelId starts with "G" or "C". This is done inorder to make sure that only gruops or channels are added manually
            if (IsPrivateChannel(slackChannelId))
            {
                var accessToken = await GetAccessToken(slackUserId);

                if (accessToken != null)
                {
                    SlackChannelDetails slackChannelDetails = new SlackChannelDetails();
                    slackChannelDetails.ChannelId = slackChannelId;
                    slackChannelDetails.CreatedOn = DateTime.UtcNow;
                    slackChannelDetails.Deleted   = false;
                    slackChannelDetails.Name      = slackChannelName;
                    await _slackChannelRepository.AddSlackChannelAsync(slackChannelDetails);

                    return(_stringConstant.ChannelAddSuccess);
                }
                else
                {
                    // if user doesn't exist then this message will be shown to user
                    return(_stringConstant.YouAreNotInExistInOAuthServer);
                }
            }
            else
            {
                return(_stringConstant.OnlyPrivateChannel);
            }
        }
        /// <summary>
        /// Add slack channel details to the database - JJ
        /// </summary>
        /// <param name="slackChannelDetails">Slack channel details obtained from slack</param>
        /// <returns></returns>
        private async Task AddChannelGroupAsync(SlackChannelDetails slackChannelDetails)
        {
            SlackChannelDetails slackChannel = await _slackChannelDetails.FirstOrDefaultAsync(x => x.ChannelId == slackChannelDetails.ChannelId);

            if (slackChannel == null)
            {
                if (!slackChannelDetails.Deleted)
                {
                    slackChannelDetails.CreatedOn = DateTime.UtcNow;
                    await _slackChannelRepository.AddSlackChannelAsync(slackChannelDetails);
                }
            }
            else
            {
                slackChannel.Name = slackChannelDetails.Name;
                await _slackChannelRepository.UpdateSlackChannelAsync(slackChannel);
            }
        }
        public async Task SlackChannelAdd()
        {
            await _slackChannelRepository.AddSlackChannelAsync(slackChannelDetails);

            Assert.Equal(slackChannelDetails.ChannelId, _stringConstant.ChannelIdForTest);
        }