@frogbotai/piece-slack 0.29.0 → 0.31.0
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/README.md +3 -2
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +286 -196
- package/dist/actions.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +47 -35
- package/dist/client.js.map +1 -1
- package/dist/config.js +17 -5
- package/dist/config.js.map +1 -1
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +1 -0
- package/dist/define.js.map +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +25 -17
- package/dist/files.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -48
- package/dist/index.js.map +1 -1
- package/dist/options.js +36 -21
- package/dist/options.js.map +1 -1
- package/dist/questions/blocks.js +148 -74
- package/dist/questions/blocks.js.map +1 -1
- package/dist/questions/index.js +2 -1
- package/dist/questions/index.js.map +1 -1
- package/dist/questions/notify.js +19 -13
- package/dist/questions/notify.js.map +1 -1
- package/dist/questions/parse.js +110 -59
- package/dist/questions/parse.js.map +1 -1
- package/dist/questions/render.js +16 -7
- package/dist/questions/render.js.map +1 -1
- package/dist/questions/settled.js +9 -3
- package/dist/questions/settled.js.map +1 -1
- package/dist/questions/slackThread.js +12 -6
- package/dist/questions/slackThread.js.map +1 -1
- package/dist/questions/state.js +18 -5
- package/dist/questions/state.js.map +1 -1
- package/dist/questions/updated.js +32 -24
- package/dist/questions/updated.js.map +1 -1
- package/dist/triggers.d.ts.map +1 -1
- package/dist/triggers.js +150 -126
- package/dist/triggers.js.map +1 -1
- package/dist/webhook.d.ts.map +1 -1
- package/dist/webhook.js +28 -43
- package/dist/webhook.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,57 +1,65 @@
|
|
|
1
|
-
import { encodeQuestionModalMetadata
|
|
1
|
+
import { encodeQuestionModalMetadata } from 'frogbot/pieces';
|
|
2
2
|
import { actionIds, customAnswerView } from './blocks.js';
|
|
3
3
|
import { interactionUserId, postEphemeral } from './slackThread.js';
|
|
4
4
|
import { customAnswers } from './state.js';
|
|
5
|
-
export const updateSlackQuestion = async ({ call, client, interaction, question, req, thread
|
|
6
|
-
if (!interaction)
|
|
7
|
-
return;
|
|
5
|
+
export const updateSlackQuestion = async ({ call, client, interaction, question, req, thread })=>{
|
|
6
|
+
if (!interaction) return;
|
|
8
7
|
try {
|
|
9
|
-
await respond({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
await respond({
|
|
9
|
+
call,
|
|
10
|
+
client,
|
|
11
|
+
interaction,
|
|
12
|
+
question,
|
|
13
|
+
thread
|
|
14
|
+
});
|
|
15
|
+
} catch (error) {
|
|
16
|
+
req.frogbot.logger.error({
|
|
17
|
+
err: error,
|
|
18
|
+
piece: 'slack',
|
|
19
|
+
toolCallId: call.toolCallId
|
|
20
|
+
}, '[piece-slack] Could not respond to a question interaction.');
|
|
13
21
|
}
|
|
14
22
|
};
|
|
15
|
-
async function respond({ call, client, interaction, question, thread
|
|
23
|
+
async function respond({ call, client, interaction, question, thread }) {
|
|
16
24
|
if (interaction.type === 'modalSubmit') {
|
|
17
25
|
await postEphemeral({
|
|
18
26
|
client,
|
|
19
27
|
interaction,
|
|
20
28
|
text: 'Saved your typed answer. Press *Submit* when every question is answered.',
|
|
21
|
-
threadId: thread.id
|
|
29
|
+
threadId: thread.id
|
|
22
30
|
});
|
|
23
31
|
return;
|
|
24
32
|
}
|
|
25
|
-
if (interaction.type !== 'action')
|
|
26
|
-
return;
|
|
33
|
+
if (interaction.type !== 'action') return;
|
|
27
34
|
const { actionId, triggerId } = interaction.event;
|
|
28
|
-
const q = call.input.questions.findIndex((_, index)
|
|
29
|
-
if (q === -1 || !triggerId)
|
|
30
|
-
return;
|
|
35
|
+
const q = call.input.questions.findIndex((_, index)=>actionId === actionIds.custom(call, index));
|
|
36
|
+
if (q === -1 || !triggerId) return;
|
|
31
37
|
const view = customAnswerView({
|
|
32
38
|
call,
|
|
33
39
|
initialValue: customAnswers({
|
|
34
40
|
state: question.state,
|
|
35
|
-
userId: interactionUserId(interaction)
|
|
41
|
+
userId: interactionUserId(interaction)
|
|
36
42
|
})[q],
|
|
37
43
|
metadata: encodeQuestionModalMetadata({
|
|
38
44
|
threadId: thread.id,
|
|
39
|
-
messageId: question.messages.at(-1).id
|
|
45
|
+
messageId: question.messages.at(-1).id
|
|
40
46
|
}),
|
|
41
|
-
q
|
|
47
|
+
q
|
|
42
48
|
});
|
|
43
49
|
try {
|
|
44
|
-
await client.request('views.open', {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
await client.request('views.open', {
|
|
51
|
+
trigger_id: triggerId,
|
|
52
|
+
view
|
|
53
|
+
});
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (!(error instanceof Error) || !error.message.includes('expired_trigger_id')) throw error;
|
|
49
56
|
await postEphemeral({
|
|
50
57
|
client,
|
|
51
58
|
interaction,
|
|
52
59
|
text: 'That took too long. Press the button again to type your answer.',
|
|
53
|
-
threadId: thread.id
|
|
60
|
+
threadId: thread.id
|
|
54
61
|
});
|
|
55
62
|
}
|
|
56
63
|
}
|
|
64
|
+
|
|
57
65
|
//# sourceMappingURL=updated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/updated.ts"],"names":["encodeQuestionModalMetadata","actionIds","customAnswerView","interactionUserId","postEphemeral","customAnswers","updateSlackQuestion","call","client","interaction","question","req","thread","respond","error","frogbot","logger","err","piece","toolCallId","type","text","threadId","id","actionId","triggerId","event","q","input","questions","findIndex","_","index","custom","view","initialValue","state","userId","metadata","messageId","messages","at","request","trigger_id","Error","message","includes"],"mappings":"AAAA,SACEA,2BAA2B,QAGtB,iBAAiB;AAGxB,SAASC,SAAS,EAAEC,gBAAgB,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QACzC;QACAI;IACF;IAEA,IAAI;QACF,MAAMnB,OAAOkC,OAAO,CAAC,cAAc;YAAEC,YAAYlB;YAAWS;QAAK;IACnE,EAAE,OAAOpB,OAAO;QACd,IAAI,CAAEA,CAAAA,iBAAiB8B,KAAI,KAAM,CAAC9B,MAAM+B,OAAO,CAACC,QAAQ,CAAC,uBAAuB,MAAMhC;QAEtF,MAAMV,cAAc;YAClBI;YACAC;YACAY,MAAM;YACNC,UAAUV,OAAOW,EAAE;QACrB;IACF;AACF","file":"updated.js"}
|
package/dist/triggers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../src/triggers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../src/triggers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwExB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;kBAZiC,CAAC;gBAEpD,CAAC;mBAEgB,CAAC;iBACtB,CAAC;;;;;;;;;;gBAwD6B,CAAC;;iBACd,CAAC;iBAAuB,CAAC;;;;;;;CAnC7C,CAAC;AAIH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;kBA/B0B,CAAC;gBAEpD,CAAC;mBAEgB,CAAC;iBACtB,CAAC;;;;;;;;;;gBAwD6B,CAAC;;iBACd,CAAC;iBAAuB,CAAC;;;;;;;CAf7C,CAAC;AAIH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;kBAnD2B,CAAC;gBAEpD,CAAC;mBAEgB,CAAC;iBACtB,CAAC;;;;;;;;;;gBAwD6B,CAAC;;iBACd,CAAC;iBAAuB,CAAC;;;;;;;CAO7C,CAAC;AAUH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;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;;;kBA9Da,CAAC;gBAEpD,CAAC;mBAEgB,CAAC;iBACtB,CAAC;;;;;;;;;;gBAwD6B,CAAC;;iBACd,CAAC;iBAAuB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;kBA9Da,CAAC;gBAEpD,CAAC;mBAEgB,CAAC;iBACtB,CAAC;;;;;;;;;;gBAwD6B,CAAC;;iBACd,CAAC;iBAAuB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA9Da,CAAC;gBAEpD,CAAC;mBAEgB,CAAC;iBACtB,CAAC;;;;;;;;;;gBAwD6B,CAAC;;iBACd,CAAC;iBAAuB,CAAC;;;;;;;KAqS9C,CAAC"}
|
package/dist/triggers.js
CHANGED
|
@@ -5,53 +5,54 @@ import { defineAppTrigger } from './define.js';
|
|
|
5
5
|
import { slackEvent, slackWorkspace } from './webhook.js';
|
|
6
6
|
const emptyInput = z.object({});
|
|
7
7
|
const messageFilters = {
|
|
8
|
-
ignoreBots: z.boolean().default(false)
|
|
8
|
+
ignoreBots: z.boolean().default(false)
|
|
9
9
|
};
|
|
10
10
|
const selfFilters = {
|
|
11
11
|
...messageFilters,
|
|
12
|
-
ignoreSelfMessages: z.boolean().default(false)
|
|
12
|
+
ignoreSelfMessages: z.boolean().default(false)
|
|
13
13
|
};
|
|
14
|
-
const channel = z.string().min(1).meta({
|
|
15
|
-
|
|
14
|
+
const channel = z.string().min(1).meta({
|
|
15
|
+
label: 'Channel ID'
|
|
16
|
+
});
|
|
17
|
+
const user = z.string().min(1).meta({
|
|
18
|
+
label: 'User ID'
|
|
19
|
+
});
|
|
16
20
|
const eventOutput = slackValue;
|
|
17
21
|
async function event(args) {
|
|
18
22
|
const deliveredWorkspace = slackWorkspace(args.req);
|
|
19
|
-
if (!deliveredWorkspace || deliveredWorkspace !==
|
|
23
|
+
if (!deliveredWorkspace || deliveredWorkspace !== await args.client.workspaceId()) {
|
|
20
24
|
return undefined;
|
|
21
25
|
}
|
|
22
26
|
return slackEvent(args.req);
|
|
23
27
|
}
|
|
24
28
|
function emit(value) {
|
|
25
|
-
return value
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]
|
|
32
|
-
: [];
|
|
29
|
+
return value ? [
|
|
30
|
+
{
|
|
31
|
+
dedupeKey: createHash('sha256').update(JSON.stringify(value)).digest('hex'),
|
|
32
|
+
data: value
|
|
33
|
+
}
|
|
34
|
+
] : [];
|
|
33
35
|
}
|
|
34
36
|
function field(value, key) {
|
|
35
37
|
return key in value ? value[key] : undefined;
|
|
36
38
|
}
|
|
37
39
|
function eventMap(value) {
|
|
38
|
-
return value && typeof value === 'object' && !Array.isArray(value)
|
|
39
|
-
? Object.fromEntries(Object.entries(value))
|
|
40
|
-
: undefined;
|
|
40
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? Object.fromEntries(Object.entries(value)) : undefined;
|
|
41
41
|
}
|
|
42
42
|
async function selfUser(client) {
|
|
43
43
|
const response = await client.request('auth.test');
|
|
44
44
|
return typeof response.user_id === 'string' ? response.user_id : undefined;
|
|
45
45
|
}
|
|
46
46
|
function command(text, userId, commands) {
|
|
47
|
-
if (typeof text !== 'string')
|
|
48
|
-
return undefined;
|
|
47
|
+
if (typeof text !== 'string') return undefined;
|
|
49
48
|
const match = text.match(new RegExp(`<@${userId}>\\s+(.+)`, 's'));
|
|
50
|
-
if (!match)
|
|
51
|
-
return undefined;
|
|
49
|
+
if (!match) return undefined;
|
|
52
50
|
const parts = match[1].trim().split(/\s+/);
|
|
53
51
|
const name = parts[0].toLowerCase();
|
|
54
|
-
return commands.includes(name) ? {
|
|
52
|
+
return commands.includes(name) ? {
|
|
53
|
+
command: name,
|
|
54
|
+
args: parts.slice(1)
|
|
55
|
+
} : undefined;
|
|
55
56
|
}
|
|
56
57
|
const anyMessageInput = z.object(messageFilters);
|
|
57
58
|
export const messageCreated = defineAppTrigger({
|
|
@@ -61,16 +62,19 @@ export const messageCreated = defineAppTrigger({
|
|
|
61
62
|
event: 'message',
|
|
62
63
|
input: anyMessageInput,
|
|
63
64
|
output: eventOutput,
|
|
64
|
-
async run(args) {
|
|
65
|
+
async run (args) {
|
|
65
66
|
const value = await event(args);
|
|
66
|
-
if (!value || ![
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (!value || ![
|
|
68
|
+
'channel',
|
|
69
|
+
'group'
|
|
70
|
+
].includes(String(field(value, 'channel_type')))) return [];
|
|
71
|
+
if (args.input.ignoreBots && field(value, 'bot_id')) return [];
|
|
70
72
|
return emit(value);
|
|
71
|
-
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const channelMessageInput = anyMessageInput.extend({
|
|
76
|
+
channel
|
|
72
77
|
});
|
|
73
|
-
const channelMessageInput = anyMessageInput.extend({ channel });
|
|
74
78
|
export const channelMessageCreated = defineAppTrigger({
|
|
75
79
|
slug: 'channelMessageCreated',
|
|
76
80
|
description: 'Trigger for a message in one selected channel.',
|
|
@@ -78,16 +82,16 @@ export const channelMessageCreated = defineAppTrigger({
|
|
|
78
82
|
event: 'message',
|
|
79
83
|
input: channelMessageInput,
|
|
80
84
|
output: eventOutput,
|
|
81
|
-
async run(args) {
|
|
85
|
+
async run (args) {
|
|
82
86
|
const value = await event(args);
|
|
83
|
-
if (!value || ![
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
87
|
+
if (!value || ![
|
|
88
|
+
'channel',
|
|
89
|
+
'group'
|
|
90
|
+
].includes(String(field(value, 'channel_type')))) return [];
|
|
91
|
+
if (field(value, 'channel') !== args.input.channel) return [];
|
|
92
|
+
if (args.input.ignoreBots && field(value, 'bot_id')) return [];
|
|
89
93
|
return emit(value);
|
|
90
|
-
}
|
|
94
|
+
}
|
|
91
95
|
});
|
|
92
96
|
const directMessageInput = z.object(selfFilters);
|
|
93
97
|
export const directMessageCreated = defineAppTrigger({
|
|
@@ -97,24 +101,28 @@ export const directMessageCreated = defineAppTrigger({
|
|
|
97
101
|
event: 'message',
|
|
98
102
|
input: directMessageInput,
|
|
99
103
|
output: eventOutput,
|
|
100
|
-
async run(args) {
|
|
104
|
+
async run (args) {
|
|
101
105
|
const value = await event(args);
|
|
102
|
-
if (!value || field(value, 'channel_type') !== 'im')
|
|
103
|
-
|
|
104
|
-
if (args.input.
|
|
105
|
-
return [];
|
|
106
|
-
if (args.input.ignoreSelfMessages && field(value, 'user') === (await selfUser(args.client))) {
|
|
106
|
+
if (!value || field(value, 'channel_type') !== 'im') return [];
|
|
107
|
+
if (args.input.ignoreBots && field(value, 'bot_id')) return [];
|
|
108
|
+
if (args.input.ignoreSelfMessages && field(value, 'user') === await selfUser(args.client)) {
|
|
107
109
|
return [];
|
|
108
110
|
}
|
|
109
111
|
return emit(value);
|
|
110
|
-
}
|
|
112
|
+
}
|
|
111
113
|
});
|
|
112
114
|
const mentionInput = z.object({
|
|
113
|
-
users: z.array(z.string()).default([]).meta({
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
users: z.array(z.string()).default([]).meta({
|
|
116
|
+
label: 'User IDs'
|
|
117
|
+
}),
|
|
118
|
+
userGroups: z.array(z.string()).default([]).meta({
|
|
119
|
+
label: 'User group IDs'
|
|
120
|
+
}),
|
|
121
|
+
channels: z.array(z.string()).default([]).meta({
|
|
122
|
+
label: 'Channel IDs'
|
|
123
|
+
}),
|
|
116
124
|
ignoreBots: z.boolean().default(false),
|
|
117
|
-
removeMention: z.boolean().default(false)
|
|
125
|
+
removeMention: z.boolean().default(false)
|
|
118
126
|
});
|
|
119
127
|
export const channelMentionCreated = defineAppTrigger({
|
|
120
128
|
slug: 'channelMentionCreated',
|
|
@@ -123,36 +131,40 @@ export const channelMentionCreated = defineAppTrigger({
|
|
|
123
131
|
event: 'message',
|
|
124
132
|
input: mentionInput,
|
|
125
133
|
output: eventOutput,
|
|
126
|
-
async run(args) {
|
|
134
|
+
async run (args) {
|
|
127
135
|
const value = await event(args);
|
|
128
|
-
if (!value || ![
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
if (!value || ![
|
|
137
|
+
'channel',
|
|
138
|
+
'group'
|
|
139
|
+
].includes(String(field(value, 'channel_type')))) return [];
|
|
140
|
+
if (args.input.channels.length && !args.input.channels.includes(String(field(value, 'channel')))) {
|
|
132
141
|
return [];
|
|
133
142
|
}
|
|
134
|
-
if (args.input.ignoreBots && field(value, 'bot_id'))
|
|
135
|
-
return [];
|
|
143
|
+
if (args.input.ignoreBots && field(value, 'bot_id')) return [];
|
|
136
144
|
const text = String(field(value, 'text') ?? '');
|
|
137
|
-
const users = args.input.users.filter((id)
|
|
138
|
-
const groups = args.input.userGroups.filter((id)
|
|
139
|
-
if (!users.length && !groups.length)
|
|
140
|
-
|
|
141
|
-
if (!args.input.removeMention)
|
|
142
|
-
return emit(value);
|
|
145
|
+
const users = args.input.users.filter((id)=>text.includes(`<@${id}>`));
|
|
146
|
+
const groups = args.input.userGroups.filter((id)=>text.includes(`<!subteam^${id}`));
|
|
147
|
+
if (!users.length && !groups.length) return [];
|
|
148
|
+
if (!args.input.removeMention) return emit(value);
|
|
143
149
|
let cleanText = text;
|
|
144
|
-
for (const id of users)
|
|
145
|
-
|
|
146
|
-
for (const id of groups) {
|
|
150
|
+
for (const id of users)cleanText = cleanText.replaceAll(`<@${id}>`, '');
|
|
151
|
+
for (const id of groups){
|
|
147
152
|
cleanText = cleanText.replace(new RegExp(`<!subteam\\^${id}(\\|[^>]*)?>`, 'g'), '');
|
|
148
153
|
}
|
|
149
|
-
return emit({
|
|
150
|
-
|
|
154
|
+
return emit({
|
|
155
|
+
...value,
|
|
156
|
+
clean_text: cleanText.trim()
|
|
157
|
+
});
|
|
158
|
+
}
|
|
151
159
|
});
|
|
152
160
|
const reactionInput = z.object({
|
|
153
161
|
emojis: z.array(z.string()).default([]),
|
|
154
|
-
user: z.string().optional().meta({
|
|
155
|
-
|
|
162
|
+
user: z.string().optional().meta({
|
|
163
|
+
label: 'User ID'
|
|
164
|
+
}),
|
|
165
|
+
channels: z.array(z.string()).default([]).meta({
|
|
166
|
+
label: 'Channel IDs'
|
|
167
|
+
})
|
|
156
168
|
});
|
|
157
169
|
function reactionTrigger(slug, eventName, description) {
|
|
158
170
|
return defineAppTrigger({
|
|
@@ -162,14 +174,11 @@ function reactionTrigger(slug, eventName, description) {
|
|
|
162
174
|
event: eventName,
|
|
163
175
|
input: reactionInput,
|
|
164
176
|
output: eventOutput,
|
|
165
|
-
async run(args) {
|
|
177
|
+
async run (args) {
|
|
166
178
|
const value = await event(args);
|
|
167
|
-
if (!value)
|
|
168
|
-
|
|
169
|
-
if (args.input.
|
|
170
|
-
return [];
|
|
171
|
-
if (args.input.emojis.length &&
|
|
172
|
-
!args.input.emojis.includes(String(field(value, 'reaction')))) {
|
|
179
|
+
if (!value) return [];
|
|
180
|
+
if (args.input.user && field(value, 'user') !== args.input.user) return [];
|
|
181
|
+
if (args.input.emojis.length && !args.input.emojis.includes(String(field(value, 'reaction')))) {
|
|
173
182
|
return [];
|
|
174
183
|
}
|
|
175
184
|
const item = eventMap(field(value, 'item'));
|
|
@@ -178,7 +187,7 @@ function reactionTrigger(slug, eventName, description) {
|
|
|
178
187
|
return [];
|
|
179
188
|
}
|
|
180
189
|
return emit(value);
|
|
181
|
-
}
|
|
190
|
+
}
|
|
182
191
|
});
|
|
183
192
|
}
|
|
184
193
|
export const reactionAdded = reactionTrigger('reactionAdded', 'reaction_added', 'Trigger when a reaction is added.');
|
|
@@ -190,15 +199,19 @@ export const channelCreated = defineAppTrigger({
|
|
|
190
199
|
event: 'channel_created',
|
|
191
200
|
input: emptyInput,
|
|
192
201
|
output: eventOutput,
|
|
193
|
-
async run(args) {
|
|
202
|
+
async run (args) {
|
|
194
203
|
return emit(await event(args));
|
|
195
|
-
}
|
|
204
|
+
}
|
|
196
205
|
});
|
|
197
206
|
const commandInput = z.object({
|
|
198
207
|
user,
|
|
199
|
-
commands: z.array(z.string().min(1)).min(1).default([
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
commands: z.array(z.string().min(1)).min(1).default([
|
|
209
|
+
'help'
|
|
210
|
+
]),
|
|
211
|
+
channels: z.array(z.string()).default([]).meta({
|
|
212
|
+
label: 'Channel IDs'
|
|
213
|
+
}),
|
|
214
|
+
ignoreBots: z.boolean().default(true)
|
|
202
215
|
});
|
|
203
216
|
export const channelCommandCreated = defineAppTrigger({
|
|
204
217
|
slug: 'channelCommandCreated',
|
|
@@ -207,21 +220,27 @@ export const channelCommandCreated = defineAppTrigger({
|
|
|
207
220
|
event: 'message',
|
|
208
221
|
input: commandInput,
|
|
209
222
|
output: eventOutput,
|
|
210
|
-
async run(args) {
|
|
223
|
+
async run (args) {
|
|
211
224
|
const value = await event(args);
|
|
212
|
-
if (!value || ![
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
225
|
+
if (!value || ![
|
|
226
|
+
'channel',
|
|
227
|
+
'group'
|
|
228
|
+
].includes(String(field(value, 'channel_type')))) return [];
|
|
229
|
+
if (args.input.channels.length && !args.input.channels.includes(String(field(value, 'channel')))) {
|
|
216
230
|
return [];
|
|
217
231
|
}
|
|
218
|
-
if (args.input.ignoreBots && field(value, 'bot_id'))
|
|
219
|
-
return [];
|
|
232
|
+
if (args.input.ignoreBots && field(value, 'bot_id')) return [];
|
|
220
233
|
const parsed = command(field(value, 'text'), args.input.user, args.input.commands);
|
|
221
|
-
return parsed ? emit({
|
|
222
|
-
|
|
234
|
+
return parsed ? emit({
|
|
235
|
+
...value,
|
|
236
|
+
parsed_command: parsed
|
|
237
|
+
}) : [];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const directMentionInput = z.object({
|
|
241
|
+
user,
|
|
242
|
+
...selfFilters
|
|
223
243
|
});
|
|
224
|
-
const directMentionInput = z.object({ user, ...selfFilters });
|
|
225
244
|
export const directMentionCreated = defineAppTrigger({
|
|
226
245
|
slug: 'directMentionCreated',
|
|
227
246
|
description: 'Trigger when a selected user is mentioned in a direct message.',
|
|
@@ -229,21 +248,21 @@ export const directMentionCreated = defineAppTrigger({
|
|
|
229
248
|
event: 'message',
|
|
230
249
|
input: directMentionInput,
|
|
231
250
|
output: eventOutput,
|
|
232
|
-
async run(args) {
|
|
251
|
+
async run (args) {
|
|
233
252
|
const value = await event(args);
|
|
234
|
-
if (!value || field(value, 'channel_type') !== 'im')
|
|
235
|
-
|
|
236
|
-
if (args.input.
|
|
237
|
-
return [];
|
|
238
|
-
if (args.input.ignoreSelfMessages && field(value, 'user') === (await selfUser(args.client))) {
|
|
253
|
+
if (!value || field(value, 'channel_type') !== 'im') return [];
|
|
254
|
+
if (args.input.ignoreBots && field(value, 'bot_id')) return [];
|
|
255
|
+
if (args.input.ignoreSelfMessages && field(value, 'user') === await selfUser(args.client)) {
|
|
239
256
|
return [];
|
|
240
257
|
}
|
|
241
258
|
return String(field(value, 'text') ?? '').includes(`<@${args.input.user}>`) ? emit(value) : [];
|
|
242
|
-
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
const directCommandInput = commandInput.omit({
|
|
262
|
+
channels: true
|
|
263
|
+
}).extend({
|
|
264
|
+
ignoreSelfMessages: z.boolean().default(false)
|
|
243
265
|
});
|
|
244
|
-
const directCommandInput = commandInput
|
|
245
|
-
.omit({ channels: true })
|
|
246
|
-
.extend({ ignoreSelfMessages: z.boolean().default(false) });
|
|
247
266
|
export const directCommandCreated = defineAppTrigger({
|
|
248
267
|
slug: 'directCommandCreated',
|
|
249
268
|
description: 'Trigger for a configured bot command in a direct message.',
|
|
@@ -251,18 +270,19 @@ export const directCommandCreated = defineAppTrigger({
|
|
|
251
270
|
event: 'message',
|
|
252
271
|
input: directCommandInput,
|
|
253
272
|
output: eventOutput,
|
|
254
|
-
async run(args) {
|
|
273
|
+
async run (args) {
|
|
255
274
|
const value = await event(args);
|
|
256
|
-
if (!value || field(value, 'channel_type') !== 'im')
|
|
257
|
-
|
|
258
|
-
if (args.input.
|
|
259
|
-
return [];
|
|
260
|
-
if (args.input.ignoreSelfMessages && field(value, 'user') === (await selfUser(args.client))) {
|
|
275
|
+
if (!value || field(value, 'channel_type') !== 'im') return [];
|
|
276
|
+
if (args.input.ignoreBots && field(value, 'bot_id')) return [];
|
|
277
|
+
if (args.input.ignoreSelfMessages && field(value, 'user') === await selfUser(args.client)) {
|
|
261
278
|
return [];
|
|
262
279
|
}
|
|
263
280
|
const parsed = command(field(value, 'text'), args.input.user, args.input.commands);
|
|
264
|
-
return parsed ? emit({
|
|
265
|
-
|
|
281
|
+
return parsed ? emit({
|
|
282
|
+
...value,
|
|
283
|
+
parsed_command: parsed
|
|
284
|
+
}) : [];
|
|
285
|
+
}
|
|
266
286
|
});
|
|
267
287
|
export const userJoined = defineAppTrigger({
|
|
268
288
|
slug: 'userJoined',
|
|
@@ -271,13 +291,12 @@ export const userJoined = defineAppTrigger({
|
|
|
271
291
|
event: 'team_join',
|
|
272
292
|
input: emptyInput,
|
|
273
293
|
output: eventOutput,
|
|
274
|
-
async run(args) {
|
|
294
|
+
async run (args) {
|
|
275
295
|
const value = await event(args);
|
|
276
|
-
if (!value || field(value, 'type') !== 'team_join')
|
|
277
|
-
return [];
|
|
296
|
+
if (!value || field(value, 'type') !== 'team_join') return [];
|
|
278
297
|
const joined = eventMap(field(value, 'user'));
|
|
279
298
|
return emit(joined);
|
|
280
|
-
}
|
|
299
|
+
}
|
|
281
300
|
});
|
|
282
301
|
export const messageSaved = defineAppTrigger({
|
|
283
302
|
slug: 'messageSaved',
|
|
@@ -286,13 +305,12 @@ export const messageSaved = defineAppTrigger({
|
|
|
286
305
|
event: 'star_added',
|
|
287
306
|
input: emptyInput,
|
|
288
307
|
output: eventOutput,
|
|
289
|
-
async run(args) {
|
|
308
|
+
async run (args) {
|
|
290
309
|
const value = await event(args);
|
|
291
|
-
if (!value || field(value, 'type') !== 'star_added')
|
|
292
|
-
return [];
|
|
310
|
+
if (!value || field(value, 'type') !== 'star_added') return [];
|
|
293
311
|
const item = eventMap(field(value, 'item'));
|
|
294
312
|
return item && field(item, 'type') === 'message' ? emit(item) : [];
|
|
295
|
-
}
|
|
313
|
+
}
|
|
296
314
|
});
|
|
297
315
|
export const customEmojiAdded = defineAppTrigger({
|
|
298
316
|
slug: 'customEmojiAdded',
|
|
@@ -301,16 +319,22 @@ export const customEmojiAdded = defineAppTrigger({
|
|
|
301
319
|
event: 'emoji_changed',
|
|
302
320
|
input: emptyInput,
|
|
303
321
|
output: eventOutput,
|
|
304
|
-
async run(args) {
|
|
322
|
+
async run (args) {
|
|
305
323
|
const value = await event(args);
|
|
306
324
|
if (!value || field(value, 'type') !== 'emoji_changed' || field(value, 'subtype') !== 'add') {
|
|
307
325
|
return [];
|
|
308
326
|
}
|
|
309
|
-
return emit({
|
|
310
|
-
|
|
327
|
+
return emit({
|
|
328
|
+
id: field(value, 'name'),
|
|
329
|
+
image: field(value, 'value')
|
|
330
|
+
});
|
|
331
|
+
}
|
|
311
332
|
});
|
|
312
333
|
const modalInput = z.object({
|
|
313
|
-
interactionType: z.enum([
|
|
334
|
+
interactionType: z.enum([
|
|
335
|
+
'view_submission',
|
|
336
|
+
'view_closed'
|
|
337
|
+
]).default('view_submission')
|
|
314
338
|
});
|
|
315
339
|
export const modalInteraction = defineAppTrigger({
|
|
316
340
|
slug: 'modalInteraction',
|
|
@@ -319,13 +343,12 @@ export const modalInteraction = defineAppTrigger({
|
|
|
319
343
|
event: 'modal_interaction',
|
|
320
344
|
input: modalInput,
|
|
321
345
|
output: eventOutput,
|
|
322
|
-
async run(args) {
|
|
346
|
+
async run (args) {
|
|
323
347
|
const value = await event(args);
|
|
324
|
-
if (!value || field(value, 'type') !== args.input.interactionType)
|
|
325
|
-
|
|
326
|
-
const safe = Object.fromEntries(Object.entries(value).filter(([key]) => key !== 'token'));
|
|
348
|
+
if (!value || field(value, 'type') !== args.input.interactionType) return [];
|
|
349
|
+
const safe = Object.fromEntries(Object.entries(value).filter(([key])=>key !== 'token'));
|
|
327
350
|
return emit(safe);
|
|
328
|
-
}
|
|
351
|
+
}
|
|
329
352
|
});
|
|
330
353
|
export const slackTriggers = [
|
|
331
354
|
messageCreated,
|
|
@@ -341,6 +364,7 @@ export const slackTriggers = [
|
|
|
341
364
|
userJoined,
|
|
342
365
|
messageSaved,
|
|
343
366
|
customEmojiAdded,
|
|
344
|
-
modalInteraction
|
|
367
|
+
modalInteraction
|
|
345
368
|
];
|
|
369
|
+
|
|
346
370
|
//# sourceMappingURL=triggers.js.map
|