import {z} from 'zod' export type GetApiV1InsightsQualityManagementAssessmentsCommentsArgs = {Authorization?: string | undefined, SegmentId?: string | undefined, AgentId?: string | undefined, PageSize?: number | undefined, Page?: number | undefined, PageToken?: string | undefined}; export type GetApiV1InsightsQualityManagementAssessmentsCommentsOptions = {baseUrl?: string | undefined, accountSidAuthToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const flexV1InsightsAssessmentsComment = z.object({account_sid: z.string().min(34).max(34).nullable().optional(), assessment_sid: z.string().min(34).max(34).nullable().optional(), comment: z.unknown(), offset: z.string().nullable().optional(), report: z.boolean().nullable().optional(), weight: z.string().nullable().optional(), agent_id: z.string().nullable().optional(), segment_id: z.string().nullable().optional(), user_name: z.string().nullable().optional(), user_email: z.string().nullable().optional(), timestamp: z.string().nullable().optional(), url: z.string().nullable().optional()}); export const getApiV1InsightsQualityManagementAssessmentsCommentsResponse = z.object({comments: z.array(flexV1InsightsAssessmentsComment).optional(), meta: z.object({first_page_url: z.string().optional(), key: z.string().optional(), next_page_url: z.string().nullable().optional(), page: z.number().int().optional(), page_size: z.number().int().optional(), previous_page_url: z.string().nullable().optional(), url: z.string().optional()}).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * To create a comment assessment for a conversation * * GET /v1/Insights/QualityManagement/Assessments/Comments */ export const getApiV1InsightsQualityManagementAssessmentsComments = async (args: GetApiV1InsightsQualityManagementAssessmentsCommentsArgs, options?: GetApiV1InsightsQualityManagementAssessmentsCommentsOptions) => { const {baseUrl = "https://flex-api.twilio.com", fetch: fetchFn = fetch, accountSidAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.SegmentId != null) query.append("SegmentId", String(args.SegmentId)) if (args.AgentId != null) query.append("AgentId", String(args.AgentId)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageToken != null) query.append("PageToken", String(args.PageToken)) if (accountSidAuthToken !== undefined) headers.set('authorization', `Basic ${btoa(`${accountSidAuthToken.username}:${accountSidAuthToken.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Insights/QualityManagement/Assessments/Comments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1InsightsQualityManagementAssessmentsCommentsResponse, await res.json()) };