Last active
December 10, 2015 23:13
-
-
Save jakepeyser/9527612cf9b5d13e0400 to your computer and use it in GitHub Desktop.
Assistant Shop.r Demo Gists
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
if | |
the feedback score of 'the product' is between 20 and 80 | |
then | |
make it false that 'the product' needs a divestment review; | |
make it false that 'the product' needs an investment review; |
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
if | |
the feedback score of 'the product' is less than 20 | |
then | |
make it true that 'the product' needs a divestment review; | |
make it false that 'the product' needs an investment review; |
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
if | |
the feedback score of 'the product' is more than 80 | |
then | |
make it false that 'the product' needs a divestment review; | |
make it true that 'the product' needs an investment review; |
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
// Kick of the process | |
start = RECEIVEGET(null, 'start'); | |
// Set the global variables | |
setupGlobalVars = SCRIPT(start, function() { | |
var productId = start.out.productId; | |
var feedbackScore = start.out.feedbackScore; | |
var reviewInvestment = start.out.reviewInvestment; | |
}); | |
// Call Assistant-Shop.r API to create a new task document in Cloudant | |
createTask = GET(setupGlobalVars, | |
'http://appname.mybluemix.net/api/v1/task', | |
{productId: productId, | |
reviewInvestment: reviewInvestment, | |
user: 'Brooke', | |
replyLink: Location + '/decision'}, | |
{contentType: 'application/json', | |
failOnHTTPError: true} | |
); | |
// If Cloudant call fails, reply to initial call with error | |
failOnCreateTask = REPLYGET({activity: createTask, | |
error: true}, | |
'start', | |
"{message:Error creating investment review task," + | |
"errorCode:" + createTask.error.errorCode + "," + | |
"error:" + createTask.error.message + "}" | |
); | |
// Return initial call with "success" message | |
reply = REPLYGET(createTask, 'start', | |
'{message: Success,Location:' + Location + '/decision}'); | |
// Wait for the user to click the 'Decision' button | |
waitForDecisionClick = RECEIVEGET(reply, 'decision'); | |
// Respond back to the user if they decided to review | |
replyReview = REPLYGET({activity: waitForDecisionClick, | |
condition: waitForDecisionClick.out.decision==="review"}, | |
'decision', | |
'{message:Reviewing investment in ' + productId + '!}'); | |
// Respond back to the user if they decided to ignore | |
replyIgnore = REPLYGET({activity: waitForDecisionClick, | |
condition: waitForDecisionClick.out.decision==="ignore"}, | |
'decision', | |
'{message:Ignoring proposal to review investment in ' + productId + '!}'); | |
// Respond back to the user if decision response was invalid | |
replyInvalidDecision = REPLYGET({activity: waitForDecisionClick, | |
condition: waitForDecisionClick.out.decision!=="review" && waitForDecisionClick.out.decision!=="ignore"}, | |
'decision', | |
'{message:Invalid decision received for ' + productId + '.}'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment