@pipedream/slack 0.4.26 → 0.4.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/sources/common/base.mjs +93 -35
- package/sources/common/constants.mjs +3 -0
- package/sources/new-direct-message/new-direct-message.mjs +1 -1
- package/sources/new-interaction-event-received/new-interaction-event-received.mjs +1 -1
- package/sources/new-mention/new-mention.mjs +1 -1
- package/sources/new-message-in-channels/new-message-in-channels.mjs +1 -1
- package/sources/new-reaction-added/new-reaction-added.mjs +1 -1
- package/sources/new-star-added/new-star-added.mjs +1 -1
package/package.json
CHANGED
package/sources/common/base.mjs
CHANGED
|
@@ -1,21 +1,86 @@
|
|
|
1
1
|
import slack from "../../slack.app.mjs";
|
|
2
|
+
import {
|
|
3
|
+
NAME_CACHE_MAX_SIZE, NAME_CACHE_TIMEOUT,
|
|
4
|
+
} from "./constants.mjs";
|
|
2
5
|
|
|
3
6
|
export default {
|
|
4
7
|
props: {
|
|
5
8
|
slack,
|
|
6
|
-
|
|
9
|
+
db: "$.service.db",
|
|
7
10
|
},
|
|
8
11
|
methods: {
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
_getNameCache() {
|
|
13
|
+
return this.db.get("nameCache") ?? {};
|
|
14
|
+
},
|
|
15
|
+
_setNameCache(cacheObj) {
|
|
16
|
+
this.db.set("nameCache", cacheObj);
|
|
17
|
+
},
|
|
18
|
+
_getLastCacheCleanup() {
|
|
19
|
+
return this.db.get("lastCacheCleanup") ?? 0;
|
|
20
|
+
},
|
|
21
|
+
_setLastCacheCleanup(time) {
|
|
22
|
+
this.db.set("lastCacheCleanup", time);
|
|
23
|
+
},
|
|
24
|
+
cleanCache(cacheObj) {
|
|
25
|
+
console.log("Initiating cache check-up...");
|
|
26
|
+
const timeout = Date.now() - NAME_CACHE_TIMEOUT;
|
|
27
|
+
|
|
28
|
+
const entries = Object.entries(cacheObj);
|
|
29
|
+
let cleanArr = entries.filter(
|
|
30
|
+
([
|
|
31
|
+
, { ts },
|
|
32
|
+
]) => ts > timeout,
|
|
33
|
+
);
|
|
34
|
+
const diff = entries.length - cleanArr.length;
|
|
35
|
+
if (diff) {
|
|
36
|
+
console.log(`Cleaned up ${diff} outdated cache entries.`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (cleanArr.length > NAME_CACHE_MAX_SIZE) {
|
|
40
|
+
console.log(`Reduced the cache from ${cleanArr.length} to ${NAME_CACHE_MAX_SIZE / 2} entries.`);
|
|
41
|
+
cleanArr = cleanArr.slice(NAME_CACHE_MAX_SIZE / -2);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const cleanObj = Object.fromEntries(cleanArr);
|
|
45
|
+
return cleanObj;
|
|
46
|
+
},
|
|
47
|
+
getCache() {
|
|
48
|
+
let cacheObj = this._getNameCache();
|
|
49
|
+
|
|
50
|
+
const lastCacheCleanup = this._getLastCacheCleanup();
|
|
51
|
+
const time = Date.now();
|
|
52
|
+
|
|
53
|
+
const shouldCleanCache = time - lastCacheCleanup > NAME_CACHE_TIMEOUT / 2;
|
|
54
|
+
if (shouldCleanCache) {
|
|
55
|
+
cacheObj = this.cleanCache(cacheObj);
|
|
56
|
+
this._setLastCacheCleanup(time);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return [
|
|
60
|
+
cacheObj,
|
|
61
|
+
shouldCleanCache,
|
|
62
|
+
];
|
|
63
|
+
},
|
|
64
|
+
async maybeCached(key, refreshVal) {
|
|
65
|
+
let [
|
|
66
|
+
cacheObj,
|
|
67
|
+
wasUpdated,
|
|
68
|
+
] = this.getCache();
|
|
69
|
+
let record = cacheObj[key];
|
|
11
70
|
const time = Date.now();
|
|
12
|
-
if (!record || time - record.ts >
|
|
71
|
+
if (!record || time - record.ts > NAME_CACHE_TIMEOUT) {
|
|
13
72
|
record = {
|
|
14
73
|
ts: time,
|
|
15
74
|
val: await refreshVal(),
|
|
16
75
|
};
|
|
17
|
-
|
|
76
|
+
cacheObj[key] = record;
|
|
77
|
+
wasUpdated = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (wasUpdated) {
|
|
81
|
+
this._setNameCache(cacheObj);
|
|
18
82
|
}
|
|
83
|
+
|
|
19
84
|
return record.val;
|
|
20
85
|
},
|
|
21
86
|
async getUserName(id) {
|
|
@@ -56,43 +121,35 @@ export default {
|
|
|
56
121
|
});
|
|
57
122
|
return info.team.name;
|
|
58
123
|
} catch (err) {
|
|
59
|
-
console.log(
|
|
124
|
+
console.log(
|
|
125
|
+
"Error getting team name, probably need to re-connect the account at pipedream.com/apps",
|
|
126
|
+
err,
|
|
127
|
+
);
|
|
60
128
|
return id;
|
|
61
129
|
}
|
|
62
130
|
});
|
|
63
131
|
},
|
|
64
|
-
async getLastMessage({
|
|
65
|
-
channel, event_ts,
|
|
66
|
-
}) {
|
|
67
|
-
return this.maybeCached(`lastMessage:${channel}:${event_ts}`, async () => {
|
|
68
|
-
const info = await this.slack.sdk().conversations.history({
|
|
69
|
-
channel,
|
|
70
|
-
latest: event_ts,
|
|
71
|
-
limit: 1,
|
|
72
|
-
inclusive: true,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return info;
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
132
|
async getMessage({
|
|
79
|
-
channel, event_ts,
|
|
133
|
+
channel, event_ts: ts,
|
|
80
134
|
}) {
|
|
81
|
-
return await this.maybeCached(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
135
|
+
return await this.maybeCached(
|
|
136
|
+
`lastMessage:${channel}:${ts}`,
|
|
137
|
+
async () => {
|
|
138
|
+
const response = await this.slack.sdk().conversations.replies({
|
|
139
|
+
channel,
|
|
140
|
+
ts,
|
|
141
|
+
limit: 1,
|
|
142
|
+
});
|
|
87
143
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
144
|
+
if (response.messages.length) {
|
|
145
|
+
response.messages = [
|
|
146
|
+
response.messages[0],
|
|
147
|
+
];
|
|
148
|
+
}
|
|
93
149
|
|
|
94
|
-
|
|
95
|
-
|
|
150
|
+
return response;
|
|
151
|
+
},
|
|
152
|
+
);
|
|
96
153
|
},
|
|
97
154
|
processEvent(event) {
|
|
98
155
|
return event;
|
|
@@ -103,7 +160,8 @@ export default {
|
|
|
103
160
|
|
|
104
161
|
if (event) {
|
|
105
162
|
if (!event.client_msg_id) {
|
|
106
|
-
event.pipedream_msg_id = `pd_${Date.now()}_${Math.random()
|
|
163
|
+
event.pipedream_msg_id = `pd_${Date.now()}_${Math.random()
|
|
164
|
+
.toString(36)
|
|
107
165
|
.substr(2, 10)}`;
|
|
108
166
|
}
|
|
109
167
|
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
...common,
|
|
5
5
|
key: "slack-new-direct-message",
|
|
6
6
|
name: "New Direct Message (Instant)",
|
|
7
|
-
version: "1.0.
|
|
7
|
+
version: "1.0.12",
|
|
8
8
|
description: "Emit new event when a message was posted in a direct message channel",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
@@ -2,7 +2,7 @@ import common from "../common/base.mjs";
|
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
name: "New Interaction Events",
|
|
5
|
-
version: "0.0.
|
|
5
|
+
version: "0.0.9",
|
|
6
6
|
key: "slack-new-interaction-event-received",
|
|
7
7
|
description:
|
|
8
8
|
"Emit new events on new Slack [interactivity events](https://api.slack.com/interactivity) sourced from [Block Kit interactive elements](https://api.slack.com/interactivity/components), [Slash commands](https://api.slack.com/interactivity/slash-commands), or [Shortcuts](https://api.slack.com/interactivity/shortcuts).",
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
...common,
|
|
6
6
|
key: "slack-new-mention",
|
|
7
7
|
name: "New Mention (Instant)",
|
|
8
|
-
version: "1.0.
|
|
8
|
+
version: "1.0.15",
|
|
9
9
|
description: "Emit new event when a username or specific keyword is mentioned in a channel",
|
|
10
10
|
type: "source",
|
|
11
11
|
dedupe: "unique",
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
...common,
|
|
6
6
|
key: "slack-new-message-in-channels",
|
|
7
7
|
name: "New Message In Channels (Instant)",
|
|
8
|
-
version: "1.0.
|
|
8
|
+
version: "1.0.12",
|
|
9
9
|
description: "Emit new event when a new message is posted to one or more channels",
|
|
10
10
|
type: "source",
|
|
11
11
|
dedupe: "unique",
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
...common,
|
|
5
5
|
key: "slack-new-reaction-added",
|
|
6
6
|
name: "New Reaction Added (Instant)",
|
|
7
|
-
version: "1.1.
|
|
7
|
+
version: "1.1.16",
|
|
8
8
|
description: "Emit new event when a member has added an emoji reaction to a message",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|