Function-generated Email Body for Notification from Automation or Action

Hi there!

I am working on a function that generates the content for an email body, to be used in either a notification effect from an automation or in a notification effect for an action. Platform documentation outlines the process for a “Notification Builder” function, but I wasn’t sure if an automation (or action) function-generated email body could also just take in an HTML string? When I wrote a version of the function below, the function doesn’t populate as an option to select. It is published to master branch and tagged.

export function getExampleEmailBody (object: ObjectType): string {
    return (`  
    <h2>Example header</h2>
    <table style="width:100%;border:1px solid black;border-collapse:collapse;">
      <tr>
        <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 1</th>
        <td style="border:1px solid black;padding:5px;">${object.objectProperty1}</td>
      <tr>
        <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 2</th>
        <td style="border:1px solid black;padding:5px;">${object.objectProperty2}</td>
      </tr>
    </table>
        `);
}

Hi @kelseylt , only functions that output the Notification type (docs) can be used. However, you can use HTML as the content of the email notification, e.g.:

@Function()
public exampleHtmlNotification(object: ObjectType): Notification {
    const emailBody = `
        <h2>Example header</h2>
        <table style="width:100%;border:1px solid black;border-collapse:collapse;">
          <tr>
            <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 1</th>
            <td style="border:1px solid black;padding:5px;">${object.objectProperty1}</td>
          <tr>
            <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 2</th>
            <td style="border:1px solid black;padding:5px;">${object.objectProperty2}</td>
          </tr>
        </table>
    `;

    return Notification.builder()
        .shortNotification(ShortNotification.builder()
            .heading("Notification heading")
            .content("Notification content")
            .build())
        .emailNotificationContent(EmailNotificationContent.builder()
            .subject("Email subject")
            .body(emailBody)
            .build())
        .build();
}
3 Likes

Hello @willem,

Is there some nuance to what html Foundry expects? I have the below function but the html isn’t being used to format the email.

    @Function()
    public async createPmTaskNotification(pmTask: PmTask): Promise<Notification> {


        // Define the email body
        const body = `
            Hello!
            <br>
            <br>
            You have been assigned a new task. in the project: NA.
            <br>
            <br>
            
            <b><u>Task Name:</b></u> NA
            <br>
            <b><u>Task Description:</b></u> NA
            <br>
            <b><u>project:</b></u> NA
        `;

        // Create a short notification that will be shown within the platform
        const shortNotification = ShortNotification.builder()
            .heading(`New Task in project: NA.`)
            .content(body)
            .addObjectLink("View Task", NA)
            .build();
        
        // Create Email Notification Content
        const emailNotificationContent = EmailNotificationContent.builder()
            .subject(`New Task in Project:NA`)
            .body(body)
            .addObjectLink("View Task", NA)
            .build();

        return Notification.builder()
            .shortNotification(shortNotification)
            .emailNotificationContent(emailNotificationContent)
            .build();
    }```