import type { IntegrationAccountRequirement, TriggerDefinition } from "../types" const APPOINTMENT_ACCOUNT = highLevelOAuthAccount(["calendars/events.readonly"]) const CAMPAIGN_ACCOUNT = highLevelOAuthAccount(["campaigns.readonly"]) const CONTACT_ACCOUNT = highLevelOAuthAccount(["contacts.readonly"]) const CONVERSATION_ACCOUNT = highLevelOAuthAccount(["conversations.readonly"]) const MESSAGE_ACCOUNT = highLevelOAuthAccount([ "conversations/message.readonly", ]) const OPPORTUNITY_ACCOUNT = highLevelOAuthAccount(["opportunities.readonly"]) const LOCATION_ACCOUNT = highLevelOAuthAccount(["locations.readonly"]) const USER_ACCOUNT = highLevelOAuthAccount(["users.write"]) export const highLevelTriggerDefinitions = { highLevelAppointmentCreated: definition( APPOINTMENT_ACCOUNT, "highlevel.appointment.created", ), highLevelAppointmentDeleted: definition( APPOINTMENT_ACCOUNT, "highlevel.appointment.deleted", ), highLevelAppointmentUpdated: definition( APPOINTMENT_ACCOUNT, "highlevel.appointment.updated", ), highLevelCampaignStatusUpdated: definition( CAMPAIGN_ACCOUNT, "highlevel.campaign.statusUpdated", ), highLevelContactCreated: definition( CONTACT_ACCOUNT, "highlevel.contact.created", ), highLevelContactDeleted: definition( CONTACT_ACCOUNT, "highlevel.contact.deleted", ), highLevelContactDndUpdated: definition( CONTACT_ACCOUNT, "highlevel.contact.dndUpdated", ), highLevelContactTagsUpdated: definition( CONTACT_ACCOUNT, "highlevel.contact.tagsUpdated", ), highLevelContactUpdated: definition( CONTACT_ACCOUNT, "highlevel.contact.updated", ), highLevelConversationUnreadUpdated: definition( CONVERSATION_ACCOUNT, "highlevel.conversation.unreadUpdated", ), highLevelConversationUpdated: definition( CONVERSATION_ACCOUNT, "highlevel.conversation.updated", ), highLevelEvent: definition( highLevelOAuthAccount([ "calendars/events.readonly", "campaigns.readonly", "contacts.readonly", "conversations.readonly", "conversations/message.readonly", "locations.readonly", "opportunities.readonly", "users.readonly", "users.write", ]), "highlevel.event", ), highLevelLocationUpdated: definition( LOCATION_ACCOUNT, "highlevel.location.updated", ), highLevelMessageReceived: definition( MESSAGE_ACCOUNT, "highlevel.message.received", ), highLevelMessageSent: definition(MESSAGE_ACCOUNT, "highlevel.message.sent"), highLevelNoteCreated: definition(CONTACT_ACCOUNT, "highlevel.note.created"), highLevelNoteDeleted: definition(CONTACT_ACCOUNT, "highlevel.note.deleted"), highLevelNoteUpdated: definition(CONTACT_ACCOUNT, "highlevel.note.updated"), highLevelOpportunityAssigneeUpdated: definition( OPPORTUNITY_ACCOUNT, "highlevel.opportunity.assigneeUpdated", ), highLevelOpportunityCreated: definition( OPPORTUNITY_ACCOUNT, "highlevel.opportunity.created", ), highLevelOpportunityDeleted: definition( OPPORTUNITY_ACCOUNT, "highlevel.opportunity.deleted", ), highLevelOpportunityStageUpdated: definition( OPPORTUNITY_ACCOUNT, "highlevel.opportunity.stageUpdated", ), highLevelOpportunityStatusUpdated: definition( OPPORTUNITY_ACCOUNT, "highlevel.opportunity.statusUpdated", ), highLevelOpportunityUpdated: definition( OPPORTUNITY_ACCOUNT, "highlevel.opportunity.updated", ), highLevelOpportunityValueUpdated: definition( OPPORTUNITY_ACCOUNT, "highlevel.opportunity.valueUpdated", ), highLevelTaskCompleted: definition( CONTACT_ACCOUNT, "highlevel.task.completed", ), highLevelTaskCreated: definition(CONTACT_ACCOUNT, "highlevel.task.created"), highLevelTaskDeleted: definition(CONTACT_ACCOUNT, "highlevel.task.deleted"), highLevelUserCreated: definition(USER_ACCOUNT, "highlevel.user.created"), highLevelUserDeleted: definition(USER_ACCOUNT, "highlevel.user.deleted"), highLevelUserUpdated: definition(USER_ACCOUNT, "highlevel.user.updated"), } as const satisfies Record /** * Defines one HighLevel trigger. * * @param account - OAuth account requirement. * @param type - Internal event type. */ function definition( account: IntegrationAccountRequirement<"highlevel">, type: TType, ) { return { account, type } } /** * Builds a HighLevel OAuth trigger requirement. * * @param requiredScopes - Provider scopes required by the webhook family. */ function highLevelOAuthAccount( requiredScopes: readonly string[], ): IntegrationAccountRequirement<"highlevel"> { return { connectionOptions: [{ connectionMethodId: "oauth", requiredScopes }], serviceId: "highlevel", } }