|
|
Documentation Wiki > Developer Documentation > Web Service Guide > Technical Articles > SMS API Scenario Guide > Scenario: Guessing Game
Scenario: Guessing GameFrom $1Table of contents(Click the banner to go to the related Docs.Code.ExactTarget.com page.) OverviewA radio station runs a promotion where listeners must discover a password to win a t-shirt. To discover the password, the listeners must guess the correct number between 1 and 100. The listeners text GUESS and a guess to the radio station's short code. For example, to guess 50, a listener texts in GUESS 50. If the guess is too low or high, the system responds with an SMS message saying to guess a higher or lower number. If the guess is correct, the listener receives the password to redeem for a station t-shirt. To make this scenario work, the radio station must:
Creating the Data ExtensionsThe GUESSDE data extension stores the phone number and guess for the listeners who enter the contest. When a listener sends an SMS message with a guess, a row is created in this data extension.
Creating the AMPscriptThis block of AMPscript creates a row in the GUESSDE data extension with the listener's phone number and guess if the incoming message starts with the word GUESS. After the first message, the listener does not include the verb, so the previous conversation continues. After starting the conversation, the AMPscript block selects a random number between 1 and 100 that the listener is trying to guess. The code compares the guess with the random number:
%%[
VAR @Number
IF UPPERCASE([MSG(0).VERB]) == "GUESS" THEN
/* Reset game */
SET @Number = RANDOM(1, 100)
UPSERTDATA("GUESSDE", 1, "Phone", MOBILE_NUMBER, "Number", @Number)
SetSmsConversationNextKeyword("12345", MOBILE_NUMBER, "GUESS")
]%%Starting new game! Guess a number from 1 to 100!%%[
ELSE
VAR @Guess
SET @Guess = V([MSG(0).VERB])
IF @Guess <= 100 AND @Guess >= 1 THEN
VAR @Number
SET @Number = LOOKUP("GUESSDE", "Number", "Phone", MOBILE_NUMBER)
IF @Number == @Guess THEN
]%%You guessed it! Call the station and say "94.3 Rocks My Midday" for your t-shirt.%%[
ELSE
IF @Number < @Guess THEN
]%%Nice try but %%=V(@Guess)=%% is too high... Why not give it another shot?%%[
ELSE
]%%Nice try but %%=V(@Guess)=%% is too low... Why not give it another shot?%%[
ENDIF
SetSmsConversationNextKeyword("12345", MOBILE_NUMBER, "GUESS")
ENDIF
ELSE
]%%That's an invalid guess. Try again!%%[
SetSmsConversationNextKeyword("12345", MOBILE_NUMBER, "GUESS")
ENDIF
ENDIF
]%%
Creating the SMS MO KeywordThe radio station creates an SMS MO keyword and includes the above AMPscript block in the Message field. As soon as the radio station saves this keyword, listeners can begin submitting guesses to play the game. This page was last updated by Ryan Williams on Fri, 06 Jan 2012 21:24:22 GMT. If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:
Tags: (Edit tags)
|
Powered by MindTouch 2010 |