Last active
June 22, 2019 11:26
-
-
Save heyAyushh/c5538a9b89dda3819bd94ae480de616f to your computer and use it in GitHub Desktop.
heyjumblr
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
// to be renamed root/heyjumblr/index.js | |
var randomWord = require("random-word"); | |
let azure = require("azure-storage"); | |
let connectionString = "connectionstring for azure storage" | |
var axios = require("axios"); | |
function check(temp, word) { | |
if (temp == word) return 1; | |
return 0; | |
} | |
function shuffleWord(word) { | |
var shuffledWord = ""; | |
word = word.split(""); | |
while (word.length > 0) { | |
shuffledWord += word.splice((word.length * Math.random()) << 0, 1); | |
} | |
return shuffledWord.split(""); | |
} | |
module.exports = function(context, req, intable) { | |
context.log("JavaScript HTTP trigger function processed a request."); | |
if (req.body.queryResult.action == "input.welcome") { | |
var word = randomWord(); | |
var shuffle = shuffleWord(word); | |
context.res = { | |
body: { | |
fulfillmentText: "Solve the Jumbled word " + shuffle | |
} | |
}; | |
let tableService = azure.createTableService(connectionString); | |
//store | |
var store = { | |
PartitionKey: "function", | |
RowKey: req.body.session, | |
Word: word.toLowerCase() | |
}; | |
tableService.insertOrReplaceEntity( | |
"words", | |
store, | |
(error, result, response) => { | |
if (error) { | |
console.log(error); | |
} | |
} | |
); | |
context.done(); | |
} else if (req.body.queryResult.action == "input.unknown") { | |
if (check(req.body.queryResult.queryText.toLowerCase(), intable.Word)) { | |
context.res = { | |
body: { | |
fulfillmentText: "Yes, You are Right " | |
} | |
}; | |
context.done(); | |
} else { | |
context.res = { | |
body: { | |
fulfillmentText: "Nope, You are Wrong. The word was " + intable.Word | |
} | |
}; | |
context.done(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment