Why is the JavaScript return object not resolving to the actual filename when trying to attach a file in an email automation process?

This topic was automatically generated from Slack. You can find the original thread here.

Hi, I’m wondering if this behaviour is normal:
Trigger: new Gmail attachment with certain label
Action 1: (JS) find zip folder attached to email
Action 2: (Gmail Developer) Download zip attachment to tmp using JS return object which has the url
Action 3: (JS) unzip attachment, look for a file starting with VO-ED & download it to tmp/ also return last week number and filename.
Action 4: (gmail developer app) Send email with attachment this is where I’m stuck, I’d like to attach the file found in step 3 to my email, unfortunately when I try to setup the key to the filename using my JS return object property, it doesn’t resolve to the actual filename (see pic).
Action 5 (upload zip folder to Gdrive)
Action 6 (notify on slack)

CCL: I do have the correct file attached to my email, but the filename & extensions are wrong

Here’s a share link: Sign Up - Pipedream

Custom expressions don’t currently work in object keys, so you’ll need to define the key:value object and pass as a custom expression for that attachments prop.

So in your first screenshot, select the “Enter a custom expression” tab, and either define the object directly in there, or I’d recommend adding a step right before and returning the object you want.

Hi Danny, ok thanks, sorry for the delay but I’m in EU so not the same timezone and I logged out yesterday, didn’t expect the answer to come so quickly!

  1. Tried the custom expression path first, doesn’t seem to work or I’m not setting it up correctly? dynamic variable path get resolved but I get errors
    a. when trying with a key value pair I get “ENOENT: no such file or directory, open ‘{’ ”
    b. when trying to attach the file directly from tmp I get a “EISDIR: illegal operation on a directory, read”
  2. Now I’ll try to modify the js code from previous action to return an object
    → 2 worked fine, I simply added following code to return object:
const orderFile = {};
          orderFile[foundFile.fileName] = foundFilePath;

          return { 
            files: orderFile,
            lastWeekNumber
          };

thank you very much for your support

Sorry, did it end up working for you?

Hi , not sure if you already solved this, but the Attachments prop requires a downloadable URL, not a file path from /tmp

I returned the {filename:file} as an object in the JS code and set that as a custom expression in the attachment field of the gmail block

  • Totally independent questions, but did you have any issues setting up the New Attachment Trigger? I set up a polling schedule for every 15 sec to catch a new attachment at 7:00AM daily.

I can trigger with a test email, but by 7:00AM the Gmail event emission does not trigger the workflow.

following up on this too! Having the same problem

cc can you help triage?

I’m able to replicate the issue - I’ve opened a bug report here, feel free to follow along!

Michael, I’m not sure what you meant by setting up a polling schedule to catch an attachment at 7:00AM daily - can you clarify your workflow setup? I was able to replicate the trigger not working as expected, by setting up a 15sec polling trigger, and after a while the trigger just stopped emitting new events.

Quick question and @U076HHH0ULQ, do you guys clearly receive more than 100 messages a day? What about 500?

I’m looking at the trigger code and we fetch the latest 100 messages, not sure why. We can increase to 500 (Gmail’s max limit per page)

If you’re able to filter by labels, that’d help the search filter reduce the number of messages being fetched

I think the whole polling for new emails strategy needs to be improved: pipedream/components/gmail_custom_oauth/sources/common/polling.mjs at master · PipedreamHQ/pipedream · GitHub

Hi Andrew-- We receive ~10 emails per in this inbox. -I added the “labels” filter and set up a Gmail rule which I agree should be best practice for polling
-I noticed the inbound email was sent to as a “cc” instead of “to” which I’m updating today

I created another 2 workflows to trigger at (1) 7:15 AM EST and (2) every 15 minutes.

The 7:15AM EST appeared successful today, but the 15-min intervals failed to trigger

Ah yes, you were talking with that if the email address was CC’d instead of sent directly TO, it didn’t trigger the workflow, yeah?

Interesting that the second workflow failed to trigger. Could you share the workflow URL? It should look something like: