public ResourceSet <MessageResource> ReadAllSMS(string date) { DateTime timeSent; if (!DateTime.TryParse(date, out timeSent)) { timeSent = DateTime.Today; } TwilioClient.Init(_accountSid, _authToken); try { return(MessageResource.Read(dateSent: timeSent)); } catch (Exception ex) { return(null); } }
public static List <SMSMessage> ReadSms() { try { TwilioClient.Init(accountSid, authToken); var messages = MessageResource.Read(); var result = new List <SMSMessage>(); foreach (var record in messages) { if (record.Body.ToLower().Trim().Contains("thanks for the message") || record.Body.ToLower().Trim().Contains("Oh") || record.Body.ToLower().Trim().Contains("system:")) { try { MessageResource.Delete(record.Sid); Console.WriteLine("Deleted junk! Yay!"); } catch (Exception e) { } continue; } else { MessageResource.Delete(record.Sid); } var parts = record.Body.Split(' '); var command = (parts.Length > 0 ? parts[0] : "").Trim().ToLower(); var tmpAmount = parts.Length > 1 ? parts[1] : "0"; int amount; Int32.TryParse(tmpAmount, out amount); result.Add(new SMSMessage(record.Sid, record.Body, record.From.ToString(), amount, command)); } return(result); } catch (Exception e) { Console.WriteLine("Didn't win the race : " + e.Message); return(new List <SMSMessage>()); } }
static void Main(string[] args) { // Find your Account Sid and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var messages = MessageResource.Read( to: new PhoneNumber("+15558675310"), from: new PhoneNumber("+15017122661"), dateSentAfter: new DateTime(2016, 8, 31)); foreach (var message in messages) { Console.WriteLine(message.Body); } }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console // DANGER! This is insecure. See http://twil.io/secure const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var messages = MessageResource.Read( pathSessionSid: "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); foreach (var record in messages) { Console.WriteLine(record.Sid); } }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var messages = MessageResource.Read( pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pathChannelSid: "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); foreach (var record in messages) { Console.WriteLine(record.Sid); } }
static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "accountSid"; const string authToken = "authToken"; const string serviceSid = "serviceSid"; const string channelSid = "channelSid"; TwilioClient.Init(accountSid, authToken); // List all messages var messages = MessageResource.Read(serviceSid, channelSid); foreach (var message in messages) { Console.WriteLine(message.DateCreated); } }
static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console // To set up environmental variables, see http://twil.io/secure const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID"); const string channelSid = "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; TwilioClient.Init(accountSid, authToken); // List all messages var messages = MessageResource.Read(serviceSid, channelSid); foreach (var message in messages) { Console.WriteLine(message.DateCreated); } }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var messages = MessageResource.Read( dateSent: new DateTime(2016, 8, 31, 0, 0, 0), from: new Twilio.Types.PhoneNumber("+15017122661"), to: new Twilio.Types.PhoneNumber("+15558675310") ); foreach (var record in messages) { Console.WriteLine(record.Sid); } }
static void Main(string[] args) { // Find your Account Sid and Auth Token at twilio.com/console // To set up environmental variables, see http://twil.io/secure const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); var messages = MessageResource.Read( to: new PhoneNumber("+15558675310"), from: new PhoneNumber("+15017122661"), dateSentAfter: new DateTime(2016, 8, 31)); foreach (var message in messages) { Console.WriteLine(message.Body); } }
public void TestReadRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Get, Twilio.Rest.Domain.Chat, "/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages", "" ); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { MessageResource.Read("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
public void TestReadRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Get, Twilio.Rest.Domain.Api, "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json", "" ); twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { MessageResource.Read(client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
static void Main(string[] args) { var dateToRun = args.Length >= 1 ? args[0] : DateTime.Now.AddDays(-1).ToShortDateString(); var fileName = $"twilio-logs.csv"; Console.WriteLine($"Fetching calls for {dateToRun}"); var path = $"./{fileName}"; if (!System.IO.File.Exists(path)) { using (System.IO.FileStream fs = System.IO.File.Create(path)){ Console.WriteLine("File Written"); } } using (var writer = new StreamWriter(fileName)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) { TwilioClient.Init(accountSid, authToken); var opts = new ReadMessageOptions() { PageSize = 100000, DateSentAfter = DateTime.Parse($"{dateToRun} 00:00:00") }; var messages = MessageResource.Read(opts); var exportRecords = messages.Select(x => new TwilioExportRecord { datecreated = x.DateCreated.ToString(), datesent = x.DateSent.ToString(), lastupdated = x.DateUpdated.ToString(), sid = x.Sid, status = x.Status.ToString(), url = x.Uri.ToString(), to = x.To.ToString() }); csv.WriteRecords(exportRecords); } }
public int IncomingMessagesCount(string subaccountsid, string to, string date) { try { var messages = MessageResource.Read( pathAccountSid: subaccountsid, dateSent: DateTimeParser(date), to: new PhoneNumber(FormatPhoneNumber(to)), client: _client); int MessageCount = 0; foreach (var record in messages) { MessageCount++; } return(MessageCount); } catch (ApiException) { throw; } }
public TwiMLResult Index() { try { // capture message // Your Account Sid and Token at twilio.com/console string accountSid = UT.Utility.GetAccountSid(); // this is my accountSID string authToken = UT.Utility.GetAuthToken(); // this si my authToken //initialize account TwilioClient.Init(accountSid, authToken); // get a list (collection) of messages var messages = MessageResource.Read(pathAccountSid: accountSid); //based on understanding from documentation first message is always the one that sent from phone and recevied on API end MessageResource mr = messages.FirstOrDefault <MessageResource>(); var message = MessageResource.Fetch(pathAccountSid: accountSid, pathSid: mr.Sid); //message.sid is message unique identifier // reverse the message string. string rvMsg = UT.Utility.StringReversal(message.Body.ToString()); //write to db. WriteMsgToDb(message.Body.ToString(), rvMsg); // response section. var messagingResponse = new MessagingResponse(); messagingResponse.Message(rvMsg); return(TwiML(messagingResponse)); } catch (Exception ex) { EX.ExceptionHandler.HandleException(ex); return(null); } }
public List <MessageResource> GetMessagesFromTwilio(PluginConfig pluginConfig, int secondsAgo) { this.Log.LogDebug("Starting GetMessagesFromTwilio"); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; TwilioClient.Init(pluginConfig.AccountSID, pluginConfig.AuthToken); ReadMessageOptions options = new ReadMessageOptions { To = new PhoneNumber(pluginConfig.FromNumber), DateSentAfter = DateTime.Now.AddSeconds(secondsAgo * -1) }; ResourceSet <MessageResource> messages = MessageResource.Read(options); foreach (MessageResource message in messages) { string from = message.From.ToString(); string body = message.Body; string created = message.DateCreated.GetValueOrDefault(DateTime.MinValue).ToLongDateString(); this.Log.LogDebug(string.Format("From: {0}, created: {1}, body: {2}", from, created, body)); } return(messages.Where((message) => message.DateCreated.GetValueOrDefault(DateTime.MinValue).CompareTo(options.DateSentAfter) >= 0).ToList()); }
protected void Page_Load(object sender, EventArgs e) { if (Session["user"] == null) { Response.Write("<script language=javascript> var agree; agree=confirm('You have to log in first'); window.location='Login.aspx';</script>"); } if (Convert.ToInt32(Session["userType"]) == 2) { getAgentsConvos(); LiteralControl nav = new LiteralControl(); nav.Text = "<a href=\"Registration.aspx\">Users</a>"; navADD.Controls.Add(nav); LiteralControl navedit = new LiteralControl(); navedit.Text = "<a href=\"EditHousingList.aspx\">Edit Housing List</a>"; editADD.Controls.Add(navedit); } if (Session["PhoneNumber"] == null) { Response.Write("<script language=javascript> var agree; agree=confirm('You have to log in first'); window.location='Login.aspx';</script>"); } int i = 0; string address = Request.QueryString["Address"]; Labelnum.Text = "Messages sent to " + address; const string accountSid = "AC81311ed7d5aa3a5b8debc7306abbb0ee"; const string authToken = "17d80aa7c2ad0c26a45b8607fba63dda"; TwilioClient.Init(accountSid, authToken); string qry = "select * from table4 where PropertyName = @PropertyName"; MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand(qry, conn); cmd.Parameters.AddWithValue("PropertyName", address); MySqlDataReader rdr = cmd.ExecuteReader(); LiteralControl literalControl = new LiteralControl(); literalControl.Text = "<div class=\"panel-group\" id=\"accordion\">"; test.Controls.Add(literalControl); while (rdr.Read()) { i++; LiteralControl literalControlHeader = new LiteralControl(); literalControlHeader.Text += "<div class=\"panel panel-default\">" + "<div class=\"panel-heading\">" + "<h4 class=\"panel-title\">" + "<a data-toggle=\"collapse\" data-parent=\"#accordion\" href=\"#collapse" + i + "\">" + rdr["FirstName"].ToString() + " " + rdr["LastName"].ToString() + " - " + rdr["Mobile"].ToString() + "</a>" + "</h4>" + "</div>" + "<div id=\"collapse" + i + "\" class=\"panel-collapse collapse\">" + "<div class=\"panel-body\">" + "<div id=\"scrolld" + i + "\" style=\"width:100%; max-height:400px; overflow: auto; text-align:center\">"; test.Controls.Add(literalControlHeader); //Response.Write("<script language=javascript>$(\"#scrolld" + i + "\").scrollTop($(\"#scrolld" + i +"\")[0].scrollHeight); "); //litscript.Text += ""; GridView GridView1 = new GridView(); test.Controls.Add(GridView1); DataTable convo = new DataTable(); convo.Columns.Add("From:", System.Type.GetType("System.String")); convo.Columns.Add("Message:", System.Type.GetType("System.String")); convo.Columns.Add("Time:", System.Type.GetType("System.DateTime")); var messages = MessageResource.Read(to: new PhoneNumber(rdr["Mobile"].ToString()), from: Session["PhoneNumber"].ToString()); foreach (var message in messages) { DataRow text = convo.NewRow(); text["From:"] = "You"; text["Message:"] = message.Body; if (message.DateSent == null) { text["Time:"] = DateTime.Now; } else { text["Time:"] = message.DateSent; } convo.Rows.Add(text); } var messages1 = MessageResource.Read(to: Session["PhoneNumber"].ToString(), from: new PhoneNumber(rdr["Mobile"].ToString())); foreach (var message in messages1) { DataRow text = convo.NewRow(); text["From:"] = rdr["FirstName"].ToString(); text["Message:"] = message.Body; if (message.DateSent == null) { text["Time:"] = DateTime.Now; } else { text["Time:"] = message.DateSent; } convo.Rows.Add(text); } convo.DefaultView.Sort = "Time: ASC"; GridView1.Width = Unit.Percentage(100); GridView1.DataSource = convo; GridView1.Style["width"] = "100%"; GridView1.DataBind(); LiteralControl literalControlrespond = new LiteralControl(); literalControlrespond.Text += "</div><br/><div style=\"text-align: center;\">"; test.Controls.Add(literalControlrespond); TextBox tb = new TextBox(); tb.Rows = 5; tb.Columns = 60; tb.Attributes.Add("maxlength", "1500"); tb.CssClass = "form-control"; tb.TextMode = TextBoxMode.MultiLine; tb.ID = rdr["Mobile"].ToString(); test.Controls.Add(tb); LiteralControl literalControlbtn = new LiteralControl(); literalControlbtn.Text += "</div><br/><div style=\"text-align: center;\">"; test.Controls.Add(literalControlbtn); Button btnsend = new Button(); btnsend.OnClientClick = "this.disabled = true; this.value = 'Sending...';"; btnsend.UseSubmitBehavior = false; btnsend.Text = "Send"; btnsend.Click += new EventHandler(btnevent_Click); btnsend.CommandArgument = rdr["Mobile"].ToString(); btnsend.CssClass = "btn btn-success"; test.Controls.Add(btnsend); LiteralControl literalControlBody = new LiteralControl(); literalControlBody.Text += "</div></div></div></div>"; test.Controls.Add(literalControlBody); } LiteralControl literalControlEnd = new LiteralControl(); literalControlEnd.Text += "</div>"; test.Controls.Add(literalControlEnd); //close Data Reader rdr.Close(); //close Connection conn.Close(); tbMessage.Attributes.Add("maxlength", "1500"); }
private void getAgentsConvos() { int i = 0; string address = Request.QueryString["Address"]; const string accountSid = "AC81311ed7d5aa3a5b8debc7306abbb0ee"; const string authToken = "17d80aa7c2ad0c26a45b8607fba63dda"; TwilioClient.Init(accountSid, authToken); LiteralControl literalControl = new LiteralControl(); literalControl.Text = "<div class=\"panel-group\" id=\"accordion1\">"; Div1.Controls.Add(literalControl); string qry = "select * from messages where Address = @PropertyName"; MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand(qry, conn); cmd.Parameters.AddWithValue("PropertyName", address); MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { string phoneNumber = rdr["phoneNumber"].ToString(); string qry2 = "select * from users where PhoneNumber = @PhoneNumber"; MySqlConnection conn2 = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); conn2.Open(); MySqlCommand cmd2 = new MySqlCommand(qry2, conn2); cmd2.Parameters.AddWithValue("PhoneNumber", phoneNumber); MySqlDataReader rdr2 = cmd2.ExecuteReader(); while (rdr2.Read()) { if (rdr2["PhoneNumber"].ToString() == Session["PhoneNumber"].ToString()) { } else { i++; LiteralControl literalControlHeader = new LiteralControl(); literalControlHeader.Text += "<div class=\"panel panel-default\">" + "<div class=\"panel-heading\">" + "<h4 class=\"panel-title\">" + "<a data-toggle=\"collapse\" data-parent=\"#accordion1\" href=\"#collapse1" + i + "\">" + rdr2["Firstname"].ToString() + " " + rdr2["Lastname"].ToString() + " - " + rdr2["PhoneNumber"].ToString() + "</a>" + "</h4>" + "</div>" + "<div id=\"collapse1" + i + "\" class=\"panel-collapse collapse\">" + "<div class=\"panel-body\">"; Div1.Controls.Add(literalControlHeader); // here we make inner accordian for messages sent to tenants from whatever agent LiteralControl literalControlInner = new LiteralControl(); literalControlInner.Text = "<div class=\"panel-group\" id=\"accordion2\">"; Div1.Controls.Add(literalControlInner); string qry3 = "select * from table4 where PropertyName = @PropertyName"; MySqlConnection conn3 = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); conn3.Open(); MySqlCommand cmd3 = new MySqlCommand(qry3, conn3); cmd3.Parameters.AddWithValue("PropertyName", address); MySqlDataReader rdr3 = cmd3.ExecuteReader(); while (rdr3.Read()) { i++; LiteralControl literalControlHeaderInner = new LiteralControl(); literalControlHeaderInner.Text += "<div class=\"panel panel-default\">" + "<div class=\"panel-heading\">" + "<h4 class=\"panel-title\">" + "<a data-toggle=\"collapse\" data-parent=\"#accordion2\" href=\"#collapseInner" + i + "\">" + rdr3["FirstName"].ToString() + " " + rdr3["LastName"].ToString() + " - " + rdr3["Mobile"].ToString() + "</a>" + "</h4>" + "</div>" + "<div id=\"collapseInner" + i + "\" class=\"panel-collapse collapse\">" + "<div class=\"panel-body\">" + "<div id=\"scrollb" + i + "\" style=\"width:100%; max-height:400px; overflow: auto; text-align:center\">"; Div1.Controls.Add(literalControlHeaderInner); //Response.Write("<script language=javascript>$(\"#scrollb"+i+ "\").scrollTop($(\"#scrollb" + i +"\")[0].scrollHeight); "); //litscript.Text += "<script language=javascript>$(\"#scrollb" + i + "\").scrollTop($(\"#scrollb" + i + "\")[0].scrollHeight);</script>"; GridView GridView1 = new GridView(); Div1.Controls.Add(GridView1); DataTable convo = new DataTable(); convo.Columns.Add("From:", System.Type.GetType("System.String")); convo.Columns.Add("Message:", System.Type.GetType("System.String")); convo.Columns.Add("Time:", System.Type.GetType("System.DateTime")); var messages = MessageResource.Read(to: new PhoneNumber(rdr3["Mobile"].ToString()), from: rdr2["PhoneNumber"].ToString()); foreach (var message in messages) { DataRow text = convo.NewRow(); text["From:"] = rdr2["Firstname"].ToString() + " " + rdr2["Lastname"].ToString(); text["Message:"] = message.Body; if (message.DateSent == null) { text["Time:"] = DateTime.Now; } else { text["Time:"] = message.DateSent; } convo.Rows.Add(text); } var messages1 = MessageResource.Read(to: rdr2["PhoneNumber"].ToString(), from: new PhoneNumber(rdr3["Mobile"].ToString())); foreach (var message in messages1) { DataRow text = convo.NewRow(); text["From:"] = rdr3["FirstName"].ToString(); text["Message:"] = message.Body; if (message.DateSent == null) { text["Time:"] = DateTime.Now; } else { text["Time:"] = message.DateSent; } convo.Rows.Add(text); } convo.DefaultView.Sort = "Time: ASC"; GridView1.Width = Unit.Percentage(100); GridView1.DataSource = convo; GridView1.Style["width"] = "100%"; GridView1.DataBind(); LiteralControl literalControlrespondInner = new LiteralControl(); literalControlrespondInner.Text += "</div></div></div></div>"; Div1.Controls.Add(literalControlrespondInner); } //close Data Reader rdr3.Close(); //close Connection conn3.Close(); LiteralControl literalControlBody = new LiteralControl(); literalControlBody.Text += "</div></div></div></div>"; Div1.Controls.Add(literalControlBody); } } //close Data Reader rdr2.Close(); //close Connection conn2.Close(); } LiteralControl literalControlEnd = new LiteralControl(); literalControlEnd.Text += "</div><hr/>"; Div1.Controls.Add(literalControlEnd); //close Data Reader rdr.Close(); //close Connection conn.Close(); }
static void Main(string[] args) { Console.WriteLine("Welcome to our shitty pseudo twillio chat client"); Console.WriteLine("At any point, you may hit the \"R\" key to interrupt and send a response to the last message "); Console.WriteLine(); Console.WriteLine(); string AccountSid = Environment.GetEnvironmentVariable("ACCOUNT_SID"); string AuthToken = Environment.GetEnvironmentVariable("AUTH_TOKEN"); string ListeningNumber = Environment.GetEnvironmentVariable("LISTENING_NUMBER"); List <MessageResource> processed = new List <MessageResource>(); if (AccountSid == null || AuthToken == null || ListeningNumber == null) { Console.WriteLine("Required environmental values not present. Please make sure both ACCOUNT_SID and AUTH_TOKEN are configured"); Environment.Exit(-1); } //Init the client TwilioClient.Init(AccountSid, AuthToken); while (true) { //Listen for CTRL+R to respond while (!Console.KeyAvailable) { var currentMessage = MessageResource.Read( to: new PhoneNumber(ListeningNumber) ).First(); if (!processed.Any(x => x.Sid == currentMessage.Sid)) { Console.WriteLine($"From {currentMessage.From}: {currentMessage.Body}"); } processed.Add(currentMessage); //Add it to the list for later evaluations Task.Delay(1000).Wait(); } switch (Console.ReadKey(true).Key.ToString().ToLower()) { case "r": Console.WriteLine(); Console.WriteLine("\tPlease type your response followed by enter"); string response = Console.ReadLine(); Console.WriteLine(); SendMessage(processed.Last().From.ToString(), response); break; case "s": Console.WriteLine(); Console.WriteLine("\tPlease enter the phone number you wish to message"); string to = NormalizePhoneString(Console.ReadLine()); Console.WriteLine("\tPlease type your message below"); string body = Console.ReadLine(); SendMessage(to, body); break; } } }
private bool CompareLatestMessage(string address) { MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); conn.Open(); string checkShowing = "select * from table4 where PropertyName = @Address"; MySqlCommand comd = new MySqlCommand(checkShowing, conn); comd.Parameters.AddWithValue("Address", address); MySqlDataReader dr = comd.ExecuteReader(); DataTable convo = new DataTable(); convo.Columns.Add("Message:", System.Type.GetType("System.String")); convo.Columns.Add("Time:", System.Type.GetType("System.DateTime")); while (dr.Read()) { const string accountSid = "AC81311ed7d5aa3a5b8debc7306abbb0ee"; const string authToken = "17d80aa7c2ad0c26a45b8607fba63dda"; TwilioClient.Init(accountSid, authToken); try { var messages = MessageResource.Read(to: new PhoneNumber(dr["Mobile"].ToString()), from: Session["PhoneNumber"].ToString()); foreach (var message in messages) { DataRow text = convo.NewRow(); text["Message:"] = message.Body; if (message.DateSent == null) { text["Time:"] = DateTime.Now; } else { text["Time:"] = message.DateSent; } convo.Rows.Add(text); } var messages1 = MessageResource.Read(to: Session["PhoneNumber"].ToString(), from: new PhoneNumber(dr["Mobile"].ToString())); foreach (var message in messages1) { DataRow text = convo.NewRow(); text["Message:"] = message.Body; if (message.DateSent == null) { text["Time:"] = DateTime.Now; } else { text["Time:"] = message.DateSent; } convo.Rows.Add(text); } } catch (Exception ex) { } } dr.Close(); conn.Close(); convo.DefaultView.Sort = "Time: ASC"; convo = convo.DefaultView.ToTable(); try { DataRow lastRow = convo.Rows[convo.Rows.Count - 1]; string lastmessage = lastRow["Message:"].ToString(); string qry2 = "select * from messages where phoneNumber = '" + Session["PhoneNumber"].ToString() + "' and Address = '" + address + "'"; MySqlConnection conn2 = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); conn2.Open(); MySqlCommand cmd2 = new MySqlCommand(qry2, conn2); MySqlDataReader rdr2 = cmd2.ExecuteReader(); while (rdr2.Read()) { if (rdr2["messageBody"].ToString() != lastmessage) { MySqlConnection connd = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); connd.Open(); string deleteString = "delete from messages where address = @address and phoneNumber = @PhoneNumber"; MySqlCommand comdd = new MySqlCommand(deleteString, connd); comdd.Parameters.AddWithValue("@address", address); comdd.Parameters.AddWithValue("@PhoneNumber", Session["PhoneNumber"].ToString()); comdd.ExecuteNonQuery(); connd.Close(); MySqlConnection conni = new MySqlConnection(ConfigurationManager.ConnectionStrings["TestCapstone"].ConnectionString); conni.Open(); string insertString = "insert into messages (Address, MessageBody, phoneNumber) " + "values (@Address, @MessageBody, @PhoneNumber) "; MySqlCommand comdi = new MySqlCommand(insertString, conni); comdi.Parameters.AddWithValue("@Address", address); comdi.Parameters.AddWithValue("@MessageBody", lastmessage); comdi.Parameters.AddWithValue("@PhoneNumber", Session["PhoneNumber"].ToString()); comdi.ExecuteNonQuery(); conni.Close(); return(true); } } rdr2.Close(); conn2.Close(); } catch (Exception ex) { return(false); } return(false); }
static void Main(string[] args) { while (true) { Thread.Sleep(1000); { string SID = ConfigurationSettings.AppSettings.Get("sid"); string AUTH = ConfigurationSettings.AppSettings.Get("auth"); TwilioClient.Init(SID, AUTH); var messages = MessageResource.Read(limit: 1, dateSent: DateTime.Now); foreach (var record in messages) { string Body = record.Body.ToString(); if (Body.StartsWith("Shutdown PC")) { Process shutdown = new Process(); shutdown.StartInfo.FileName = "shutdown.exe"; shutdown.StartInfo.Arguments = "/s /f /t 0"; shutdown.Start(); } if (Body.StartsWith("shutdown /s /f /t 0")) { Process shutdown = new Process(); shutdown.StartInfo.FileName = "shutdown.exe"; shutdown.StartInfo.Arguments = "/s /f /t 0"; shutdown.Start(); } if (Body.StartsWith("Restart PC")) { Process restart = new Process(); restart.StartInfo.FileName = "shutdown.exe"; restart.StartInfo.Arguments = "/r /f /t 0"; restart.Start(); } if (Body.StartsWith("shutdown /r /f /t 0")) { Process restart = new Process(); restart.StartInfo.FileName = "shutdown.exe"; restart.StartInfo.Arguments = "/r /f /t 0"; restart.Start(); } if (Body.StartsWith("Hibernate PC")) { Process hibernate = new Process(); hibernate.StartInfo.FileName = "shutdown.exe"; hibernate.StartInfo.Arguments = "/h"; hibernate.Start(); } if (Body.StartsWith("shutdown /h")) { Process hibernate = new Process(); hibernate.StartInfo.FileName = "shutdown.exe"; hibernate.StartInfo.Arguments = "/h"; hibernate.Start(); } if (Body.StartsWith("Shutdown PC on next boot")) { Process g = new Process(); g.StartInfo.FileName = "shutdown.exe"; g.StartInfo.Arguments = "/g"; } if (Body.StartsWith("shutdown /g")) { Process g = new Process(); g.StartInfo.FileName = "shutdown.exe"; g.StartInfo.Arguments = "/g"; } if (Body.StartsWith("Shutdown PC and go to firmware settings")) { Process fw = new Process(); fw.StartInfo.FileName = "shutdown.exe"; fw.StartInfo.Arguments = "/fw"; } if (Body.StartsWith("shutdown /fw")) { Process fw = new Process(); fw.StartInfo.FileName = "shutdown.exe"; fw.StartInfo.Arguments = "/fw"; } } } } }
static void Main(string[] args) { IWebDriver _driver = new ChromeDriver(); _driver.Manage().Window.Maximize(); _driver.Navigate().GoToUrl("https://www.amazon.in"); #region CreateAccount //IWebElement signInButton = _driver.FindElement(By.CssSelector("#nav-link-accountList > span.nav-line-1")); //signInButton.Click(); //IWebElement createAccount = _driver.FindElement(By.CssSelector("#createAccountSubmit")); //createAccount.Click(); //IWebElement yourName = _driver.FindElement(By.CssSelector("#ap_customer_name")); //yourName.SendKeys("Test"); //IWebElement ccDropDown = _driver.FindElement(By.CssSelector("#auth-country-picker")); //SelectElement countryCode = new SelectElement(ccDropDown); //countryCode.SelectByText("US +1"); //IWebElement mobileNumber = _driver.FindElement(By.CssSelector("#ap_phone_number")); //mobileNumber.SendKeys("8635937563"); //IWebElement passWord = _driver.FindElement(By.CssSelector("#ap_password")); //passWord.SendKeys("Test2345"); //to avoid the apperance of capTCHA static wait is used //Thread.Sleep(700); //IWebElement continueButton = _driver.FindElement(By.CssSelector("#continue")); //continueButton.Click(); //IWebElement oTP = _driver.FindElement(By.CssSelector("#auth-pv-enter-code")); //oTP.SendKeys(otp); //IWebElement createAmazonAccount = _driver.FindElement(By.CssSelector("#auth-verify-button")); //createAmazonAccount.Click(); #endregion IWebElement signInButton = _driver.FindElement(By.CssSelector("#nav-link-accountList > span.nav-line-1")); signInButton.Click(); //enter mobile number and password to login IWebElement enterMobileNumber = _driver.FindElement(By.CssSelector("#ap_email")); enterMobileNumber.SendKeys("8635937563"); IWebElement continueButton = _driver.FindElement(By.CssSelector("#continue")); continueButton.Click(); IWebElement password = _driver.FindElement(By.CssSelector("#ap_password")); password.SendKeys("Test2345"); IWebElement loginButton = _driver.FindElement(By.CssSelector("#signInSubmit")); loginButton.Click(); IWebElement sendOtpButton = _driver.FindElement(By.CssSelector("#continue")); sendOtpButton.Click(); //Get the OTP using Twilio Account const string accountSid = "AC56f4e0ec37b7cc42807ad75369747e4a"; const string authToken = "2ae8777060d091980245514beacf50d9"; TwilioClient.Init(accountSid, authToken); var message = MessageResource.Read().First(); string smsBody = message.Body; string otp = Regex.Replace(smsBody, "[^-0-9]+", " "); Console.WriteLine(otp); IWebElement enterOtpButton = _driver.FindElement(By.CssSelector("div:nth-child(2) > input")); enterOtpButton.SendKeys(otp); IWebElement conButton = _driver.FindElement(By.CssSelector("#a-autoid-0>span>input")); conButton.Click(); _driver.Close(); _driver.Quit(); }