public SMSMessage MessageHandler(string From, string Body) { SMSMessage message = new SMSMessage(); message.message_in = Body; message.message_out = ReverseIt(Body).ToString(); message.Timestamp = DateTime.Now; var accountSid = "ACa3955b3a8072e7e0d5efd4e181ccd729"; var authToken = "4c9c9b0f6095d2954cfaec8aa48e28c2"; TwilioClient.Init(accountSid, authToken); try { var SMS = MessageResource.Create(to: new PhoneNumber(From), from: new PhoneNumber("+15873295321"), body: message.message_out); return(message); } catch (ApiException ex) { Console.WriteLine(ex.Message); return(null); } }
public List <SMSMessage> GetMessages() { List <SMSMessage> messages = new List <SMSMessage>(); string myConnectionString; myConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["symendsMySQL"].ConnectionString; MySqlConnection conn = null; try { conn = new MySqlConnection(myConnectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT id, message_in, message_out, Timestamp FROM messages"; cmd.Prepare(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { SMSMessage message = new SMSMessage(); message.id = reader.GetInt32(0); message.message_in = reader.GetString(1); message.message_out = reader.GetString(2); message.Timestamp = reader.GetDateTime(3); messages.Add(message); } } catch (MySqlException ex) { Console.WriteLine("Error: {0}", ex.ToString()); } finally { if (conn != null) { conn.Close(); } } return(messages); }
public bool SaveMessage(SMSMessage message) { string myConnectionString; myConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["symendsMySQL"].ConnectionString; MySqlConnection conn = null; try { conn = new MySqlConnection(myConnectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText += string.Format("INSERT INTO messages (message_in, message_out, Timestamp) VALUES (@message_in, @message_out, @Timestamp);"); cmd.Parameters.AddWithValue("@message_in", message.message_in); cmd.Parameters.AddWithValue("@message_out", message.message_out); cmd.Parameters.AddWithValue("@Timestamp", message.Timestamp); Console.WriteLine("Executing insert.... this could take a second."); try { cmd.ExecuteNonQuery(); return(true); } catch (MySqlException ex) { Console.WriteLine("Error: {0}", ex.ToString()); return(false); } } catch (MySqlException ex) { Console.WriteLine("Error: {0}", ex.ToString()); return(false); } finally { if (conn != null) { conn.Close(); } } }
public void ProcessMessage(Stream TwilioResponse) { //Lets open our plaintext stream test StreamReader messageReader = new StreamReader(TwilioResponse); String rawBody = messageReader.ReadToEnd(); NameValueCollection qs = HttpUtility.ParseQueryString(rawBody); string From = qs["From"]; string Body = qs["Body"]; WebOperationContext.Current.OutgoingRequest.Accept = "text/xml"; WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); ProcessMessage messageHandler = new ProcessMessage(); SMSMessage SMSMessage = messageHandler.MessageHandler(From, Body); if (SMSMessage != null) { SaveToDatabase saveMessage = new SaveToDatabase(); saveMessage.SaveMessage(SMSMessage); } }