import { BaseEvent , BotonicEvent , BotonicMessageEvent , ConnectionEventStatuses , EventTypes , User , } from '@botonic/core' ; import { ulid } from 'ulid' ; export const ID_FROM_CHANNEL = '1234' ; export function initChannelInformation ( { idFromChannel , channel , } ) { return { idFromChannel : idFromChannel || ID_FROM_CHANNEL , channel } ; } export function initBaseEvent ( user , eventType ) { const { idFromChannel , channel } = user ; return { userId : user . id , eventId : ulid ( ) , createdAt : new Date ( ) . toISOString ( ) , eventType , ... initChannelInformation ( { idFromChannel , channel } ) , } ; } type ConnectionEventArgs = { user : User ; status : ConnectionEventStatuses ; } ; export function createConnectionEvent ( args ) { const { user , status } = args ; return { ... initBaseEvent ( user , EventTypes . CONNECTION ) , status , } as BotonicEvent ; } type BotonicMessageEventArgs = { user : User ; properties : Partial < BotonicMessageEvent > ; } ; export function createMessageEvent ( args ) { const { user , properties } = args ; return { ... properties , ... initBaseEvent ( user , EventTypes . MESSAGE ) , } as BotonicEvent ; } type IntegrationEventArgs = { user : User ; details : any ; } ; export function createIntegrationEvent ( eventType , args ) { const { user , details } = args ; return { ... initBaseEvent ( user , eventType ) , details } as BotonicEvent ; } type WebchatActionEventArgs = { user : User ; action : string ; properties : any ; } ; export function createWebchatActionEvent ( args ) { const { user , properties , action } = args ; const { idFromChannel , channel } = user ; return { ... initChannelInformation ( { idFromChannel , channel } ) , ... properties , action , } as BotonicEvent ; }