Skip to content

Specify createTicket return type for improved type safety #15

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 3 commits into from
Jun 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/services/unthread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ interface SendMessageJSONParams {
onBehalfOf: OnBehalfOfUser;
}

/**
* Ticket creation response
*/
interface CreateTicketResponse {
id: string;
friendlyId: string;
}

/**
* Extracts and formats the customer company name from a Telegram group chat title by removing the bot's company name and handling various separators.
*
Expand Down Expand Up @@ -235,7 +243,7 @@ export async function createCustomer(groupChatName: string): Promise<Customer> {
* @param params - Includes group chat name, customer ID, ticket summary, and user information on whose behalf the ticket is created.
* @returns The created ticket object from Unthread.
*/
export async function createTicket(params: CreateTicketParams): Promise<any> {
export async function createTicket(params: CreateTicketParams): Promise<CreateTicketResponse> {
try {
const { groupChatName, customerId, summary, onBehalfOf } = params;

Expand All @@ -262,7 +270,7 @@ export async function createTicket(params: CreateTicketParams): Promise<any> {
* @returns An object containing the ticket's unique ID and friendly ID
* @throws If the API request fails or returns a non-OK response
*/
async function createTicketJSON(params: CreateTicketJSONParams): Promise<any> {
async function createTicketJSON(params: CreateTicketJSONParams): Promise<CreateTicketResponse> {
const { title, summary, customerId, onBehalfOf } = params;

const payload = {
Expand All @@ -289,7 +297,7 @@ async function createTicketJSON(params: CreateTicketJSONParams): Promise<any> {
throw new Error(`Failed to create ticket: ${response.status} ${errorText}`);
}

const result = await response.json() as { id: string; friendlyId: string };
const result = await response.json() as CreateTicketResponse;

LogEngine.info('Ticket created (JSON)', {
ticketTitle: title,
Expand Down