import {z} from 'zod' export type GetApiTeamMessagingV1TasksTaskIdArgs = {taskId: string}; export type GetApiTeamMessagingV1TasksTaskIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const taskRecurrenceInfo = z.object({schedule: z.enum(["None", "Daily", "Weekdays", "Weekly", "Monthly", "Yearly"]).optional(), endingCondition: z.enum(["None", "Count", "Date"]).optional(), endingAfter: z.number().int().gte(1).lte(10).optional(), endingOn: z.string().optional()}); export const taskAttachment = z.object({id: z.string().optional(), type: z.literal("File").optional(), name: z.string().optional(), contentUri: z.string().optional()}); export const tMTaskInfo = z.object({id: z.string().optional(), creationTime: z.string().optional(), lastModifiedTime: z.string().optional(), type: z.literal("Task").optional(), creator: z.object({id: z.string().optional()}).optional(), chatIds: z.array(z.string()).optional(), status: z.enum(["Pending", "InProgress", "Completed"]).optional(), subject: z.string().optional(), assignees: z.array(z.object({id: z.string().optional(), status: z.enum(["Pending", "Completed"]).optional()})).optional(), completenessCondition: z.enum(["Simple", "AllAssignees", "Percentage"]).optional(), completenessPercentage: z.number().int().gte(0).lte(100).optional(), startDate: z.string().optional(), dueDate: z.string().optional(), color: z.enum(["Black", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Magenta"]).optional(), section: z.string().optional(), description: z.string().optional(), recurrence: taskRecurrenceInfo.optional(), attachments: z.array(taskAttachment).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 }; /** * Get Task * * GET /team-messaging/v1/tasks/{taskId} */ export const getApiTeamMessagingV1TasksTaskId = async (args: GetApiTeamMessagingV1TasksTaskIdArgs, options?: GetApiTeamMessagingV1TasksTaskIdOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/team-messaging/v1/tasks/${encodeURIComponent(String(args.taskId))}${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(tMTaskInfo, await res.json()) };