public void Send(OutgoingMessage outgoingMessage) { var client = new RestClient(TwilioBaseUrl); client.Authenticator = new HttpBasicAuthenticator(AccountSid, AuthToken); const string sendResource = "/SMS/Messages.json"; var request = new RestRequest(sendResource, Method.POST); request.AddParameter("From", From); request.AddParameter("To", outgoingMessage.To); request.AddParameter("Body", outgoingMessage.Body); var response = client.Post<TwilioResponse>(request); if (response.ErrorException != null) { throw response.ErrorException; } if(response.Data.Status!="queued") { throw new Exception(response.Data.Message); } _repository.Create(new LoggedOutgoingMessage { Body = outgoingMessage.Body, Sent = SystemDateTime.Now(), ToNumber = outgoingMessage.To }); }
//POST /api/Cases/SendCaseNumber/{caseId} public void SendCaseNumber(Guid caseId) { var wantedCase = _repository.Get<Case>(caseId); var caseNumber = wantedCase.CaseNumber(); var message = new OutgoingMessage(wantedCase.CellPhoneNumber, "Su número de caso es: " + caseNumber); _sender.Send(message); }
// POST: /ChatMessages/{cellPhoneNumber, body} public void Post(OutgoingMessage outgoingMessage) { _messageSender.Send(outgoingMessage); }