-
Notifications
You must be signed in to change notification settings - Fork 6
refactor(feedback): extract app builder Slack notifications into modules with thread support #433
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
Open
kilo-code-bot
wants to merge
1
commit into
main
Choose a base branch
from
session/agent_65312df6-235a-4168-ac13-5b1ad7ed32ae
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import 'server-only'; | ||
|
|
||
| import { | ||
| postInternalSlackMessage, | ||
| postInternalSlackThreadReply, | ||
| } from '@/lib/slack/internal-notifications'; | ||
|
|
||
| const FEEDBACK_PREVIEW_LIMIT = 500; | ||
|
|
||
| /** | ||
| * Sends an app builder feedback notification to the internal Kilo Slack channel. | ||
| * If the feedback text exceeds the preview limit, the full text is posted as a thread reply. | ||
| * Fire-and-forget safe — catches and logs all errors. | ||
| */ | ||
| export async function notifyAppBuilderFeedback( | ||
| projectId: string, | ||
| feedbackText: string | ||
| ): Promise<void> { | ||
| const adminLink = `https://app.kilo.ai/admin/app-builder/${projectId}`; | ||
| const trimmedFeedback = feedbackText.trim(); | ||
| const wasTruncated = trimmedFeedback.length > FEEDBACK_PREVIEW_LIMIT; | ||
| const previewText = | ||
| trimmedFeedback.slice(0, FEEDBACK_PREVIEW_LIMIT) + (wasTruncated ? '...' : ''); | ||
|
|
||
| try { | ||
| const ts = await postInternalSlackMessage( | ||
| [ | ||
| { | ||
| type: 'header', | ||
| text: { | ||
| type: 'plain_text', | ||
| text: 'New App Builder feedback :hammer_and_wrench:', | ||
| }, | ||
| }, | ||
| { | ||
| type: 'section', | ||
| text: { type: 'mrkdwn', text: `<${adminLink}|View project>` }, | ||
| }, | ||
| { | ||
| type: 'section', | ||
| text: { type: 'plain_text', text: previewText }, | ||
| }, | ||
| ], | ||
| 'New App Builder feedback' | ||
| ); | ||
|
|
||
| if (wasTruncated && ts) { | ||
| await postInternalSlackThreadReply(ts, trimmedFeedback); | ||
| } | ||
| } catch (error) { | ||
| console.error('[AppBuilderFeedback] Failed to post to Slack', error); | ||
| } | ||
| } |
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,57 @@ | ||
| import 'server-only'; | ||
|
|
||
| import { WebClient } from '@slack/web-api'; | ||
| import type { Block, KnownBlock } from '@slack/web-api'; | ||
| import { SLACK_FEEDBACK_BOT_TOKEN, SLACK_FEEDBACK_CHANNEL_ID } from '@/lib/config.server'; | ||
|
|
||
| function makeClient(): WebClient { | ||
| if (!SLACK_FEEDBACK_BOT_TOKEN) { | ||
| throw new Error('SLACK_FEEDBACK_BOT_TOKEN is not configured'); | ||
| } | ||
| return new WebClient(SLACK_FEEDBACK_BOT_TOKEN); | ||
| } | ||
|
|
||
| /** | ||
| * Posts a message to the internal Kilo Slack feedback channel. | ||
| * Returns the message ts on success (needed for threading), or undefined if not configured. | ||
| * Throws on API errors. | ||
| */ | ||
| export async function postInternalSlackMessage( | ||
| blocks: (Block | KnownBlock)[], | ||
| fallbackText: string | ||
| ): Promise<string | undefined> { | ||
| if (!SLACK_FEEDBACK_BOT_TOKEN || !SLACK_FEEDBACK_CHANNEL_ID) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const client = makeClient(); | ||
| const result = await client.chat.postMessage({ | ||
| channel: SLACK_FEEDBACK_CHANNEL_ID, | ||
| text: fallbackText, | ||
| unfurl_links: false, | ||
| unfurl_media: false, | ||
| blocks, | ||
| }); | ||
|
|
||
| return result.ts; | ||
| } | ||
|
|
||
| /** | ||
| * Posts a thread reply to an existing message in the internal Kilo Slack feedback channel. | ||
| * Throws on API errors. | ||
| */ | ||
| export async function postInternalSlackThreadReply( | ||
| threadTs: string, | ||
| text: string | ||
| ): Promise<void> { | ||
| if (!SLACK_FEEDBACK_BOT_TOKEN || !SLACK_FEEDBACK_CHANNEL_ID) { | ||
| return; | ||
| } | ||
|
|
||
| const client = makeClient(); | ||
| await client.chat.postMessage({ | ||
| channel: SLACK_FEEDBACK_CHANNEL_ID, | ||
| thread_ts: threadTs, | ||
| text, | ||
| }); | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[SUGGESTION]: Dead
.catch()handler —notifyAppBuilderFeedbackalready catches and logs all errors internally (see its try/catch on lines 25–52 ofapp-builder-feedback-slack.ts), so this promise will never reject.You can simplify to a bare call:
Alternatively, if you'd prefer the router to own error logging, remove the try/catch inside
notifyAppBuilderFeedbackand keep this.catch()instead.