-
Notifications
You must be signed in to change notification settings - Fork 564
[dashboard] - support in dashboard #7608
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
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,143 @@ | ||
"use server"; | ||
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "@/constants/public-envs"; | ||
import type { SupportTicket } from "../../app/(app)/team/[team_slug]/(team)/~/support/types/tickets"; | ||
import { getAuthToken, getAuthTokenWalletAddress } from "./auth-token"; | ||
|
||
const ESCALATION_FEEDBACK_RATING = 9999; | ||
|
||
export async function createSupportTicket(params: { | ||
message: string; | ||
teamSlug: string; | ||
teamId: string; | ||
title: string; | ||
conversationId?: string; | ||
}): Promise<{ data: SupportTicket } | { error: string }> { | ||
const token = await getAuthToken(); | ||
if (!token) { | ||
return { error: "No auth token available" }; | ||
} | ||
|
||
try { | ||
const walletAddress = await getAuthTokenWalletAddress(); | ||
|
||
const encodedTeamSlug = encodeURIComponent(params.teamSlug); | ||
const apiUrl = `${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/teams/${encodedTeamSlug}/support-conversations`; | ||
|
||
// Build the payload for creating a conversation | ||
// If the message does not already include wallet address, prepend it | ||
let message = params.message; | ||
if (!message.includes("Wallet address:")) { | ||
message = `Wallet address: ${String(walletAddress || "-")}\n${message}`; | ||
} | ||
|
||
const payload = { | ||
markdown: message.trim(), | ||
title: params.title, | ||
}; | ||
|
||
const body = JSON.stringify(payload); | ||
const headers: Record<string, string> = { | ||
Accept: "application/json", | ||
Authorization: `Bearer ${token}`, | ||
"Content-Type": "application/json", | ||
"Accept-Encoding": "identity", | ||
}; | ||
|
||
const response = await fetch(apiUrl, { | ||
body, | ||
headers, | ||
method: "POST", | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorText = await response.text(); | ||
return { error: `API Server error: ${response.status} - ${errorText}` }; | ||
} | ||
|
||
const createdConversation: SupportTicket = await response.json(); | ||
|
||
// Escalate to SIWA feedback endpoint if conversationId is provided | ||
if (params.conversationId) { | ||
try { | ||
const siwaUrl = process.env.NEXT_PUBLIC_SIWA_URL; | ||
if (siwaUrl) { | ||
await fetch(`${siwaUrl}/v1/chat/feedback`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${token}`, | ||
...(params.teamId ? { "x-team-id": params.teamId } : {}), | ||
}, | ||
body: JSON.stringify({ | ||
conversationId: params.conversationId, | ||
feedbackRating: ESCALATION_FEEDBACK_RATING, | ||
}), | ||
}); | ||
} | ||
} catch (error) { | ||
// Log error but don't fail the ticket creation | ||
console.error("Failed to escalate to SIWA feedback:", error); | ||
} | ||
} | ||
|
||
return { data: createdConversation }; | ||
} catch (error) { | ||
return { | ||
error: `Failed to create support ticket: ${error instanceof Error ? error.message : "Unknown error"}`, | ||
}; | ||
} | ||
} | ||
|
||
export async function sendMessageToTicket(request: { | ||
ticketId: string; | ||
teamSlug: string; | ||
teamId: string; | ||
message: string; | ||
}): Promise<{ success: true } | { error: string }> { | ||
if (!request.ticketId || !request.teamSlug) { | ||
return { error: "Ticket ID and team slug are required" }; | ||
} | ||
|
||
const token = await getAuthToken(); | ||
if (!token) { | ||
return { error: "No auth token available" }; | ||
} | ||
|
||
try { | ||
const encodedTeamSlug = encodeURIComponent(request.teamSlug); | ||
const encodedTicketId = encodeURIComponent(request.ticketId); | ||
const apiUrl = `${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/teams/${encodedTeamSlug}/support-conversations/${encodedTicketId}/messages`; | ||
|
||
// Append /unthread send for customer messages to ensure proper routing | ||
const messageWithUnthread = `${request.message.trim()}\n/unthread send`; | ||
const payload = { | ||
markdown: messageWithUnthread, | ||
}; | ||
|
||
const body = JSON.stringify(payload); | ||
const headers: Record<string, string> = { | ||
Accept: "application/json", | ||
Authorization: `Bearer ${token}`, | ||
"Content-Type": "application/json", | ||
"Accept-Encoding": "identity", | ||
...(request.teamId ? { "x-team-id": request.teamId } : {}), | ||
}; | ||
|
||
const response = await fetch(apiUrl, { | ||
body, | ||
headers, | ||
method: "POST", | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorText = await response.text(); | ||
return { error: `API Server error: ${response.status} - ${errorText}` }; | ||
} | ||
|
||
return { success: true }; | ||
} catch (error) { | ||
return { | ||
error: `Failed to send message: ${error instanceof Error ? error.message : "Unknown 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
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.