user-1
(User 1)
April 8, 2025, 12:56pm
1
This topic was automatically generated from Slack. You can find the original thread here .
:
How do you reuse methods from an app file?
Documentation read:
Whenever possible, reuse methods defined in the app file. If you need to use an API for which a method is not defined and it may be used in future components, define a new method in the app file.
But, how do you that? For example, gmail.app.mjs defines getAttachment
and I would like to reuse that method in my own component (note that getAttachment
calls _client
). Any tips?
user-1
(User 1)
April 8, 2025, 12:56pm
2
Check out our actions, for example this one:
import gmail from "../../gmail.app.mjs";
import fs from "fs";
import path from "path";
import { ConfigurationError } from "@pipedream/platform";
export default {
key: "gmail-download-attachment",
name: "Download Attachment",
description: "Download an attachment by attachmentId to the /tmp directory. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.messages.attachments/get)",
version: "0.0.5",
type: "action",
props: {
gmail,
messageId: {
propDefinition: [
gmail,
"messageWithAttachments",
],
},
attachmentId: {
This file has been truncated. show original
user-1
(User 1)
April 8, 2025, 12:56pm
3
You import the file locally or from the npm package @pipedream/gmail
user-1
(User 1)
April 8, 2025, 12:56pm
4
user-1
(User 1)
April 8, 2025, 12:56pm
5
Then all methods from the app file will be available as: this.gmail.methodName()
user-1
(User 1)
April 8, 2025, 12:56pm
6
user-1
(User 1)
April 8, 2025, 12:56pm
7
Thank you Andrew, this works.
Bottom line is to import the npm package and use it in props
!