Skip to content

Instantly share code, notes, and snippets.

@heyAyushh
Last active Jun 22, 2019
Embed
What would you like to do?
heyjumblr
// 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