How Can I Get Only the Last Reply from an Email Trigger in Dev?

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

an devs i am using a email trigger in the body i reciv the whole text, is there a way of getting the last reply ?

To extract the last reply from the email body, you can use a code step after the Email trigger in your workflow. Here’s an example of how to do this: ```
export default defineComponent({ async run({ steps }) { const emailBody = steps.trigger.event.body; // Split the email body by line breaks const lines = emailBody.split(“\n”); // Find the last non-empty line as the last reply const lastReply = lines.reverse().find(line => line.trim() !== “”); return lastReply; }, });

split is not a funcion

Apologies for the confusion earlier. It seems there was a mistake in my response. Let’s try a different approach to extract the last reply from the email body. Please use the following code step after your Email trigger in the workflow: ```
export default defineComponent({ async run({ steps }) { const emailBody = steps.trigger.event.body; // Split the email body by a common reply separator, such as “On … wrote:” const separator = “On … wrote:”; const parts = emailBody.split(separator); // Get the last reply by taking the first part of the split const lastReply = parts[0].trim(); return lastReply; }, });

i nned thaht works for multiple lenguages

I understand that you want to extract the last reply from an email body in multiple languages. To achieve this, you can use a more generic separator that works across different languages. Here’s an updated code step: ```
export default defineComponent({ async run({ steps }) { const emailBody = steps.trigger.event.body; // Split the email body by a generic separator, such as “-----” const separator = “-----”; const parts = emailBody.split(separator); // Get the last reply by taking the first part of the split const lastReply = parts[0].trim(); return lastReply; }, });