How to Set Up Slack Notifications for Specific Gmail Emails and Process Email Content While Minimizing Pipedream Credits Usage?

This topic was automatically generated from Slack. You can find the original thread here.

I would like to receive a Slack notification when I receive an email with a specific title.
Not sure if webhooks exists fro GMail. Take into consideration that the inbox corresponding to the email address receive a lot of emails during the day, so I need to avoid running the pipedream workflow for each emails received as it will be costly in terms of Pipedream credits.

Also, is it possible to process the content of the email to send some elements in the Slack notification ?

Thank you Pi !

To receive a Slack notification when you receive an email with a specific title, you can use the Gmail trigger “New Email” and the Slack action “Send a Large Message (3000+ characters)”. However, since you mentioned that you receive a lot of emails and want to avoid running the workflow for each email, you can add a code step to filter emails based on the title and process the content before sending the notification. Here’s an example workflow: 1. Add the Gmail “New Email” trigger. 2. Add a code step to filter emails based on the title and process the content. Replace specificTitle with the title you’re looking for: if (steps.trigger.event.subject === "specificTitle") { const processedContent = steps.trigger.event.body; // Process the content as needed this.filteredEmail = { subject: steps.trigger.event.subject, content: processedContent, }; } else { $.end("Email title does not match"); } 3. Add the Slack “Send a Large Message (3000+ characters)” action. Use the output of the previous code step as input for the Slack message. Remember to connect your Gmail and Slack accounts in the respective steps. Regarding processing the content of the email, you can do that within the code step by modifying the processedContent variable as needed. Please note that this workflow will still run for each email received, but it will exit early and not send a Slack notification if the email title doesn’t match. This will help you save Pipedream credits.

Thank you ! I think the best is to do a redirect rule in GMail for the email with the specific title to another email address, and then process the emails received from this new email address. This will reduce the numbers of call to Pipedream workflow

That’s a great idea! By creating a redirect rule in Gmail for emails with the specific title to another email address, you can reduce the number of emails processed by your Pipedream workflow. Once you’ve set up the redirect rule, you can use the Gmail “New Email” trigger in your Pipedream workflow to process emails received at the new email address. This way, you’ll only trigger the workflow for relevant emails, saving Pipedream credits. Don’t forget to connect the Gmail account associated with the new email address when setting up the trigger.

Finally, the best option is to use to filter the email on GMail side, create a rule to forward the specific email to the Pipedream trigger “New email” .So the workflow will be triggered only on the emails that require a Slack notification

That’s a great solution! By creating a Gmail filter and forwarding the specific emails to the Pipedream “New Email” trigger, you’ll ensure that the workflow is only triggered for the emails that require a Slack notification. This will help you save Pipedream credits and keep your workflow focused on the relevant emails. Just make sure to set up the forwarding rule in Gmail and connect the Email account in the Pipedream trigger.

The content of the email is HTML is there a way to display HTML in Slack ? Or how could I convert the HTML to text with Javascript ?

Slack does not support displaying raw HTML, but it does support its own formatting called “mrkdwn”. You can use this formatting to style your text in Slack messages. However, to convert HTML content from your email to plain text or Slack-compatible formatting, you can use a library like html-to-text in a code step within your Pipedream workflow. Here’s an example of how to use the html-to-text library to convert HTML content to plain text: ```
import { htmlToText } from “html-to-text”; const htmlContent = steps.trigger.event.body; // Replace this with the HTML content from your email const plainText = htmlToText(htmlContent, { wordwrap: false, }); // Now you can use plainText in your Slack message