Node example | School Menu
const { Client } = require('@automationcloud/client');
// Create Client instance
const client = new Client({
serviceId: '691030cf-57ae-47bc-b863-75e9a12f973e',
auth: process.env.SECRET_KEY, // That's the secret key of the Application
});
// Create the Job. Let's start with no input whatsoever.
const job = await client.createJob();
// Subscribe to Job state updates, to know what's happening.
job.onStateChanged(newState => console.log(`job: ${newState}`));
// Once the list of ingredients is ready...
job.onOutput('ingredients', async ingredients => {
console.log('output: ingredients', ingredients);
// Pick first and return to the Job as an input
const ingredientToAvoid = ingredients[0];
await job.submitInput('ingredientToAvoid', ingredientToAvoid);
console.log('input: ' + ingredientToAvoid);
});
// Wait for the Job to finish. Resolves once the job reaches the "success" state (e.g. enters a "success" context).
await job.waitForCompletion();
// And finally, let's get the "menu" output
const output = await job.getOutput('menu');
console.log('output: menu', output);
no comments