static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken = "your_auth_token";
        var twilio = new TwilioRestClient(AccountSid, AuthToken);

        // Generate a random, unique code
        var uniqueCode = "1234567890";

        // Normally, we would call twilio.SendMessage() to send an SMS
        // But it doesn't support passing the ProvideFeedback parameter.
        var request = new RestRequest("Accounts/" + AccountSid + "/Messages.json", Method.POST);
        request.AddParameter("From", "+15017250604");
        request.AddParameter("To", "+15558675309");
        request.AddParameter("Body", "Open to confirm: http://yourserver.com/confirm?id=" + uniqueCode);
        request.AddParameter("ProvideFeedback", true);
        var response = twilio.Execute(request);

        var message = JsonConvert.DeserializeObject<Message>(response.Content,
            new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });

        Console.WriteLine("We should save this to a database:");
        Console.WriteLine("Unique Code = " + uniqueCode);
        Console.WriteLine("Message SID = " + message.Sid);
    }
Ejemplo n.º 2
0
        public void DownloadMessages()
        {
            try
            {
                db = new VehicleDBEntities(Connection.GetConnectionString());
                var ps = db.ProjectSettings.FirstOrDefault();
                if (ps == null)
                    ps = new ProjectSetting() { StopSmsLogService = false, SmsLogUpdateDate = DateTime.Now.AddYears(-1), SmsLogRefreshTime = 1, };
                if (!ps.StopSmsLogService)
                {
                    var d = ps.SmsLogUpdateDate.Value;
                    var twilio = new TwilioRestClient(ConfigHelper.AppSetting("Twilio_AccountSid"), ConfigHelper.AppSetting("Twilio_AuthToken"));
                    var NowDate = DateTime.Now;
                    string resource = string.Format("Accounts/{0}/SMS/Messages.json?DateSent>={1}", ConfigHelper.AppSetting("Twilio_AccountSid"), d.ToString("yyyy-MM-dd HH:mm:ss"));
                    RestSharp.RestRequest rs = new RestSharp.RestRequest();
                    rs.Resource = resource;

                    var smsResult = twilio.Execute<SmsMessageResult>(rs);
                    var smsList = new List<Message>();
                    if (smsResult != null)
                        AutoMapper.Mapper.Map(smsResult.SMSMessages, smsList);
                    if (smsList.Count > 0)
                    {
                        foreach (var item in smsList)
                        {
                            if (!db.Messages.Any(p => p.Sid == item.Sid))
                                db.Messages.AddObject(item);
                        }
                        db.SaveChanges();
                    }
                    ps.SmsLogUpdateDate = NowDate;
                    if (ps.ID == 0)
                        db.ProjectSettings.AddObject(ps);
                    db.SaveChanges();
                    WriteLog(smsList.Count + " Sms read");
                }
                int interval = ps.SmsLogRefreshTime * 60 * 1000;
                if (timer1.Interval != interval)
                {
                    timer1.Stop();
                    timer1.Interval = interval;
                    timer1.Start();
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex.ToString());
            }
        }
    // GET: Confirm
    public ActionResult Index(string id)
    {
        // Lookup variable `id` in a database to find messageSid
        var messageSid = "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        // Find your Account Sid and Auth Token at twilio.com/console
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken = "your_auth_token";
        var twilio = new TwilioRestClient(AccountSid, AuthToken);

        // Send Feedback to Twilio
        var request = new RestRequest("Accounts/" + AccountSid +
            "/Messages/" + messageSid + "/Feedback.json", Method.POST);
        request.AddParameter("Outcome", "confirmed");
        twilio.Execute(request);

        // Handle remaining request normally
        return View();
    }
Ejemplo n.º 4
0
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {

                var twilio = new TwilioRestClient(ConfigHelper.AppSetting("Twilio_AccountSid"), ConfigHelper.AppSetting("Twilio_AuthToken"));
                var d = new DateTime(2013, 1, 31, 21, 28, 0);
                // string resource = string.Format("Accounts/{0}/SMS/Messages.json?DateSent>={1}", ConfigHelper.AppSetting("Twilio_AccountSid"), d.ToString("yyyy-MM-dd HH:mm:ss"));
                string resource = string.Format("Accounts/{0}/SMS/Messages.json?DateSent>={1}", ConfigHelper.AppSetting("Twilio_AccountSid"), d.ToString("yyyy-MM-dd HH:mm:ss"));
                RestSharp.RestRequest rs = new RestSharp.RestRequest();
                rs.Resource = resource;
                //var smsList = twilio.ListSmsMessages("", "", d, null, null);
                var smsResult = twilio.Execute<SmsMessageResult>(rs);
                var smsList = new List<Message>();
                AutoMapper.Mapper.Map(smsResult.SMSMessages, smsList);
                new MessageRepository().Add(smsList);
                ShowMessage(true, Resources.Messages.SmsLog_LogRefresh);

            }
            catch (Exception ex)
            {

                ShowMessage(false, ex.Message);
            }
        }