@pipedream/slack 0.4.6 → 0.4.8
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
CHANGED
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
...common,
|
|
5
5
|
key: "slack-new-mention",
|
|
6
6
|
name: "New Mention (Instant)",
|
|
7
|
-
version: "1.0.
|
|
7
|
+
version: "1.0.5",
|
|
8
8
|
description: "Emit new event when a username or specific keyword is mentioned in a channel",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
@@ -49,8 +49,42 @@ export default {
|
|
|
49
49
|
],
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
+
hooks: {
|
|
53
|
+
...common.hooks,
|
|
54
|
+
async deploy() {
|
|
55
|
+
// emit historical events
|
|
56
|
+
const messages = await this.getMatches({
|
|
57
|
+
query: this.keyword,
|
|
58
|
+
sort: "timestamp",
|
|
59
|
+
});
|
|
60
|
+
const filteredMessages = this.conversations?.length > 0
|
|
61
|
+
? messages.filter((message) => this.conversations.includes(message.channel.id))
|
|
62
|
+
: messages;
|
|
63
|
+
await this.emitHistoricalEvents(filteredMessages.slice(-25).reverse());
|
|
64
|
+
},
|
|
65
|
+
},
|
|
52
66
|
methods: {
|
|
53
67
|
...common.methods,
|
|
68
|
+
async getMatches(params) {
|
|
69
|
+
return (await this.slack.sdk().search.messages(params)).messages.matches || [];
|
|
70
|
+
},
|
|
71
|
+
async emitHistoricalEvents(messages) {
|
|
72
|
+
for (const message of messages) {
|
|
73
|
+
const event = await this.processEvent(message);
|
|
74
|
+
if (event) {
|
|
75
|
+
if (!event.client_msg_id) {
|
|
76
|
+
event.pipedream_msg_id = `pd_${Date.now()}_${Math.random().toString(36)
|
|
77
|
+
.substr(2, 10)}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.$emit(event, {
|
|
81
|
+
id: event.client_msg_id || event.pipedream_msg_id,
|
|
82
|
+
summary: this.getSummary(event),
|
|
83
|
+
ts: event.event_ts || Date.now(),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
54
88
|
getSummary() {
|
|
55
89
|
return "New mention received";
|
|
56
90
|
},
|
|
@@ -77,14 +111,14 @@ export default {
|
|
|
77
111
|
for (const item of elements) {
|
|
78
112
|
if (item.user_id) {
|
|
79
113
|
const username = await this.getUserName(item.user_id);
|
|
80
|
-
if (username === this.
|
|
114
|
+
if (username === this.keyword) {
|
|
81
115
|
emitEvent = true;
|
|
82
116
|
break;
|
|
83
117
|
}
|
|
84
118
|
}
|
|
85
119
|
}
|
|
86
120
|
|
|
87
|
-
} else if (event.text.indexOf(this.
|
|
121
|
+
} else if (event.text.indexOf(this.keyword) !== -1) {
|
|
88
122
|
emitEvent = true;
|
|
89
123
|
}
|
|
90
124
|
if (emitEvent) {
|
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
...common,
|
|
9
9
|
key: "slack-new-star-added",
|
|
10
10
|
name: "New Star Added (Instant)",
|
|
11
|
-
version: "0.0.
|
|
11
|
+
version: "0.0.8",
|
|
12
12
|
description: "Emit new event when a star is added to an item",
|
|
13
13
|
type: "source",
|
|
14
14
|
dedupe: "unique",
|
|
@@ -38,7 +38,9 @@ export default {
|
|
|
38
38
|
return `New star added - ${events[type] ?? type}`;
|
|
39
39
|
},
|
|
40
40
|
async processEvent(event) {
|
|
41
|
-
if (this.eventTypes
|
|
41
|
+
if (this.eventTypes == null
|
|
42
|
+
|| this.eventTypes.length === 0
|
|
43
|
+
|| this.eventTypes.includes(event.item.type)) {
|
|
42
44
|
return event;
|
|
43
45
|
}
|
|
44
46
|
},
|