/// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        public async void Handle(TwilioSendSmsCommand command)
        {
            InfoAccumulator info = new InfoAccumulator();
            TwilioSms       sms  = null;

            if (string.IsNullOrEmpty(command.Message) || string.IsNullOrEmpty(command.PhoneNumber))
            {
                info.AddError("got empty message or phone number");
            }
            else
            {
                Message response = await Twilio.SendSms(command.PhoneNumber, command.Message);

                if (response == null)
                {
                    info.AddError("error in sending sms");
                }
                else
                {
                    sms = GetTwilioSms(response);
                }
            }

            SendReply(info, command, resp => resp.Sms = sms);
        }
Exemple #2
0
        public HttpResponseMessage Get(
            [FromUri] string tenant,                // Our stuff
            [FromUri] string notifierId,
            [FromUri] TwilioSms sms)
        {
            // Run service
            using (Profiler.Measure("TwilioController.Get"))
            {
                try
                {
                    long notifierIdNum;

                    try
                    {
                        notifierIdNum = Int64.Parse(notifierId);
                    }
                    catch
                    {
                        throw new UnmatchedNotifierException();
                    }

                    using (WebApiHelpers.GetTenantContext(tenant))
                    {
                        _receiver.HandleRequest(notifierIdNum, sms);
                    }

                    return(new HttpResponseMessage(HttpStatusCode.Accepted));
                }
                catch (TwilioValidationException)
                {
                    EventLog.Application.WriteError($"Request failed validation. URL:{System.Web.HttpContext.Current.Request.Url}");
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Saves the Twilio SMS.
        /// </summary>
        /// <param name="sms">The SMS.</param>
        /// <returns></returns>
        public bool SaveTwilioSms(TwilioSms sms)
        {
            DataTable dataTable = ConvertToDataTable(sms);

            using (var sqlConnection = GetOpenedSqlConnection()) {
                using (SqlCommand sqlCommand = new SqlCommand(SaveSmsMessage, sqlConnection))
                {
                    sqlCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter tableValueParameter = sqlCommand.Parameters.AddWithValue("@Tbl", dataTable);
                    tableValueParameter.SqlDbType = SqlDbType.Structured;

                    return(ExecuteNonQueryAndLog(sqlCommand));
                }
            }
        }