Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/slack_v2/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
50 changes: 50 additions & 0 deletions components/slack_v2/sources/common/base-polling.mjs
Original file line number Diff line number Diff line change
@@ -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();
},
};
Original file line number Diff line number Diff line change
@@ -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,
};
},
},
};
6 changes: 2 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading