mirror of
https://github.com/FoggedLens/deflock.git
synced 2026-08-18 00:17:13 +02:00
commit for the purpose of working on another machine
This commit is contained in:
@@ -23,11 +23,12 @@ export const ContactMessageBodySchema = Type.Object({
|
||||
subject: Type.String({ minLength: 1 }),
|
||||
message: Type.String({ minLength: 1 }),
|
||||
turnstileToken: Type.String({ minLength: 1 }),
|
||||
aiScreeningOptOut: Type.Optional(Type.Boolean({ default: false })),
|
||||
});
|
||||
|
||||
export type ContactMessageBody = Static<typeof ContactMessageBodySchema>;
|
||||
|
||||
const TOPIC_GROUP_MAP: Record<ContactTopic, string> = {
|
||||
export const TOPIC_GROUP_MAP: Record<ContactTopic, string> = {
|
||||
'website-support': 'Website Support',
|
||||
'app-support': 'App Support',
|
||||
'local-groups': 'Local Groups',
|
||||
@@ -77,7 +78,7 @@ export class ZammadClient {
|
||||
return user.id;
|
||||
}
|
||||
|
||||
async createTicket(payload: CreateTicketPayload): Promise<void> {
|
||||
async createTicket(payload: CreateTicketPayload): Promise<{ id: number }> {
|
||||
const { name, email, topic, subject, message } = payload;
|
||||
const group = TOPIC_GROUP_MAP[topic];
|
||||
|
||||
@@ -86,7 +87,7 @@ export class ZammadClient {
|
||||
const body = JSON.stringify({
|
||||
title: subject,
|
||||
group,
|
||||
priority: topic === 'media' ? '3 high' : '2 normal',
|
||||
priority: '2 normal',
|
||||
customer_id: customerId,
|
||||
article: {
|
||||
subject,
|
||||
@@ -111,5 +112,110 @@ export class ZammadClient {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad ticket creation failed: ${response.status} ${text}`);
|
||||
}
|
||||
const ticket = await response.json() as { id: number };
|
||||
return { id: ticket.id };
|
||||
}
|
||||
|
||||
async getTicket(ticketId: number): Promise<{ id: number; title: string; group: string; customer_id: number }> {
|
||||
const response = await fetch(`${ZAMMAD_URL}/api/v1/tickets/${ticketId}`, {
|
||||
headers: { 'Authorization': `Token token=${ZAMMAD_TOKEN}` },
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad ticket fetch failed: ${response.status} ${text}`);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async getTicketArticles(ticketId: number): Promise<Array<{ body: string; content_type: string; from: string; to: string; cc: string; sender: string }>> {
|
||||
const response = await fetch(`${ZAMMAD_URL}/api/v1/ticket_articles/by_ticket/${ticketId}`, {
|
||||
headers: { 'Authorization': `Token token=${ZAMMAD_TOKEN}` },
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad ticket articles fetch failed: ${response.status} ${text}`);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async getUser(userId: number): Promise<{ email: string }> {
|
||||
const response = await fetch(`${ZAMMAD_URL}/api/v1/users/${userId}`, {
|
||||
headers: { 'Authorization': `Token token=${ZAMMAD_TOKEN}` },
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad user fetch failed: ${response.status} ${text}`);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async addTag(ticketId: number, tag: string): Promise<void> {
|
||||
const response = await fetch(`${ZAMMAD_URL}/api/v1/tags/add`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Token token=${ZAMMAD_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
// Zammad's tag-add endpoint reads the tag name from "item", not "tag" — sending the
|
||||
// wrong key leaves it nil server-side and crashes Zammad's own tag_add with an
|
||||
// unhandled NoMethodError (500) rather than a clean validation error.
|
||||
body: JSON.stringify({ item: tag, object: 'Ticket', o_id: ticketId }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad tag creation failed for tag "${tag}" on ticket ${ticketId}: ${response.status} ${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
async addInternalNote(ticketId: number, body: string): Promise<void> {
|
||||
const response = await fetch(`${ZAMMAD_URL}/api/v1/ticket_articles`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Token token=${ZAMMAD_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ ticket_id: ticketId, body, type: 'note', internal: true }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad internal note creation failed: ${response.status} ${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
async setTicketFields(ticketId: number, fields: Record<string, unknown>): Promise<void> {
|
||||
const response = await fetch(`${ZAMMAD_URL}/api/v1/tickets/${ticketId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Authorization': `Token token=${ZAMMAD_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(fields),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad ticket fields update failed: ${response.status} ${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
async upsertSharedDraft(ticketId: number, body: string, recipients: { to: string; cc?: string }): Promise<void> {
|
||||
const response = await fetch(`${ZAMMAD_URL}/api/v1/tickets/${ticketId}/shared_draft`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Authorization': `Token token=${ZAMMAD_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
// TicketSharedDraftZoomController#draft_params only permits nested "new_article" /
|
||||
// "ticket_attributes" keys (params.permit ticket_attributes: {}, new_article: {}) —
|
||||
// top-level body/type/internal are silently stripped by Rails strong params, which
|
||||
// creates/updates the draft with an empty article and no error at all.
|
||||
body: JSON.stringify({
|
||||
new_article: { body, type: 'email', internal: false, to: recipients.to, cc: recipients.cc ?? '' },
|
||||
ticket_attributes: {},
|
||||
}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Zammad shared draft update failed: ${response.status} ${text}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user