register_triggers( $triggers ); $this->register_conditions( $conditions ); $this->register_actions( $actions, $conditions, $sender ); } /** * Triggers. * * @param AutomationTriggerRegistry $triggers Registry. */ private function register_triggers( AutomationTriggerRegistry $triggers ): void { $booking = SubjectType::Booking; $cust = SubjectType::Customer; $intent = SubjectType::Intent; $pay = SubjectType::Payment; $event = TriggerKind::Event; $rel = TriggerKind::Relative; $sched = TriggerKind::Schedule; $bg = self::BOOKING_GROUPS; $map = [ [ 'booking.created', 'Booking created', $event, $booking, $bg ], [ 'booking.confirmed', 'Booking confirmed', $event, $booking, $bg ], [ 'booking.rescheduled', 'Booking rescheduled', $event, $booking, $bg ], [ 'booking.cancelled', 'Booking cancelled', $event, $booking, $bg ], [ 'booking.completed', 'Booking completed', $event, $booking, $bg ], [ 'booking.no_show', 'Booking marked no-show', $event, $booking, $bg ], [ 'payment.succeeded', 'Payment succeeded', $event, $pay, [ 'payment', 'order', 'booking', 'customer', 'site' ] ], [ 'payment.failed', 'Payment failed', $event, $pay, [ 'payment', 'order', 'booking', 'customer', 'site' ] ], [ 'payment.refunded', 'Payment refunded', $event, $pay, [ 'payment', 'order', 'booking', 'customer', 'site' ] ], [ 'customer.created', 'Customer created', $event, $cust, [ 'customer', 'site', 'links' ] ], [ 'customer.verified', 'Customer verified', $event, $cust, [ 'customer', 'site', 'links' ] ], [ 'intent.abandoned', 'Booking abandoned', $event, $intent, [ 'order', 'service', 'customer', 'links', 'site' ] ], [ 'review.requested', 'Review requested', $event, $booking, $bg ], [ 'before_booking_start', 'Before booking start', $rel, $booking, $bg ], [ 'after_booking_start', 'After booking start', $rel, $booking, $bg ], [ 'after_booking_end', 'After booking end', $rel, $booking, $bg ], [ 'after_intent_abandoned', 'After intent abandoned', $rel, $intent, [ 'order', 'service', 'customer', 'links', 'site' ] ], [ 'after_last_booking', 'After last booking', $rel, $booking, $bg ], [ 'daily_at', 'Daily at', $sched, $booking, $bg ], [ 'weekly_on', 'Weekly on', $sched, $booking, $bg ], [ 'monthly_on', 'Monthly on', $sched, $booking, $bg ], ]; foreach ( $map as $row ) { $triggers->register( new CatalogueTrigger( (string) $row[0], (string) $row[1], $row[2], $row[3], $row[4] ) ); } } /** * Conditions. * * @param AutomationConditionRegistry $conditions Registry. */ private function register_conditions( AutomationConditionRegistry $conditions ): void { $b = [ SubjectType::Booking ]; $bi = [ SubjectType::Booking, SubjectType::Intent ]; $all = [ SubjectType::Booking, SubjectType::Customer, SubjectType::Intent, SubjectType::Payment ]; $cust = [ SubjectType::Customer, SubjectType::Booking ]; $intent = [ SubjectType::Intent ]; $rows = [ [ 'service_is', 'Service is', $bi, 'service_id', 'eq' ], [ 'service_is_not', 'Service is not', $bi, 'service_id', 'neq' ], [ 'agent_is', 'Agent is', $b, 'agent_id', 'eq' ], [ 'agent_is_not', 'Agent is not', $b, 'agent_id', 'neq' ], [ 'location_is', 'Location is', $bi, 'location_id', 'eq' ], [ 'location_is_not', 'Location is not', $bi, 'location_id', 'neq' ], [ 'booking_status_is', 'Booking status is', $b, 'booking_status', 'in' ], [ 'price_greater_than', 'Price greater than', $bi, 'price_minor', 'gt' ], [ 'price_less_than', 'Price less than', $bi, 'price_minor', 'lt' ], [ 'customer_is_new', 'Customer is new', $cust, 'is_new_customer', 'truthy' ], [ 'customer_is_returning', 'Customer is returning', $cust, 'is_new_customer', 'falsy' ], [ 'customer_booking_count', 'Customer booking count', $cust, 'booking_count', 'gte' ], [ 'customer_no_show_count', 'Customer no-show count', $cust, 'no_show_count', 'gte' ], [ 'day_of_week', 'Day of week', $b, 'day_of_week', 'in' ], [ 'time_of_day', 'Time of day', $b, 'time_of_day_minutes', 'gte' ], [ 'lead_time_greater_than', 'Lead time greater than', $b, 'lead_time_minutes', 'gt' ], [ 'lead_time_less_than', 'Lead time less than', $b, 'lead_time_minutes', 'lt' ], [ 'has_coupon', 'Has coupon', $bi, 'has_coupon', 'truthy' ], [ 'payment_status', 'Payment status', [ SubjectType::Booking, SubjectType::Payment ], 'payment_status', 'eq' ], [ 'custom_field_equals', 'Custom field equals', $all, 'custom_field', 'eq' ], [ 'marketing_consent_given', 'Marketing consent given', $cust, 'marketing_consent', 'truthy' ], [ 'details_step_reached', 'Details step reached', $intent, 'details_step_reached', 'truthy' ], ]; foreach ( $rows as $row ) { $conditions->register( new PredicateCondition( (string) $row[0], (string) $row[1], $row[2], (string) $row[3], (string) $row[4] ) ); } } /** * Actions. * * @param AutomationActionRegistry $actions Registry. * @param AutomationConditionRegistry $conditions Conditions for if-gates. */ private function register_actions( AutomationActionRegistry $actions, AutomationConditionRegistry $conditions, ?AutomationNotificationSender $sender = null, ): void { $all = [ SubjectType::Booking, SubjectType::Customer, SubjectType::Intent, SubjectType::Payment ]; $book = [ SubjectType::Booking ]; $cust = [ SubjectType::Customer, SubjectType::Booking ]; $actions->register( new CoreAutomationAction( 'send_email', 'Send email', $all, true ) ); $actions->register( new CoreAutomationAction( 'send_notification_template', 'Send notification template', $all, true, false, false, $sender ) ); $actions->register( new CoreAutomationAction( 'change_booking_status', 'Change booking status', $book, false, true ) ); $actions->register( new CoreAutomationAction( 'add_internal_note', 'Add internal note', $book ) ); $actions->register( new CoreAutomationAction( 'add_customer_tag', 'Add customer tag', $cust ) ); $actions->register( new HttpIntegrationAction() ); $actions->register( new CoreAutomationAction( 'log_activity', 'Log activity', $all ) ); $actions->register( new CoreAutomationAction( 'wait', 'Wait', $all ) ); $actions->register( new IfConditionAction( $conditions ) ); $actions->register( new GotoAction() ); $actions->register( new FlowLayoutAction() ); } }