import { z } from "zod" import { defineAction } from "../../../automation/actions" import { getGoogleMeetApi, GOOGLE_MEET_CONFERENCE_RECORD_REFERENCE_SCHEMA, GOOGLE_MEET_PARTICIPANT_NAME_SCHEMA, GOOGLE_MEET_PARTICIPANT_PAGE_SCHEMA, GOOGLE_MEET_PARTICIPANT_SCHEMA, GOOGLE_MEET_PARTICIPANT_SESSION_NAME_SCHEMA, GOOGLE_MEET_PARTICIPANT_SESSION_PAGE_SCHEMA, GOOGLE_MEET_PARTICIPANT_SESSION_SCHEMA, normalizeGoogleMeetConferenceRecordName, normalizeGoogleMeetParticipant, normalizeGoogleMeetParticipantSession, } from "@automate.ax/integration-contracts/google-meet" import { GOOGLE_MEET_READ_REQUIREMENT } from "../lib/scopes" /** Retrieves one participant from a conference record. */ export const getGoogleMeetParticipant = defineAction( "Get Google Meet participant", ) .describe("Gets one participant identity and attendance interval.") .account("google", GOOGLE_MEET_READ_REQUIREMENT) .input( z.object({ /** Full participant resource name returned by Meet. */ participant: GOOGLE_MEET_PARTICIPANT_NAME_SCHEMA, }), ) .output(GOOGLE_MEET_PARTICIPANT_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => { const { data } = await getGoogleMeetApi( account.secret, ).conferenceRecords.participants.get({ name: input.participant }) return normalizeGoogleMeetParticipant(data) }) /** Lists one page of participants in a conference record. */ export const listGoogleMeetParticipants = defineAction( "List Google Meet participants", ) .describe("Lists participant identities and attendance intervals.") .account("google", GOOGLE_MEET_READ_REQUIREMENT) .input( z.object({ /** Conference-record resource name or raw record ID. */ conferenceRecord: GOOGLE_MEET_CONFERENCE_RECORD_REFERENCE_SCHEMA, /** Provider filter over earliest_start_time or latest_end_time. */ filter: z.string().min(1).optional(), /** Maximum participants returned in this page. */ pageSize: z.number().int().min(1).max(250).optional(), /** Token returned by a previous call. */ pageToken: z.string().min(1).optional(), }), ) .output(GOOGLE_MEET_PARTICIPANT_PAGE_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => { const { data } = await getGoogleMeetApi( account.secret, ).conferenceRecords.participants.list({ filter: input.filter, pageSize: input.pageSize, pageToken: input.pageToken, parent: normalizeGoogleMeetConferenceRecordName(input.conferenceRecord), }) return { nextPageToken: data.nextPageToken ?? undefined, participants: (data.participants ?? []).map( normalizeGoogleMeetParticipant, ), totalSize: data.totalSize ?? undefined, } }) /** Retrieves one participant-device join session. */ export const getGoogleMeetParticipantSession = defineAction( "Get Google Meet participant session", ) .describe("Gets timing for one participant-device join session.") .account("google", GOOGLE_MEET_READ_REQUIREMENT) .input( z.object({ /** Full participant-session resource name returned by Meet. */ participantSession: GOOGLE_MEET_PARTICIPANT_SESSION_NAME_SCHEMA, }), ) .output(GOOGLE_MEET_PARTICIPANT_SESSION_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => { const { data } = await getGoogleMeetApi( account.secret, ).conferenceRecords.participants.participantSessions.get({ name: input.participantSession, }) return normalizeGoogleMeetParticipantSession(data) }) /** Lists one page of device sessions for a participant. */ export const listGoogleMeetParticipantSessions = defineAction( "List Google Meet participant sessions", ) .describe("Lists every join session for one conference participant.") .account("google", GOOGLE_MEET_READ_REQUIREMENT) .input( z.object({ /** Provider filter over start_time or end_time. */ filter: z.string().min(1).optional(), /** Maximum sessions returned in this page. */ pageSize: z.number().int().min(1).max(250).optional(), /** Token returned by a previous call. */ pageToken: z.string().min(1).optional(), /** Full participant resource name returned by Meet. */ participant: GOOGLE_MEET_PARTICIPANT_NAME_SCHEMA, }), ) .output(GOOGLE_MEET_PARTICIPANT_SESSION_PAGE_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => { const { data } = await getGoogleMeetApi( account.secret, ).conferenceRecords.participants.participantSessions.list({ filter: input.filter, pageSize: input.pageSize, pageToken: input.pageToken, parent: input.participant, }) return { nextPageToken: data.nextPageToken ?? undefined, participantSessions: (data.participantSessions ?? []).map( normalizeGoogleMeetParticipantSession, ), } })