public Customer DoAction(StateActionDto dto) { var message = _messageService.GetRandomTypedMessage(MessageType.IntroGreetingReturning).Text; var customer = dto.Customer; customer.Session.AwaitState = SessionState.Listening; if (string.IsNullOrEmpty(customer.Name)) { message += System.Environment.NewLine + System.Environment.NewLine + _messageService.GetRandomTypedMessage(MessageType.RequestName).Text; customer.Session.AwaitState = SessionState.AwaitName; } _twilioService.SendMessage(new SendMessageDto { FromNumber = dto.MyNumber, ToNumber = customer.PhoneNumber }, new MessageBuilderContext { Customer = customer, InputText = dto.InputText, SendText = message }); return(customer); }
/// <summary> /// Send SMS /// </summary> /// <param name="contactInfo"></param> /// <returns></returns> public bool SendSms(SmsRequestModel contactInfo) { try { var smsBody = string.Format( "Emergency contact first name: {0}, {0} has activated a safety feature through our YayYo ride-sharing application. " + "{0} was picked up at: {1} from: {2}. {0} was to be dropped off at: {3}.", contactInfo.FirstName, contactInfo.RideScheduledTime, contactInfo.RiderPickupLocation, contactInfo.DestinationAddress); if (!string.IsNullOrEmpty(contactInfo.GeolocationAddress)) { var geolocationAddress = string.Format(" {0} last known location is: {1}", contactInfo.FirstName, contactInfo.GeolocationAddress); smsBody += geolocationAddress; } var fromPhone = ConfigurationManager.AppSettings["TwilioFromPhone"]; var messageResponse = _twilioService.SendMessage(fromPhone, contactInfo.ContactPhoneNumber, smsBody); if (messageResponse == null || messageResponse.ErrorCode != 0) { return(false); } return(true); } catch { return(false); } }
public Customer DoAction(StateActionDto dto) { var customer = dto.Customer; string message = ""; var response = _googleAnalyticsService.Analyze(dto.InputText); var person = response.Entities.FirstOrDefault(e => e.Type == Type.Person); if (person != null) { customer.Name = person.Name; message = _messageService.GetRandomTypedMessage(MessageType.RequestNameResponseSuccess).Text; customer.Session.AwaitState = SessionState.Listening; } else { message = _messageService.GetRandomTypedMessage(MessageType.RequestNameResponseFail).Text; customer.Session.AwaitState = SessionState.AwaitName; } _twilioService.SendMessage(new SendMessageDto { FromNumber = dto.MyNumber, ToNumber = customer.PhoneNumber }, new MessageBuilderContext { Customer = customer, InputText = dto.InputText, SendText = message });; return(customer); }
public IActionResult Post([FromBody] SendMessageRequest sendMessageRequest) { SendMessageResponse response = new SendMessageResponse(); if (!ModelState.IsValid) { // validation errors have occurred foreach (var modelState in ModelState.Values) { foreach (var error in modelState.Errors) { response.ErrorMessages.Add(new ErrorMessage { Message = error.ErrorMessage }); } } return(BadRequest(response)); // send message } response = _twilioService.SendMessage(sendMessageRequest.Message, sendMessageRequest.MobileNo); if (!response.IsSuccess) { return(BadRequest(response)); } response.SuccessMessage = $"{sendMessageRequest.Message} sent to {sendMessageRequest.MobileNo} successfully"; return(Ok(response)); }
public async Task <IActionResult> Post([FromBody] MessageResource message) { var messageSid = await _twilioService.SendMessage(message); _logger.LogInformation($"Message Sid: {messageSid} sent."); // _twilioService.SendMessage will create the response and send it, however // the Twilio webhook will still expect a response, so we return an empty // <Response></Response> return(Content("<Response></Response>", "text/xml")); }
public Customer DoAction(StateActionDto dto) { var customer = dto.Customer; var listeningActions = _listeningActionService.GetListeningActionsByMatch(dto.InputText); var priorities = new List <Func <MessageBuilderContext> > { () => NoMatch(customer, listeningActions), () => UniqueTypedMatch(customer, listeningActions), () => MultipleTypedMatches(customer, listeningActions), () => GeneralMatch(customer, listeningActions) }; var mbContext = new MessageBuilderContext(); foreach (var func in priorities) { mbContext = func(); if (mbContext == null) { continue; } else { break; } } mbContext.InputText = dto.InputText; _twilioService.SendMessage(new SendMessageDto { FromNumber = dto.MyNumber, ToNumber = customer.PhoneNumber }, mbContext); return(customer); }
public IActionResult SendSMS([FromBody] SendSMS sendSMS) { _twilioService.SendMessage(sendSMS.Message, sendSMS.PhoneNumber); return(Ok()); }