Skip to content

Instantly share code, notes, and snippets.

@rwisner
Created November 3, 2020 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwisner/e6d35b199c37d64db9c1c3b87c6c0a97 to your computer and use it in GitHub Desktop.
Save rwisner/e6d35b199c37d64db9c1c3b87c6c0a97 to your computer and use it in GitHub Desktop.
Flip a coin action webhook
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