Created
November 3, 2020 18:56
-
-
Save rwisner/e6d35b199c37d64db9c1c3b87c6c0a97 to your computer and use it in GitHub Desktop.
Flip a coin action webhook
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
app.handle('coin_handle', (conv) => { | |
// create a variable to hold the response | |
var response = ""; | |
// create a constant to hold what the user picked | |
const userSide = conv.intent.params.coin_slot.resolved; | |
response += "You picked " + userSide + ". "; | |
// generate a random number between 0 and 1 | |
const randomNum = Math.floor(Math.random() * 2); | |
// create a variable to hold what the system flipped | |
var flipSide = ""; | |
if (randomNum == 0) { | |
flipSide = "heads"; | |
} else { | |
flipSide = "tails"; | |
} | |
response += "I flipped " + flipSide + ". "; | |
// compare userSide with flipSide | |
if (userSide == flipSide) { | |
response += "You won!!! "; | |
} else { | |
response += "You lose!! "; | |
} | |
// add the response to the conversation | |
conv.add(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment