MCPcopy Create free account
hub / github.com/ShipSecAI/studio / execute

Function execute

worker/src/components/notification/slack.ts:171–257  ·  view source on GitHub ↗
({ inputs, params }, context)

Source from the content-addressed store, hash-verified

169 return { inputs: inputs(inputShape) };
170 },
171 async execute({ inputs, params }, context) {
172 const { text, blocks, channel, thread_ts, slackToken, webhookUrl } = inputs as Record<
173 string,
174 unknown
175 >;
176 const { authType } = params;
177 const contextData = { ...params, ...inputs };
178
179 // 1. Interpolate text
180 const finalText = interpolate(text as string, contextData);
181
182 // 2. Interpolate and parse blocks if it's a template string
183 let finalBlocks = blocks;
184 if (typeof blocks === 'string') {
185 try {
186 const interpolated = interpolate(blocks, contextData);
187 finalBlocks = JSON.parse(interpolated);
188 } catch (_e) {
189 context.logger.warn(
190 '[Slack] Failed to parse blocks JSON after interpolation, sending as raw string',
191 );
192 finalBlocks = undefined;
193 }
194 } else if (Array.isArray(blocks)) {
195 // If it's already an object, we'd need a deep interpolation,
196 // but typically users will pass a JSON string template for simplicity.
197 // For now, let's stringify and interpolate to support variables in objects too!
198 const str = JSON.stringify(blocks);
199 const interpolated = interpolate(str, contextData);
200 finalBlocks = JSON.parse(interpolated);
201 }
202
203 context.logger.info(`[Slack] Sending message to ${authType}...`);
204
205 const body: any = {
206 text: finalText,
207 blocks: finalBlocks,
208 };
209
210 if (authType === 'webhook') {
211 if (!webhookUrl) {
212 throw new ConfigurationError('Slack Webhook URL is required.', {
213 configKey: 'webhookUrl',
214 });
215 }
216 const url = typeof webhookUrl === 'string' ? webhookUrl : String(webhookUrl);
217 const response = await context.http.fetch(url, {
218 method: 'POST',
219 headers: { 'Content-Type': 'application/json' },
220 body: JSON.stringify(body),
221 });
222 if (!response.ok) {
223 const responseBody = await response.text();
224 throw fromHttpResponse(response, responseBody);
225 }
226 return outputSchema.parse({ ok: true });
227 } else {
228 if (!slackToken) {

Callers

nothing calls this directly

Calls 6

fromHttpResponseFunction · 0.90
parseMethod · 0.80
warnMethod · 0.80
infoMethod · 0.80
fetchMethod · 0.80
interpolateFunction · 0.70

Tested by

no test coverage detected