Skip to content

Instantly share code, notes, and snippets.

@jakepeyser
Last active December 10, 2015 23:13
Show Gist options
  • Save jakepeyser/9527612cf9b5d13e0400 to your computer and use it in GitHub Desktop.
Save jakepeyser/9527612cf9b5d13e0400 to your computer and use it in GitHub Desktop.
Assistant Shop.r Demo Gists
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;
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;
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;
// 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