Dear Community,
My colleague @Maarten already posted this question but we are finaly testing it on ActivePieces.
Here is the link to the previous post.
We’ve had an answer from @Dennis and was hoping for some extra help from the community.
What have we done so far?
We’ve added the code the Dennis wrote:
exports.code = async function code(inputs) {
const emailContent = inputs.emailContent;
const extractInformation = (key, content) => {
const regex = new RegExp(`${key}:\\s*(.*?)\\s*(?=\\n|$)`, 's');
const match = content.match(regex);
return match ? match[1].trim() : null;
};
return {
name: extractInformation('Name', emailContent),
email: extractInformation('Email', emailContent),
phone: extractInformation('Phone', emailContent),
company: extractInformation('Company', emailContent),
industry: extractInformation('Industry', emailContent),
stateProvince: extractInformation('State/Province', emailContent),
country: extractInformation('Country', emailContent),
activationDate: extractInformation('Activation Date', emailContent),
activationEndDate: extractInformation('Activation End Date', emailContent)
};
};
We got an error and the A.I. function changed it to: But tested this, it worked but got the “sample data” back with John Doe. We turned it back to the code Dennis wrote and now have the same result
exports.code = async function code(inputs) {
const emailContent = inputs.emailContent;
const extractInformation = (key, content) => {
const regex = new RegExp(${key}:\\s*(.*?)\\s*(?=\\n|$)
, ‘s’);
const match = content ? content.match(regex) : null;
return match ? match[1].trim() : null;
};
return {
name: extractInformation(‘Name’, emailContent),
email: extractInformation(‘Email’, emailContent),
phone: extractInformation(‘Phone’, emailContent),
company: extractInformation(‘Company’, emailContent),
industry: extractInformation(‘Industry’, emailContent),
stateProvince: extractInformation(‘State/Province’, emailContent),
country: extractInformation(‘Country’, emailContent),
activationDate: extractInformation(‘Activation Date’, emailContent),
activationEndDate: extractInformation(‘Activation End Date’, emailContent)
};
};
As far as I can see it only generates Demo data. Because in the previous step it got other information in the mail. This is the output:
{
"name": "John Doe\\nEmail: example@example.com\\nPhone: 123-456-7890\\nCompany: ActiveCompany\\nIndustry: Tech\\nState/Province: CA\\nCountry: USA\\nActivation Date: 2022-01-01\\nActivation End Date: 2022-01-31\"",
"email": "example@example.com\\nPhone: 123-456-7890\\nCompany: ActiveCompany\\nIndustry: Tech\\nState/Province: CA\\nCountry: USA\\nActivation Date: 2022-01-01\\nActivation End Date: 2022-01-31\"",
"phone": "123-456-7890\\nCompany: ActiveCompany\\nIndustry: Tech\\nState/Province: CA\\nCountry: USA\\nActivation Date: 2022-01-01\\nActivation End Date: 2022-01-31\"",
"company": "ActiveCompany\\nIndustry: Tech\\nState/Province: CA\\nCountry: USA\\nActivation Date: 2022-01-01\\nActivation End Date: 2022-01-31\"",
"industry": "Tech\\nState/Province: CA\\nCountry: USA\\nActivation Date: 2022-01-01\\nActivation End Date: 2022-01-31\"",
"stateProvince": "CA\\nCountry: USA\\nActivation Date: 2022-01-01\\nActivation End Date: 2022-01-31\"",
"country": "USA\\nActivation Date: 2022-01-01\\nActivation End Date: 2022-01-31\"",
"activationDate": "2022-01-01\\nActivation End Date: 2022-01-31\"",
"activationEndDate": "2022-01-31\""
}
Is there anything I am not seeing or doing wrong? Maybe there is someone that can help me.