Create Basic Workflow
Communicating important updates and task completions to your team or management is crucial for keeping projects on track. Automating these notifications helps prevent delays and miscommunication. In this tutorial, you’ll learn how to set up automated email notifications using the Appsmith workflow.
By following this tutorial, you will gain a comprehensive understanding of:
- The structure of workflows in Appsmith
- How to add processing logic that automatically sends emails
- Configuring a webhook trigger to connect the workflow to external systems
- Triggering the workflow from an external system to send emails
Before you begin
Before starting, ensure you have:
- A self-hosted Appsmith instance with a business subscription. Refer to the Appsmith installation guides for detailed instructions if you need to set up your instance. You can also get a trial license by signing up on customer.appsmith.com.
- Basic familiarity with Appsmith operations. If you're new to Appsmith, follow the Getting Started Tutorial to learn the basics.
- A REST client like HTTPie for testing workflows.
Create workflow
An Appsmith workflow includes:
- Main JS Function: Write the core logic within the
executeWorkflow
function. - Processes: Define tasks such as sending emails, making API calls, or processing data inside the
executeWorkflow
function. - Workflow Settings: Define the trigger that initiates the workflow, like webhooks.
Let's create your first workflow and understand its structure.
-
On your instance, go to your Appsmith workspace, click the Create New button and choose Workflow.
-
In the Main JS object code editor, rename your workflow from Untitled Workflow 1 to Send_Email. This helps you track different workflows in your workspace, each with a unique name.
-
Examine the
executeWorkflow
function in the JS editor. This function is the entry point for your workflow and must be present in the Main JS object. If it is not present, the workflow won't be invoked when triggered. You'll write the processing logic for the workflow inside this function. Here’s the default structure:export default {
/**
* Entry point for Workflow execution. All activities to be executed should be defined here.
* @param data This function takes in a JSON object as arguments (data) which can be passed when you trigger the workflow.
* @returns boolean Shall return true or false.
*/
async executeWorkflow(data) {
// start writing your code here.
return true;
}
}
Now that you've understood the basic skeleton of a workflow, let's add the processing logic to send emails.
Add processing logic
To automate tasks within your workflow, you can add processing logic. Here, you will create a query to send an email to a user. Follow these steps:
-
In your workflow, add a new Blank API query.
-
Configure the query as follows:
-
Name: Rename the query to qs_send_email. Giving a meaningful and unique name to your query helps manage and identify its purpose.
-
HTTP Method: Set to
POST
. -
URL: Enter the URL
https://run.relay.app/api/v1/playbook/clxy8oflt1rui0okqct98fmay/trigger/yqpthzdx9Znl-gxR7KA99g
. This is a preconfigured external API that takes an email as a parameter and sends an email to it. -
Body: In the Body tab, select JSON, and add the following JSON. Replace
add_your_email_address
with your email to see the workflow in action as you will receive an email.{
"email": "add_your_email_address"
}
-
-
Click the Run button to send the email. Check your inbox for an email from
demo.smtp.send.email@gmail.com
. -
Update the JSON body in your query to accept the email as a parameter, allowing you to pass the email address to the workflow at runtime.
{
"email": {{this.params.email}}
} -
Integrate the query into the workflow by updating the
executeWorkflow
function to call the query and pass the email parameter. Thedata
parameter of theexecuteWorkflow
function holds all the parameters sent to the workflow in JSON format. Use dot notation to access the parameters.export default {
async executeWorkflow(data) {
// Pass the email parameter to the query using dot notation
const response = await qs_send_email.run({ "email": data.email });
// Log the response for debugging
console.log(response);
return true;
}
}
You've successfully configured your workflow to accept email
as a parameter and call the qs_send_email
query to send email whenever the workflow is triggered. You can connect the workflow with an external app or system, and trigger it using a webhook.