Created
June 7, 2012 19:27
-
-
Save tealtail/2891036 to your computer and use it in GitHub Desktop.
Send an SMS opt-in message and detect for the presence of a keyword response from users. This is an example of an SMS Alerts system opt-in using CDYNE's SMSNotify! API from within a legacy ASP.NET WebForms application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="form1" runat="server"> | |
<h2>Enter Your Mobile Device Number to Register</h2> | |
<p>CDYNE Alerts lets you receive school, organization, or community alerts over SMS.</p> | |
<label for="mobile">Mobile Number</label> | |
<input type="text" runat="server" id="mobile" class="textbox" placeholder="ex. '(555)-555-5555'" required="required" /> | |
<p> | |
<label class="checkbox"> | |
<input type="checkbox" id="checktoc" runat="server" required="required"/> | |
I agree to the terms & conditions. | |
</label> | |
</p> | |
<div> | |
<asp:Button ID="btnSubmit" runat="server" Text="Sign-up for CDYNE Alerts" | |
OnClick="btnSubmit_Click" /> | |
<div id="success" runat="server"> | |
<span>SUCCESS!</span> | |
You will receive a message from our system shortly. Reply "<b>YES</b>" to activate CDYNE communications. | |
</div> | |
</div> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is an example of how you can responsibly implement SMS messaging by verifying customer opt-ins with CDYNE's SMSNotify! API. | |
//API reference sheet - http://www.cdyne.com/downloads/SPECS_SMS-Notify2.pdf | |
public partial class signup : System.Web.UI.Page | |
{ | |
//API DETAILS | |
IsmsClient client = new IsmsClient("sms2wsHttpBinding"); | |
//Request a free license key for any CDYNE API at http://www.cdyne.com/developers/trial-key | |
Guid Key = new Guid("PUT YOUR LICENSEKEY HERE"); | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
//These are HTML elements on the page's front end | |
mobile.Disabled = false; | |
btnSubmit.Visible = true; | |
success.Visible = false; | |
} | |
protected void btnSubmit_Click(object sender, EventArgs e) | |
{ | |
//Pulling customer's phone number from the text-input on page | |
string phoneNumber = mobile.Value; | |
//Setting the specifics of the API SMS Request | |
SMSAdvancedRequest customerOptIn = new SMSAdvancedRequest(); | |
customerOptIn.LicenseKey = Key; | |
List<SMSRequest> requests = new List<SMSRequest>(); | |
SMSRequest optIn = new SMSRequest(); | |
optIn.Message = "CDYNE Info Alerts: Reply YES to confirm. Reply HELP for help or call 8009843710. Msg&Data rates may apply. Msg freq per acct setup. Pwr'd by CDYNE."; | |
//SMS Message recipient(s) | |
optIn.PhoneNumbers = new string[] { phoneNumber }; | |
//Sets the dedicated number (DID) that the SMS message will be sent from. If not declared, the message will be sent from a pool of CDYNE's shared numbers | |
optIn.AssignedDID = "YOUR DID HERE"; | |
optIn.StatusPostBackURL = "YOUR POSTBACK PAGE URL HERE"; | |
requests.Add(optIn); | |
//Gathering it all up | |
customerOptIn.SMSRequests = requests.ToArray(); | |
//Making API call | |
SMSResponse[] smsResponses = client.AdvancedSMSsend(customerOptIn); | |
//Hiding the submit button and showing the success message. | |
mobile.Disabled = true; | |
btnSubmit.Visible = false; | |
success.Visible = true; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Server-side code for the postback page | |
public partial class signup_postback : System.Web.UI.Page | |
{ | |
//Global API Details that I don't want in my main code | |
IsmsClient client = new IsmsClient("sms2wsHttpBinding"); | |
Guid Key = new Guid("YOUR LICENSE KEY HERE"); | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
//Declaring empty variables to store the details of a customer's reply message. | |
string SMSResponse = ""; | |
string MessageID = ""; | |
string MatchedMessageID = ""; | |
string ReferenceID = ""; | |
string FromPhoneNumber = ""; | |
string ToPhoneNumber = ""; | |
string ResponseReceiveDate = ""; | |
string Message = ""; | |
//Catching and setting the details of the reply into variables. | |
SMSResponse = Request.Params["SMSResponse"]; | |
MessageID = Request.Params["MessageID"]; | |
MatchedMessageID = Request.Params["MatchedMessageID"]; | |
ReferenceID = Request.Params["ReferenceID"]; | |
FromPhoneNumber = Request.Params["FromPhoneNumber"]; | |
ToPhoneNumber = Request.Params["ToPhoneNumber"]; | |
ResponseReceiveDate = Request.Params["ResponseReceiveDate"]; | |
Message = Request.Params["Message"]; | |
//Checking that the customer is confirming their Opt-in with keyword "yes". | |
if (Message.ToLower() == "yes") | |
{ | |
//Now you might add the customer's phone number to your records/db | |
//Make the API request to send out the final confirmation/welcome message out to the customer | |
SMSAdvancedRequest confirmation = new SMSAdvancedRequest(); | |
//Getting API Key from variable that was declared earlier | |
confirmation.LicenseKey = Key; | |
List<SMSRequest> requests = new List<SMSRequest>(); | |
SMSRequest confirmationMessage = new SMSRequest(); | |
confirmationMessage.Message = "Welcome to CDYNE Info Alerts. Reply 'STOP' to cancel. Reply HELP for help or call 8009843710. Msg&Data rates may apply. Msg freq per acct setup. Pwr'd by CDYNE."; | |
//The confirmation/welcome message will go to the number that is opting-in. | |
confirmationMessage.PhoneNumbers = new string[] { FromPhoneNumber }; | |
confirmationMessage.AssignedDID = "YOUR DID HERE"; | |
requests.Add(confirmationMessage); | |
//Gather up all the details of the request | |
confirmation.SMSRequests = requests.ToArray(); | |
//Send out the confirmation/welcome | |
SMSResponse[] smsResponses = client.AdvancedSMSsend(confirmation); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment