Sure, I can help you with that. Here’s a Pipedream component that extracts the first name, last name, and email from the body of the email. This component should be placed after the “New Emails” trigger in your workflow. ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps, $ }) { // Extract the email body from the trigger data const emailBody = steps.trigger.event.body; // Use a regular expression to match the forwarded email details const match = emailBody.match(/From: ([^\s]+) ([^<]+) <([^>]+)>/); if (match) { // If a match is found, extract the first name, last name, and email const firstName = match[1]; const lastName = match[2]; const email = match[3]; // Return the extracted details return { firstName, lastName, email, }; } else { // If no match is found, return an error throw new Error(“Could not extract email details from forwarded message”); } }, });
I’m sorry for the confusion. The error message indicates that emailBody is not a string, as the match function is a method of the String object in JavaScript. The steps.trigger.event.body might not be a string or it might not exist at all. Let’s add some checks to ensure that the emailBody is a string before we try to use the match method on it. Here’s the updated code: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps, $ }) { // Extract the email body from the trigger data const emailBody = steps.trigger.event.body; // Check if emailBody exists and is a string if (typeof emailBody === 'string') { // Use a regular expression to match the forwarded email details const match = emailBody.match(/From: ([^\s]+) ([^<]+) <([^>]+)>/); if (match) { // If a match is found, extract the first name, last name, and email const firstName = match[1]; const lastName = match[2]; const email = match[3]; // Return the extracted details return { firstName, lastName, email, }; } else { // If no match is found, return an error throw new Error("Could not extract email details from forwarded message"); } } else { // If emailBody is not a string, return an error throw new Error("Email body is not a string or does not exist"); } }, }); This code will check if emailBody is a string before trying to use the match method on it. If emailBody is not a string or does not exist, it will throw an error.
So here is the path to where the FIRST NAME, LAST NAME and EMAIL ADDRESS can be found.
steps.trigger.event.body.text
Please adjust this code to reflect this.
import { axios } from "@pipedream/platform";
export default defineComponent({
async run({ steps, $ }) {
// Extract the email body from the trigger data
const emailBody = steps.trigger.event.body;
// Check if emailBody exists and is a string
if (typeof emailBody === 'string') {
// Use a regular expression to match the forwarded email details
const match = emailBody.match(/From: ([^\s]+) ([^<]+) <([^>]+)>/);
if (match) {
// If a match is found, extract the first name, last name, and email
const firstName = match[1];
const lastName = match[2];
const email = match[3];
// Return the extracted details
return {
firstName,
lastName,
email,
};
} else {
// If no match is found, return an error
throw new Error("Could not extract email details from forwarded message");
}
} else {
// If emailBody is not a string, return an error
throw new Error("Email body is not a string or does not exist");
}
},
});