-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(slack): added ephemeral message send tool, updated ci, updated docs #3278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22347fe
feat(slack): added ephemeral message send tool, updated ci, updated docs
waleedlatif1 85f56e7
added block kit support
waleedlatif1 de63a02
upgrade turborepo
waleedlatif1 b8af0da
added wandConfig for slack block kit
waleedlatif1 08643c4
fix generation type
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { z } from 'zod' | ||
| import { checkInternalAuth } from '@/lib/auth/hybrid' | ||
| import { generateRequestId } from '@/lib/core/utils/request' | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| const logger = createLogger('SlackSendEphemeralAPI') | ||
|
|
||
| const SlackSendEphemeralSchema = z.object({ | ||
| accessToken: z.string().min(1, 'Access token is required'), | ||
| channel: z.string().min(1, 'Channel ID is required'), | ||
| user: z.string().min(1, 'User ID is required'), | ||
| text: z.string().min(1, 'Message text is required'), | ||
| thread_ts: z.string().optional().nullable(), | ||
| }) | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const requestId = generateRequestId() | ||
|
|
||
| try { | ||
| const authResult = await checkInternalAuth(request, { requireWorkflowId: false }) | ||
|
|
||
| if (!authResult.success) { | ||
| logger.warn(`[${requestId}] Unauthorized Slack ephemeral send attempt: ${authResult.error}`) | ||
| return NextResponse.json( | ||
| { | ||
| success: false, | ||
| error: authResult.error || 'Authentication required', | ||
| }, | ||
| { status: 401 } | ||
| ) | ||
| } | ||
|
|
||
| logger.info( | ||
| `[${requestId}] Authenticated Slack ephemeral send request via ${authResult.authType}`, | ||
| { userId: authResult.userId } | ||
| ) | ||
|
|
||
| const body = await request.json() | ||
| const validatedData = SlackSendEphemeralSchema.parse(body) | ||
|
|
||
| logger.info(`[${requestId}] Sending ephemeral message`, { | ||
| channel: validatedData.channel, | ||
| user: validatedData.user, | ||
| threadTs: validatedData.thread_ts ?? undefined, | ||
| }) | ||
|
|
||
| const response = await fetch('https://slack.com/api/chat.postEphemeral', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: `Bearer ${validatedData.accessToken}`, | ||
| }, | ||
| body: JSON.stringify({ | ||
| channel: validatedData.channel, | ||
| user: validatedData.user, | ||
| text: validatedData.text, | ||
| ...(validatedData.thread_ts && { thread_ts: validatedData.thread_ts }), | ||
| }), | ||
| }) | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| if (!data.ok) { | ||
| logger.error(`[${requestId}] Slack API error:`, data.error) | ||
| return NextResponse.json( | ||
| { success: false, error: data.error || 'Failed to send ephemeral message' }, | ||
| { status: 400 } | ||
| ) | ||
| } | ||
|
|
||
| logger.info(`[${requestId}] Ephemeral message sent successfully`) | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| output: { | ||
| messageTs: data.message_ts, | ||
| channel: validatedData.channel, | ||
| }, | ||
| }) | ||
| } catch (error) { | ||
| logger.error(`[${requestId}] Error sending ephemeral message:`, error) | ||
| return NextResponse.json( | ||
| { | ||
| success: false, | ||
| error: error instanceof Error ? error.message : 'Unknown error occurred', | ||
| }, | ||
| { status: 500 } | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.