Class: CommandTower::Services::Messaging::Communications::Produce

Inherits:
ApplicationService show all
Defined in:
app/services/command_tower/services/messaging/communications/produce.rb

Overview

Shared multi-host produce adapter: resolve recipient → Messaging.accept → ServiceResult. Hosts supply platform_enabled_channels (deployment policy). Does not own catalog content or product workflows.

Constant Summary

Constants inherited from CommandTower::ServiceBase

CommandTower::ServiceBase::ON_ARGUMENT_VALIDATION

Instance Method Summary collapse

Methods inherited from ApplicationService

call, inherited

Methods included from Transactional

#fail_transaction!, #transaction

Methods inherited from CommandTower::ServiceBase

#command_tower_lifecycle, inherited, #internal_validate, #service_lifecycle_error_codes, #service_lifecycle_log_level, #validate!

Methods included from Logging::LifecycleDeclaration

included

Methods included from Execution::ContextAccess

#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event

Methods included from ArgumentValidation

included

Methods included from CommandTower::ServiceLogging

included

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/services/command_tower/services/messaging/communications/produce.rb', line 19

def call
  recipient_result = CommandTower::Services::Messaging::Recipients.call(user: user)
  unless recipient_result.success?
    context.fail!(application_error: recipient_result.errors.first)
    return
  end

  accept_result = CommandTower::Messaging.accept(
    recipient_id: recipient_result.data[:recipient_id],
    notification_type_key:,
    host_event_identity:,
    title:,
    body:,
    metadata:,
    preference_state: nil,
    platform_enabled_channels:,
    message_overrides: nil,
  )

  # Use communication_status — ServiceResult strips Interactor reserved :status.
  context.communication_id = accept_result.communication_id
  context.destination_plan_id = accept_result.destination_plan_id
  context.recipient_id = accept_result.recipient_id
  context.notification_type_key = accept_result.notification_type_key
  context.host_event_identity = accept_result.host_event_identity
  context.communication_status = accept_result.status
  context.idempotent_replay = accept_result.idempotent_replay
  context.inbox_item_id = accept_result.inbox_item_id
  context.selected_channels = accept_result.selected_channels
  context.inbox_selected = accept_result.inbox_selected
rescue CommandTower::Messaging::Accept::ValidationError => error
  context.fail!(application_error: CommandTower::Errors::ValidationError.new(details: { messaging: error.message }))
rescue CommandTower::Messaging::Accept::UnknownTypeError,
       CommandTower::Messaging::Accept::InvalidPreferenceError,
       CommandTower::Messaging::Accept::IllegalOverrideError,
       CommandTower::Messaging::Accept::ImpossibleMandatoryPlanError
  context.fail!(application_error: CommandTower::Errors::Messaging::AcceptRejectedError.new)
rescue CommandTower::Messaging::Accept::IdempotencyConflictError
  context.fail!(application_error: CommandTower::Errors::Messaging::IdempotencyConflictError.new)
rescue CommandTower::Messaging::Accept::PersistenceError,
       CommandTower::Messaging::Accept::InvariantError
  context.fail!(application_error: CommandTower::Errors::InternalError.new)
rescue CommandTower::Messaging::Accept::Error
  context.fail!(application_error: CommandTower::Errors::InternalError.new)
end