Introduction
Adaptive Actionable email notifications are one of the powerful and cool features of Office 365 and Power Automate. An Actionable Message appears as a card at the top of the related Outlook email, in addition to or in place of the email message body. The card provides information at a glance that reviewers can read quickly before providing a response. The reviewer can reply to the task simply by clicking a button provided. Adaptive cards support other UI elements such as checkboxes, dropdown selections etc.
Adaptive emailing can be leveraged in your digital transformation projects to support advanced features such as approving, rejecting, or performing custom actions on business records via Outlook emails. Some examples of adaptive email card are shown below.
Adaptive cards are authored in JSON format. It can be designed using designer tools provided by Microsoft. https://adaptivecards.io/designer/
A sample card designer is shown below
For smaller projects, achieving adaptive emails is straightforward by sending them from a dedicated logic app and having the logic app wait for actions. In this scenario, the logic app instance remains active until the approver takes action. However, for medium or large-scale projects, relying solely on the typical approach with a logic app or Power Automate flows may pose challenges.
In this blog post, I discuss the challenges and propose an approach to scale adaptive emailing to handle thousands of different actions. This involves leveraging a Templating Library and Service Bus in conjunction with Logic App. Templating libraries are available in various major programming languages such as JavaScript, C#, Java, and Python.
Challenge / Problem Summary
In small-scale projects, like a leave approval system, the approval email format typically remains the same. In such cases, the adaptive email JSON can be predefined in the dedicated logic app and sent to the approver. However, in medium or large-scale applications where there are numerous email formats (e.g., purchase order approval flows, quotation approval flows, sales approval flows), generating distinct adaptive JSON within a dedicated logic app becomes impractical. This approach leads to an abundance of if-else conditions in the logic app, rendering it unproductive and cost-ineffective, as all instances will continue running while waiting for approver actions. This challenge we have faced in one of our customer projects
Solution
The described approach provided us with a scalable and efficient solution capable of effectively managing a diverse range of email formats, all while maintaining productivity and minimizing costs.
In this solution, we transitioned the generation of adaptive cards to the backend system. The backend system utilized the Node.js Templating Library package to construct adaptive card JSON based on configured templates for each action. The resulting adaptive card JSON was then stored in the database. To ensure a decoupled architecture between the backend system and the adaptive notification system, we employed the Azure Service Bus. The backend system would post a message to the service bus queue, including the database record ID where the corresponding adaptive JSON card data was stored, along with recipient emails and other relevant parameters. Additionally, the backend system injected the whitelisted action URLs (invoked upon user interaction with action buttons in the email) and other necessary information. A Logic App was triggered by the service bus message. The Logic App retrieved the adaptive JSON data using a backend API and the database record ID, and subsequently sent the Outlook email
In this scenario, no Logic App remains active, waiting for user actions. The application can configure an unlimited number of action emails as needed.
Implementation Steps
- Creating Adaptive Templates: Design a collection of adaptive email templates that cater to different scenarios. These templates should be designed to accept dynamic data and should follow industry-standard formatting practices.
- Storing Templates: Store these adaptive templates in a database. Azure offers several database options, such as Azure SQL Database or Cosmos DB, that you can use to manage your templates efficiently.
- Generating Email Content: When an action occurs (e.g., a user completes a purchase), retrieve the appropriate template from the database. Populate the template with relevant data (e.g., user's name, purchased items, whitelisted action endpoint for custom actions if required) to generate the final email content. Templating library helps this data binding and generation of email content
- Storing Email Content: Store the final email content along with metadata (such as recipient's email address and timestamp) in the database. This step helps in keeping track of sent emails and their content.
- Queueing Messages: Send a message to the Azure Service Bus queue containing the ID and metadata of the stored email content. This message triggers the Logic App to start processing.
- Azure Logic App Workflow: Create an Azure Logic App that monitors the Service Bus queue. When a new message arrives, the Logic App triggers and fetches the email content using the provided ID from the database.
- Sending Emails: With the email content in hand, the Logic App sends the email to the recipient using Azure's email capabilities. This can include using Azure SendGrid integration or other suitable email services.
Benefits of the Solution
- Scalability: By utilizing Azure's cloud infrastructure, the solution can handle a large number of email requests and adapt to changing demand.
- Personalization: Adaptive templates and dynamic data binding ensure that each recipient receives a personalized email, leading to better engagement and conversion rates.
- Automation: The integration of Azure Logic App and Service Bus automates the process of email generation and delivery, reducing manual intervention.
- Efficiency: The system maintains a record of sent emails and their content, which can be invaluable for tracking and auditing purposes.
High-level Architecture
A very high-level architecture of the entire adaptive emailing system has been shown below
In conclusion, the combination of Azure Logic App, Azure Service Bus, and the Adaptive Template Library in your favourite programming language provides a powerful and scalable solution for implementing adaptive emails. This approach not only enhances the personalization of email communication but also streamlines the process, ensuring that the right message reaches the right recipient at the right time. As businesses continue to prioritize effective communication, leveraging these tools can undoubtedly give them a competitive edge in the digital landscape.
I trust that you now grasp the challenge and the solution that assisted our customer in effectively managing a large number of configurable and cost-effective adaptive email systems. Please don't hesitate to contact us if you need more information or if you're seeking solutions for similar technical challenges