Is there a way to duplicate/assign files when creating an entity in an automation?

So I have an email integration and automation that allows people to reach out and register via email. If they send an email to a given address, I want to automatically create an additional entity and attach any attachments to that newly created entity (not the email):

Somehow in the Add Field section, Files does not appear. Is there any way to do this?
Not a massive thing as we hope to move to a registration form eventually. I assume there’s a cost/benefit trade-off reason in here, just wondering. :slightly_smiling_face:

Thanks.

Could a Rule like the following work on your Email Integration DB?

Trigger: When new Email Message is created, and it has File Attachments

Action: small script to copy the attachments to a target entity:

const fiberyAccountHostName = 'https://YOURACCOUNT.fibery.io'
const API_TOKEN = '...' // See Workspace menu | Settings | Personal | API Keys

// Where we want to copy the file attachments:
const targetEntityType = '???'
const targetEntityId = ???

for( const entity of args.currentEntities ) {
    for( const file of entity.files ) {
        const file = await fibery.getEntityById('fibery/file', file.id, ['Secret', 'Name', ])      // 'Content Type'
        const fileUrl = fiberyAccountHostName + '/api/files/' + file.Secret
        await fibery.addFileFromUrl(fileUrl, file.Name, targetEntityType, targetEntityId, {Authorization: 'Token '+API_TOKEN})
    }
}
3 Likes

Thanks a lot, @Matt_Blais, needed a few days to get back to this topic. :melting_face:

I’ve set this up as a CRON-style job (there is another action that connects the mail with the contact, if that exists already):

The main remaining question for me to use this is, how do I pass the targetEntityId into the script? I think it should exist in [Step 1 Email Message].[Contact].[Public Id] but I’m not sure how to pass it into the script.
(as mentioned elsewhere, the whole scripting interface is unclear to me as the documentation is confusing to me)

Thanks a lot,
Wolf

The results of previous steps are available in scripts as args.steps which is an array.
So you can examine args.steps[2] to get info about the outcome of step 2.

In your case, to get the id, you probably need something like this:
args.steps[2].result.entities[0].id

Admittedly, this capability is not documented very well (at all) so we need to update our user guide, but I’m working on it :slight_smile:

1 Like

Thanks, @Matt_Blais and @Chr1sG, with some twiddling this finally worked. :slightly_smiling_face:

Mille grazie! :smiley:

1 Like