Class: WcoEmail::Api::MessagesController

Inherits:
WcoEmail::ApiController
  • Object
show all
Defined in:
app/controllers/wco_email/api/messages_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_postalObject

2026-03-27 payload is parsed json.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/wco_email/api/messages_controller.rb', line 9

def create_postal
  # puts! params, 'api/messages#create_postal'

  ## save to bucket
  @client ||= Aws::S3::Client.new(::SES_S3_CREDENTIALS)
  @client.put_object({
    body:          params.to_unsafe_h.to_json,
    bucket:      ::SES_S3_BUCKET,
    content_type: 'application/json',
    key:           params['message_id'],
  })

  stub = WcoEmail::MessageStub.create!({
    bucket:   ::SES_S3_BUCKET,
    format:    'json',
    object_key: params['message_id'],
  })

  WcoEmail::MessageIntakeJob.perform_async( stub.id.to_s )
  render status: :ok, json: { status: :ok }
end

#create_sesObject



31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/wco_email/api/messages_controller.rb', line 31

def create_ses
  # puts! params, 'params'
  stub = WcoEmail::MessageStub.find_or_create_by({
    bucket:     params[:bucket],
    format:    'raw',
    object_key: params[:object_key],
  })

  WcoEmail::MessageIntakeJob.perform_async( stub.id.to_s )
  render status: :ok, json: { status: :ok }
end

#postal_webhookObject

SoftFail , Sent



91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/wco_email/api/messages_controller.rb', line 91

def postal_webhook
  payload = params['payload']
  if [ 'SoftFail', 'HardFail' ].include?( payload['status'] )
    lead = Wco::Lead.where( email: payload['message']['to'].downcase ).first
    if lead
      lead.tags.push Wco::Tag.bounce
      lead.save!
    end
  end

  render status: :ok, json: { status: :ok }
end