Example #1
0
        public async Task SendMemory(string memoryToSend, string fromPhoneNumber, IEnumerable <string> phoneNumbers)
        {
            if (string.IsNullOrEmpty(memoryToSend) ||
                string.IsNullOrEmpty(fromPhoneNumber))
            {
                return;
            }

            var parameterDictionary = await _parameterManagementService.RetrieveParameters(new List <string>
            {
                Constants.TwilioAccountSidKey,
                Constants.TwilioAuthTokenKey,
                Constants.TwilioPhoneNumberKey
            });

            // initialize client
            TwilioClient.Init(parameterDictionary[Constants.TwilioAccountSidKey], parameterDictionary[Constants.TwilioAuthTokenKey]);

            var textTaskList = new List <Task <MessageResource> >();

            // send text(s)
            foreach (var phoneNumber in phoneNumbers)
            {
                var textTask = MessageResource.CreateAsync(
                    body: memoryToSend,
                    from: new Twilio.Types.PhoneNumber(parameterDictionary[Constants.TwilioPhoneNumberKey]),
                    to: new Twilio.Types.PhoneNumber(phoneNumber)
                    );

                textTaskList.Add(textTask);
            }

            // wait until done sending to all numbers
            await Task.WhenAll(textTaskList);
        }
        public async Task RetrieveParameters_GivenEmptyDictionary_MakesExpectedCallsAndReturnsParameters()
        {
            var parameterKeyList = new List <string> {
                "key1", "key2", "key3"
            };

            var result = await _sut.RetrieveParameters(parameterKeyList);

            _ssmMock.Verify(m => m.GetParameterAsync(
                                It.IsAny <GetParameterRequest>(),
                                It.IsAny <CancellationToken>()),
                            Times.Exactly(parameterKeyList.Count));

            foreach (var key in parameterKeyList)
            {
                Assert.Equal(key + "Value", result[key]);
            }
        }
        public async Task <RememberWhenResponseModel> Run()
        {
            // retrieve all sensitive parameters
            var parameterDictionary = await _parameterManagementService.RetrieveParameters(Constants.ParameterKeys);

            // determine environment
            var isProduction = _environmentService.EnvironmentType == Environments.Production;

            // select memory
            var memoryToSend = _memoryService.RetrieveRandomMemory();

            // find email addresses to send memory to
            var emailsToSendTo = new List <string> {
                parameterDictionary[Constants.HusbandEmailKey]
            };

            if (isProduction)
            {
                emailsToSendTo.Add(parameterDictionary[Constants.WifeEmailKey]);
            }

            // send memory to email addresses
            await _emailService.SendMemory(memoryToSend, parameterDictionary[Constants.HusbandEmailKey], emailsToSendTo);

            if (isProduction)
            {
                // send memory to phones via text
                await _textMessageService.SendMemory(
                    memoryToSend,
                    parameterDictionary[Constants.TwilioPhoneNumberKey],
                    new string[2] {
                    parameterDictionary[Constants.HusbandPhoneNumberKey], parameterDictionary[Constants.WifePhoneNumberKey]
                }
                    );
            }

            return(new RememberWhenResponseModel(memoryToSend));
        }