How to conditionally attach 1 or 2 files to Email module without using Router?

I need to send emails with either 1 or 2 file attachments, depending on a condition. Specifically:

  • File 1 is always attached (from a an HTTP OAuth2.0 Request module)

  • File 2 is only attached if its filename is NOT “No_Intro_Pack.pdf” ( from Google Drive module)

What I’ve tried:

  1. Make formulas - Attempted to build an array using map(), add(), and toArray(), but map() doesn’t work for creating key-value structures in Make.

  2. JavaScript code module - Built the attachments array successfully, but the binary file data gets transformed into a Node.js Buffer format {"type": "Buffer", "data": [bytes]} which the Email module can’t read. Error: “Value can’t be casted as buffer for parameter ‘data’.”

  3. Python code module - Same issue as JavaScript - the binary data format gets transformed and breaks.

What I want to avoid:

Using a Router to duplicate my email modules. I currently have 2 email routes and would need to create 4 total if I use Router, which seems excessive for this simple conditional logic.

Question:

Is there a way to conditionally build an attachments array in Make while preserving the binary data format that the Email module expects? Or is Router the only viable solution?

Thanks in advance!

Hi @Rapid-IT

I’m not sure if I understood your issue correctly without seeing the details of your scenario, but wouldn’t adding a Filter with filename Does not Equal No_Intro_Pack.pdf work? Then you would build the attachments array with whatever files pass the filter.

@damato

Why is using a router excessive though? Its the easiest and most straightforward way to do this. No complicated formulas or data conversions and trying to fight with Make to build a proper attachments array.

Semi-pseudocode:

if( file2.name != "No_Intro_Pack.pdf"; 
  add(emptyarray; file1.data; file2.data);
    add(emptyarray; file1.data)
)

Hope this helps! If that is not quite right, we can try exploring other options.

@samliew