@pipedream/slack 0.4.6 → 0.4.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/slack",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Pipedream Slack Components",
5
5
  "main": "slack.app.mjs",
6
6
  "keywords": [
@@ -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.4",
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.word) {
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.word) !== -1) {
121
+ } else if (event.text.indexOf(this.keyword) !== -1) {
88
122
  emitEvent = true;
89
123
  }
90
124
  if (emitEvent) {