Пример #1
0
        public Task Received(MessageRequest request)
        {
            if (String.IsNullOrEmpty(request.ChannelId))
            {
                request.ChannelId = Constants.PUBLIC_CHANNEL_ID;
            }

            SendToChannel(new MessageResponse
            {
                Channel = GetChannelDetail(request.ChannelId),
                Message = request.Message,
                Origin  = MessageIndividual.User,
                Target  = MessageIndividual.Channel
            });

            return(Task.CompletedTask);
        }
Пример #2
0
        public string GetRecipientAddress(MessageRequest message)
        {
            try
            {
                //Checking if input message contains correct email address if not checking value from email address node
                if (message.Recipient.LegalForm == LegalForm.Person)
                {
                    if (message.Recipient.Contacts.Any(x => x.ContactType == ContactType.Email && Regex.IsMatch(x.Value, GlobalConst.EmailValidationPattern)))
                    {
                        return(message.Recipient.Contacts.FirstOrDefault(x => x.ContactType == ContactType.Email && Regex.IsMatch(x.Value, GlobalConst.EmailValidationPattern)).Value);
                    }
                    else if (message.Recipient.Contacts.Any(x => x.ContactType == ContactType.Email))
                    {
                        return(message.Recipient.Contacts.FirstOrDefault(x => x.ContactType == ContactType.Email).Value);
                    }
                    else
                    {
                        return(null);
                    }
                }

                else
                {
                    if (message.Recipient.Contacts.Any(x => x.ContactType == ContactType.OfficeEmail && Regex.IsMatch(x.Value, GlobalConst.EmailValidationPattern)))
                    {
                        return(message.Recipient.Contacts.FirstOrDefault(x => x.ContactType == ContactType.Email && Regex.IsMatch(x.Value, GlobalConst.EmailValidationPattern)).Value);
                    }
                    else if (message.Recipient.Contacts.Any(x => x.ContactType == ContactType.OfficeEmail))
                    {
                        return(message.Recipient.Contacts.FirstOrDefault(x => x.ContactType == ContactType.Email).Value);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception error)
            {
                //Logging error
                ErrorLogger.Log(ReturnCode.InternalError, error.Message);
                return(null);
            }
        }
Пример #3
0
        public MessageResponse Send(MessageRequest message)
        {
            //Setting dependency injection container
            IKernel kernel = new StandardKernel();

            kernel.Load(Assembly.GetExecutingAssembly());

            var databaseConnection       = kernel.Get <IDatabaseConnection>();
            var recipientAddressResolver = kernel.Get <IRecipientAddressResolver>();

            recipientAddress = recipientAddressResolver.GetRecipientAddress(message);

            MessageValidator messageValidator = new MessageValidator(message, recipientAddress);

            string validationResult = messageValidator.ValidateMessage();

            //Send response using interface if input message validation was successful
            if (validationResult == "Message validated successfully")
            {
                var sender = kernel.Get <ISender>();
                //Send requested message to recipient
                sender.SendMessage(message, recipientAddress);
            }

            //Write exceptions to database
            databaseConnection.WriteToDatabase(message, recipientAddress, ErrorLogger.Logs);

            //Return response
            if (!ErrorLogger.LogsNonEmpty && validationResult == "Message validated successfully")
            {
                return(new MessageResponse(ReturnCode.Success, null));
            }
            else if (!ErrorLogger.LogsNonEmpty)
            {
                return(new MessageResponse(ReturnCode.ValidationError, validationResult));
            }
            else
            {
                return(ErrorLogger.Logs);
            }
        }
Пример #4
0
        public Task Typed(MessageRequest request)
        {
            if (String.IsNullOrEmpty(request.ChannelId))
            {
                request.ChannelId = Constants.PUBLIC_CHANNEL_ID;
            }

            var currentUser = GetCurrentUser();

            request.Message = new MessageContent {
                Text = $"{currentUser.FullName} finished typing."
            };

            SendToChannel(new MessageResponse
            {
                Channel = GetChannelDetail(request.ChannelId),
                Message = request.Message,
                Command = MessageCommand.UserTypingEnd,
                Origin  = MessageIndividual.System,
                Target  = MessageIndividual.Channel
            });

            return(Task.CompletedTask);
        }
Пример #5
0
 public MessageValidator(MessageRequest message, string recipientAddress)
 {
     this.message          = message;
     this.recipientAddress = recipientAddress;
 }