Initial commit
This commit is contained in:
		
						commit
						1c5fa2e6c7
					
				| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					################################################################################
 | 
				
			||||||
 | 
					# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
 | 
				
			||||||
 | 
					################################################################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/.vs
 | 
				
			||||||
 | 
					/obj
 | 
				
			||||||
 | 
					/TwilioDDT.sln
 | 
				
			||||||
 | 
					/TwilioDDT.csproj
 | 
				
			||||||
 | 
					/Credentials.cs
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,154 @@
 | 
				
			||||||
 | 
					using System.Data.SqlClient;
 | 
				
			||||||
 | 
					using Twilio;
 | 
				
			||||||
 | 
					using Twilio.Types;
 | 
				
			||||||
 | 
					using Twilio.Rest.Api.V2010.Account;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class TwilioDDT
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Dictionary<string, string> results = new Dictionary<string, string>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void Main(string[] args)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        string PhoneNumber = "";
 | 
				
			||||||
 | 
					        string[] NumbersToText = ["248-891-3712"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TextAgent agent = new TextAgent(PhoneNumber, NumbersToText);
 | 
				
			||||||
 | 
					        var message = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var results = agent.SendTexts(message);
 | 
				
			||||||
 | 
					        Console.WriteLine(results.ToString());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public class TextAgent
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Class Variables
 | 
				
			||||||
 | 
					        PhoneNumber PhoneNumber; // Number to send from
 | 
				
			||||||
 | 
					        string[] InputNumbers = Array.Empty<string>(); // Numbers to blast to
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public TextAgent(string ShopNumber, string[] TargetList)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            PhoneNumber = new PhoneNumber(ShopNumber);
 | 
				
			||||||
 | 
					            InputNumbers = TargetList;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Dictionary<string, string> SendTexts(string GenericMessage)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (InputNumbers.Length < 1 || GenericMessage.Length < 1)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // Input data is invalid; do not initiate sequence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 
 | 
				
			||||||
 | 
					                return new Dictionary<string, string>();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Initialize SQL Agent
 | 
				
			||||||
 | 
					            SqlDriver db = new SqlDriver("CONN_STRING");
 | 
				
			||||||
 | 
					            db.GatherUsers("SQL_QUERY_TO_GET_USERS");
 | 
				
			||||||
 | 
					            // TODO: read values from table into list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var result = new Dictionary<string, string>();
 | 
				
			||||||
 | 
					            foreach (string current in InputNumbers) // TODO: replace this with the rows in db 
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // TODO: Use values from SQL list as the fields here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Logic to add customer's name in the generic message
 | 
				
			||||||
 | 
					                Console.WriteLine(GenericMessage);
 | 
				
			||||||
 | 
					                var custName = "Josh Deck"; // Replace with lookup when data is provided
 | 
				
			||||||
 | 
					                var properMessage = string.Format("Hi {},\nStop in at Global Oil Change Center during the month of May and get $10 Off your Full Synthetic Oil Change and a free set of wiper blades. Show this text to receive discount. From your friends at Global Oil in Troy. Please reply STOP to end texts.", custName);
 | 
				
			||||||
 | 
					                var currentResult = SendMessage(properMessage, current);
 | 
				
			||||||
 | 
					                result.Add(currentResult[0], currentResult[1]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return result;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private string[] SendMessage(string Message, string Destination)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var result = new string[] { };
 | 
				
			||||||
 | 
					            var DestinationNumber = new PhoneNumber(Destination);
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                TwilioClient.Init(Credentials.TwilioSID, Credentials.TwilioAuthToken);
 | 
				
			||||||
 | 
					                var message = MessageResource.Create(
 | 
				
			||||||
 | 
					                    to: DestinationNumber,
 | 
				
			||||||
 | 
					                    from: PhoneNumber,
 | 
				
			||||||
 | 
					                    body: Message
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                result = [Destination, Message];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            catch (Exception ex)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                result = [Destination, ex.Message];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return result;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public class SqlDriver
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        private SqlConnection? conn = null;
 | 
				
			||||||
 | 
					        private List<Dictionary<string, string>>? data = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public SqlDriver(string connectionString) 
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            conn = new SqlConnection(connectionString);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        public void GatherUsers(string query)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (conn == null || data != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // Report error
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            data = new List<Dictionary<string, string>> { };
 | 
				
			||||||
 | 
					            using (SqlCommand command = new SqlCommand(query, conn))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                try
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
										conn.Open();
 | 
				
			||||||
 | 
										SqlDataReader reader = command.ExecuteReader();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    Dictionary<string, string> column;
 | 
				
			||||||
 | 
					                    while (reader.Read())
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        // Empty out the column 
 | 
				
			||||||
 | 
					                        column = new Dictionary<string, string>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        // Read the data from the table
 | 
				
			||||||
 | 
					                        // TODO: get actual fields needed
 | 
				
			||||||
 | 
					                        column["NAME"] = reader["NAME"].ToString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        data.Add(column);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										conn.Close();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									catch
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    // Handle the error and/or cry
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
								}              
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        public void ReportText()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
								if (conn == null)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									// Report error
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            using (SqlCommand command = new SqlCommand("PROCEDURE_NAME", conn) { CommandType = System.Data.CommandType.StoredProcedure })
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // TODO: add parameters to SP
 | 
				
			||||||
 | 
					                conn.Open();
 | 
				
			||||||
 | 
					                command.ExecuteNonQuery();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue