-
Notifications
You must be signed in to change notification settings - Fork 621
feat: add support siwa feedback system for closed support tickets #7916
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 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
123 changes: 123 additions & 0 deletions
123
apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/support/apis/feedback.ts
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,123 @@ | ||
| "use server"; | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type FeedbackSubmitResult = { success: true } | { error: string }; | ||
| type FeedbackStatusResult = { hasFeedback: boolean } | { error: string }; | ||
|
|
||
| export async function submitSupportFeedback({ | ||
| rating, | ||
| feedback, | ||
| ticketId, | ||
| }: { | ||
| rating: number; | ||
| feedback?: string; | ||
| ticketId: string; | ||
| }): Promise<FeedbackSubmitResult> { | ||
| try { | ||
| // Fail fast on missing configuration | ||
| const siwaUrl = | ||
| process.env.SIWA_URL ?? process.env.NEXT_PUBLIC_SIWA_URL ?? ""; | ||
|
|
||
| if (!siwaUrl) { | ||
| throw new Error("SIWA URL not configured"); | ||
| } | ||
|
|
||
| const apiKey = process.env.SERVICE_AUTH_KEY_SIWA; | ||
|
|
||
| if (!apiKey) { | ||
| throw new Error("SERVICE_AUTH_KEY_SIWA not configured"); | ||
| } | ||
GiselleNessi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Basic input validation/normalization | ||
| if (!ticketId?.trim()) { | ||
| return { error: "ticketId is required." }; | ||
| } | ||
|
|
||
| if (!Number.isInteger(rating) || rating < 1 || rating > 5) { | ||
| return { error: "Rating must be an integer between 1 and 5." }; | ||
| } | ||
|
|
||
| const normalizedFeedback = (feedback ?? "") | ||
| .toString() | ||
| .trim() | ||
| .slice(0, 1000); // hard cap length | ||
|
|
||
| const payload = { | ||
| rating: rating.toString(), | ||
| feedback: normalizedFeedback, | ||
| ticket_id: ticketId, | ||
| }; | ||
|
|
||
| const ac = new AbortController(); | ||
| const t = setTimeout(() => ac.abort(), 10_000); | ||
| const response = await fetch(`${siwaUrl}/v1/csat/saveCSATFeedback`, { | ||
| method: "POST", | ||
| cache: "no-store", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-service-api-key": apiKey, | ||
| }, | ||
| body: JSON.stringify(payload), | ||
| signal: ac.signal, | ||
| }).finally(() => clearTimeout(t)); | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text(); | ||
| return { error: `API Server error: ${response.status} - ${errorText}` }; | ||
| } | ||
|
|
||
| return { success: true }; | ||
| } catch (error) { | ||
| console.error("Feedback submission error:", error); | ||
| return { error: "Internal server error" }; | ||
| } | ||
| } | ||
|
|
||
| export async function checkFeedbackStatus( | ||
| ticketId: string, | ||
| ): Promise<FeedbackStatusResult> { | ||
| try { | ||
| // Basic input validation | ||
| if (!ticketId?.trim()) { | ||
| return { error: "ticketId is required." }; | ||
| } | ||
|
|
||
| // Fail fast on missing configuration | ||
| const siwaUrl = | ||
| process.env.SIWA_URL ?? process.env.NEXT_PUBLIC_SIWA_URL ?? ""; | ||
|
|
||
| if (!siwaUrl) { | ||
| throw new Error("SIWA URL not configured"); | ||
| } | ||
|
|
||
| const apiKey = process.env.SERVICE_AUTH_KEY_SIWA; | ||
|
|
||
| if (!apiKey) { | ||
| throw new Error("SERVICE_AUTH_KEY_SIWA not configured"); | ||
| } | ||
|
|
||
| const fullUrl = `${siwaUrl}/v1/csat/getCSATFeedback?ticket_id=${encodeURIComponent(ticketId)}`; | ||
|
|
||
| const ac = new AbortController(); | ||
| const t = setTimeout(() => ac.abort(), 10_000); | ||
| const response = await fetch(fullUrl, { | ||
| method: "GET", | ||
| cache: "no-store", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-service-api-key": apiKey, | ||
| }, | ||
| signal: ac.signal, | ||
| }).finally(() => clearTimeout(t)); | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text(); | ||
| return { error: `API Server error: ${response.status} - ${errorText}` }; | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| return { hasFeedback: data.has_feedback }; | ||
| } catch (error) { | ||
| console.error("Feedback status check error:", error); | ||
| return { error: "Internal server error" }; | ||
| } | ||
| } | ||
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.