16 lines
730 B
TypeScript
16 lines
730 B
TypeScript
export type CommissionMessageEvent = {
|
|
messageId: string; ticketId: string; ticketTitle: string; authorId: string;
|
|
authorName: string; text: string | null;
|
|
};
|
|
|
|
export function parseCommissionMessageEvent(value: string): CommissionMessageEvent | null {
|
|
if (!value.startsWith("message:")) return null;
|
|
try {
|
|
const message = JSON.parse(value.slice(8)) as CommissionMessageEvent;
|
|
return typeof message.messageId === "string" && typeof message.ticketId === "string" &&
|
|
typeof message.ticketTitle === "string" && typeof message.authorId === "string" &&
|
|
typeof message.authorName === "string" &&
|
|
(typeof message.text === "string" || message.text === null) ? message : null;
|
|
} catch { return null; }
|
|
}
|