Filter for Email Attachments Stops After First PDF – How to Process Multiple PDFs?

What are you trying to achieve?

I’m trying to pass email attachments to ChatGPT (to the vector storage), but only PDF files should be processed. The email may contain multiple attachments (e.g., 2 PDFs and 2 PNGs).

Steps taken so far

I’ve implemented a filter to exclude non-PDF files, but it stops after the first PDF is processed. For example:

If an email has attachments like file1.pdf, file2.pdf, image1.png, and image2.png, the filter removes the PNGs but only processes file1.pdf and ignores file2.pdf.

How can I adjust the filter to handle all PDF attachments in the email, regardless of how many there are?

Current setup:

  1. Trigger: “Watch Emails” (new email arrives).
  2. Iterator: Processes email attachments.
  3. Filter: Intended to exclude non-PDF files (e.g., PNGs).
  4. Action: Upload remaining PDFs to OpenAI.

Filter logic: [Briefly describe your current filter setup]

Thanks for any help!

Screenshots: scenario setup, module configuration, errors




Welcome to the Make community!

You probably need to aggregate the files before calling the assistant.

Combining Bundles Using Aggregators

Every result (item/record) from trigger/iterator/list/search/match modules will output a bundle. This can result in multiple bundles, which then trigger multiple operations in future modules (one operation per bundle). To “combine” multiple bundles into a single variable, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module. The next popular aggregator is the Text Aggregator which is very flexible and can apply to many use-cases like building of JSON, CSV, HTML.

You can find out more about the other types of aggregator modules here:

Question: Which is the best aggregator do you think you’ll need for your use-case?

Mapping a Specific Structure Into a Complex Field

If you have an array of collections, in programming terms, this is called an array of objects, or an array with non-primitive data types (“complex”).

The Array Aggregator module is very powerful because it allows you to build a new complex array of collections that matches a later module’s field to map multiple items (collections) to it. Such fields initially would allow you to manually add items, but you can toggle the “Map” switch to the “on” state and map a whole array into a single field.

This is done by selecting the “Target structure type” in an Array Aggregator module.

As you can see from the above example, the “Map” toggle on complex fields are used when you have an array variable (like from an array aggregator). Other combinations of modules may also allow you to generate an array that matches a future field’s array structure, like “Aggregate to JSON + Parse JSON”, or “Create JSON + Parse JSON”, but this is an advanced topic.

Question: Are you mapping your array into a field that accepts more than one item/collection?

Example

Here is an example of how your scenario could look like:

This is just an example. Your final solution may or may not look like this depending on your requirements and actual data.

For more information, see “Mapping with arrays” in the Help Centre. You should also do the Make Academy, which also covers the use of Iterators & Aggregators.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

Hi @samliew,

First of all, thank you so much for taking the time to explain this in such detail! Your guidance on aggregators and filters was incredibly helpful - I really appreciate how clear and patient you were. :folded_hands:

I tried implementing your suggestions, but I’m still running into a small hiccup. Here’s what I did step by step:

  1. Trigger: “Watch Emails” (new email arrives).
  2. Iterator: Processes all email attachments.
  3. Filter: Set to allow only PDFs
  4. Array Aggregator: Meant to collect the filtered PDFs.

The Issue:


Even though the filter shows it’s blocking PNGs,

the aggregator’s output bundle still contains all 4 original files (2 PDFs + 2 PNGs).

Worse, when I pass this to the next step (e.g., uploading to Nextcloud), it processes one of the PNGs instead of just the PDFs. :sweat_smile:

What I’m Confused About:

  • Why does the aggregator still see the PNGs if the filter removed them?
  • Should I adjust the aggregator’s settings, or is there a mapping step I’m missing?

I’ve attached a screenshots of my setup —maybe I misconnected something?

Thanks again for your kindness and expertise! I’m really grateful for your support and any further tips you might have.

Warm regards


Have you tried to set the filter after the aggregator?

The issue might be that the aggregator takes every attachment and doesn’t filter by format.

If you set the filter before the Nextcloud module, it should work.

You are aggregating the incorrect field. Uncheck the “Attachments” field.

Then, try scrolling up and only select fields coming from the Iterator module.

Hope this helps! Let me know if there are any further questions or issues.

@samliew