I’m looking to clean up integrated email display within our fibery a bit.
Currently, the integration brings in the body of the email text, which includes the quoted replies (represented with block quotes within the rich text field)
Is there a good way to select this part of the text - either with an automation or script - to either delete it, or create another rich text field without it?
Because the message body is rich text, you are probably limited to making changes using scripting.
I imagine that you could clean up the message using regex replacement, see here:
You will need to play around with your regex construction to make sure that you only remove the bits that are in the quoted reply, and not other genuine parts of the message.
I personally find this site useful for experimenting:
I’m currently using this script to take the Rich Text from the Field “Message”, remove the replies, and replace it into the Rich Text field “Message (No Context)”
// Fibery API is used to retrieve and update entities
const fibery = context.getService('fibery');
// affected entities are stored in args.currentEntities;
// to support batch actions they always come in an array
for (const entity of args.currentEntities) {
// the rich text field is a document, which requires a special id to get access to
// In this case, the rich text field is "Description", so we request that field be included
const entityWithMessageField = await fibery.getEntityById(entity.type, entity.id, ['Message']);
const entityWithNCMessageField = await fibery.getEntityById(entity.type, entity.id, ['Message (No Context)']);
// just saving a shorter reference to it
const dsc = entityWithMessageField['Message'];
const destdoc = entityWithNCMessageField['Message (No Context)'];
// get the rich text field contents as markdown (supports md, html, and json)
const doc = await fibery.getDocumentContent(dsc.secret, 'md');
// Update the text to remove all previous replies
const re = /[\n\r] >.*/;
const newdoc = doc.replace(re, "");
//Set the Message with no context to the newdoc
await fibery.setDocumentContent(destdoc.secret, newdoc, 'md');
}
Unfortunately, I’m not getting the desired results. At present, the field is being populated by the exact same content as Message. Any ideas?
Because rich text is stored as markdown, some charcters are not stored as they appear on the UI bit rather are ‘escaped’ in the markdown.
I suggest using some console.log messages to see what doc actually looks like before then figuring out the correct regex expression to use.
// Fibery API is used to retrieve and update entities
const fibery = context.getService('fibery');
// affected entities are stored in args.currentEntities;
// to support batch actions they always come in an array
for (const entity of args.currentEntities) {
// the rich text field is a document, which requires a special id to get access to
// In this case, the rich text field is "Description", so we request that field be included
const entityWithMessageField = await fibery.getEntityById(entity.type, entity.id, ['Message']);
const entityWithNCMessageField = await fibery.getEntityById(entity.type, entity.id, ['Message (No Context)']);
// just saving a shorter reference to it
const dsc = entityWithMessageField['Message'];
const destdoc = entityWithNCMessageField['Message (No Context)'];
// get the rich text field contents as markdown (supports md, html, and json)
const doc = await fibery.getDocumentContent(dsc.secret, 'md');
// Update the text to remove all previous replies
const re = /^>.*/gm;
const newdoc = doc.replace(re, "");
console.log(newdoc);
//Set the Message with no context to the newdoc
await fibery.setDocumentContent(destdoc.secret, newdoc, 'md');
}