diff --git a/components/slack_v2/package.json b/components/slack_v2/package.json index 230f61af81e4c..e14fc69234b14 100644 --- a/components/slack_v2/package.json +++ b/components/slack_v2/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/slack_v2", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Slack_v2 Components", "main": "slack_v2.app.mjs", "keywords": [ diff --git a/components/slack_v2/sources/common/base-polling.mjs b/components/slack_v2/sources/common/base-polling.mjs new file mode 100644 index 0000000000000..d6d933f6fefdb --- /dev/null +++ b/components/slack_v2/sources/common/base-polling.mjs @@ -0,0 +1,50 @@ +import slack from "../../slack_v2.app.mjs"; +import { + DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError, +} from "@pipedream/platform"; + +export default { + props: { + slack, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getLastTs() { + return this.db.get("lastTs") || 0; + }, + _setLastTs(lastTs) { + this.db.set("lastTs", lastTs); + }, + getResources() { + throw new ConfigurationError("getResources is not implemented"); + }, + generateMeta() { + throw new ConfigurationError("generateMeta is not implemented"); + }, + async processEvents(max) { + const results = await this.getResources(max); + if (!results.length) { + return; + } + + results.forEach((result) => { + const meta = this.generateMeta(result); + this.$emit(result, meta); + }); + }, + }, + hooks: { + async deploy() { + await this.processEvents(10); + }, + }, + async run() { + await this.processEvents(); + }, +}; diff --git a/components/slack_v2/sources/new-private-channel-created/new-private-channel-created.mjs b/components/slack_v2/sources/new-private-channel-created/new-private-channel-created.mjs new file mode 100644 index 0000000000000..545085280d4b5 --- /dev/null +++ b/components/slack_v2/sources/new-private-channel-created/new-private-channel-created.mjs @@ -0,0 +1,55 @@ +import common from "../common/base-polling.mjs"; + +export default { + ...common, + key: "slack_v2-new-private-channel-created", + name: "New Private Channel Created", + version: "0.0.1", + description: "Emit new event when a new private channel is created. [See the documentation](https://api.slack.com/methods/conversations.list)", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + async getResources(max) { + const privateChannels = []; + const params = { + limit: 1000, + types: "private_channel", + }; + const lastTs = this._getLastTs(); + let maxTs = lastTs; + + do { + const { + channels, response_metadata: { next_cursor: nextCursor }, + } = await this.slack.conversationsList(params); + if (!channels.length) { + break; + } + for (const channel of channels) { + const ts = channel.created; + if (ts > lastTs) { + privateChannels.push(channel); + maxTs = Math.max(ts, maxTs); + } + } + params.cursor = nextCursor; + } while (params.cursor); + + this._setLastTs(maxTs); + + if (max && privateChannels.length > max) { + privateChannels.length = max; + } + + return privateChannels; + }, + generateMeta(channel) { + return { + id: channel.id, + summary: `New private channel created - ${channel.name}`, + ts: channel.created, + }; + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 10ae28a51a860..bfa8994a10a3b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6789,8 +6789,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/help_scout_api_keys: - specifiers: {} + components/help_scout_api_keys: {} components/helpcrunch: dependencies: @@ -11163,8 +11162,7 @@ importers: components/pingrabbit: {} - components/pinpoint: - specifiers: {} + components/pinpoint: {} components/pinterest: dependencies: