import {z} from 'zod' export type CreateApiV1ServicesServiceSidSessionsSessionSidParticipantsParticipantSidMessageInteractionsArgs = {ServiceSid: string, SessionSid: string, ParticipantSid: string, body: {Body?: string | undefined, MediaUrl?: Array | undefined}}; export type CreateApiV1ServicesServiceSidSessionsSessionSidParticipantsParticipantSidMessageInteractionsOptions = {baseUrl?: string | undefined, accountSidAuthToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const messageInteractionEnumType = z.enum(["message", "voice", "unknown"]); export const messageInteractionEnumResourceStatus = z.enum(["accepted", "answered", "busy", "canceled", "completed", "deleted", "delivered", "delivery-unknown", "failed", "in-progress", "initiated", "no-answer", "queued", "received", "receiving", "ringing", "scheduled", "sending", "sent", "undelivered", "unknown"]); export const proxyV1ServiceSessionParticipantMessageInteraction = z.object({sid: z.string().min(34).max(34).nullable().optional(), session_sid: z.string().min(34).max(34).nullable().optional(), service_sid: z.string().min(34).max(34).nullable().optional(), account_sid: z.string().min(34).max(34).nullable().optional(), data: z.string().nullable().optional(), type: messageInteractionEnumType.optional(), participant_sid: z.string().min(34).max(34).nullable().optional(), inbound_participant_sid: z.string().min(34).max(34).nullable().optional(), inbound_resource_sid: z.string().min(34).max(34).nullable().optional(), inbound_resource_status: messageInteractionEnumResourceStatus.optional(), inbound_resource_type: z.string().nullable().optional(), inbound_resource_url: z.string().nullable().optional(), outbound_participant_sid: z.string().min(34).max(34).nullable().optional(), outbound_resource_sid: z.string().min(34).max(34).nullable().optional(), outbound_resource_status: messageInteractionEnumResourceStatus.optional(), outbound_resource_type: z.string().nullable().optional(), outbound_resource_url: z.string().nullable().optional(), date_created: z.string().nullable().optional(), date_updated: z.string().nullable().optional(), url: z.string().nullable().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 }; /** * Create a new message Interaction to send directly from your system to one [Participant](https://www.twilio.com/docs/proxy/api/participant). The `inbound` properties for the Interaction will always be empty. * * POST /v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions */ export const createApiV1ServicesServiceSidSessionsSessionSidParticipantsParticipantSidMessageInteractions = async (args: CreateApiV1ServicesServiceSidSessionsSessionSidParticipantsParticipantSidMessageInteractionsArgs, options?: CreateApiV1ServicesServiceSidSessionsSessionSidParticipantsParticipantSidMessageInteractionsOptions) => { const {baseUrl = "https://proxy.twilio.com", fetch: fetchFn = fetch, accountSidAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (accountSidAuthToken !== undefined) headers.set('authorization', `Basic ${btoa(`${accountSidAuthToken.username}:${accountSidAuthToken.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Services/${encodeURIComponent(String(args.ServiceSid))}/Sessions/${encodeURIComponent(String(args.SessionSid))}/Participants/${encodeURIComponent(String(args.ParticipantSid))}/MessageInteractions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(proxyV1ServiceSessionParticipantMessageInteraction, await res.json()) };