export type MessagePatchRequest = {text: string}; export type PatchApiV2MessagesMessageIdArgs = {'X-Signature'?: string | undefined, 'X-Timestamp'?: number | undefined, messageId: string, body: MessagePatchRequest}; export type PatchApiV2MessagesMessageIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, hmacSignature?: string | undefined, fetch?: typeof fetch | undefined}; /** * Edit a message * * PATCH /v2/messages/{messageId} * * Also accepts auth: oauth2ClientCredentials */ export const patchApiV2MessagesMessageId = async (args: PatchApiV2MessagesMessageIdArgs, options?: PatchApiV2MessagesMessageIdOptions) => { const {baseUrl = "https://api.zenzap.co", fetch: fetchFn = fetch, bearerAuth, hmacSignature} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Signature'] != null) headers.set("X-Signature", String(args['X-Signature'])) if (args['X-Timestamp'] != null) headers.set("X-Timestamp", String(args['X-Timestamp'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) if (hmacSignature !== undefined) headers.set("X-Signature", hmacSignature) const url = `${baseUrl.replace(/\/+$/, '')}/v2/messages/${encodeURIComponent(String(args.messageId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };