The workflow will be launch with those input parameters:
{
user: { email: "foo@example.com" },
documents: [
{ type: "driver-lisence" },
{ type: "passeport" }
]
}
The ProofReceivedEvent
event is sent to the workflow once an uploaded document has been checked:
{
name: "ProofReceivedEvent",
data: [
{
document_id: 456,
isValid: false,
reason: "Passeport expired"
}
]
}
This workflow is the code that orchestrates tasks (through the Zenaton workflow engine) and executes them on your servers.
const sendgridConnectorId = "";
module.exports = {
*handle(request) {
let remainingReminders = 3;
let counter = request.documents.length;
// While there are documents missing and the reminder limit hasn't been reached yet
while (counter > 0 && remainingReminders > 0) {
// Wait for a document to be uploaded for up to 3 days
const event = yield this.wait.event("ProofReceivedEvent").for(3 * 24 * 3600);
// If a document is received
if(event) {
// Get the data of the event
const [eventName, eventData] = event;
// to know if the document is valid and update the counter of remaining documents.
if (eventData.isValid) {
counter--;
}
} else {
// If no document has been uploaded within 3 days
// Send an email reminder to the user
yield* this.sendEmailReminder(request, remainingReminders);
remainingReminders--;
}
}
// Notify the user via email using the Sendgrid API connector
// about the registration process completion
// depending on the number of valid documents.
// If all documents are valid
if (counter === 0) {
// Notify the user that the registration process is complete
yield* this.sendEmailRegistrationComplete(request);
} else {
// Notify the user that the registration process failed
yield* this.sendEmailRegistrationFailed(request, remainingReminders);
}
},
*sendEmailReminder(request, remainingReminders) {
const sendgrid = this.connector('sendgrid', sendgridConnectorId);
mail_template_params = {
// build the payload that specifies the 'from', the 'to'
// and the content of the mail depending on your email provider.
}
return yield sendgrid.post('/mail/send', mail_template_params)
},
*sendEmailRegistrationComplete(request) {
// ...
},
*sendEmailRegistrationFailed(request, remainingReminders) {
// ...
}
}
A workflow is launched when a user opens an account.
Real-world Examples
Start building workflows
Sign-up and run a sample project Learn more