Class: WcoEmail::MessagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/wco_email/messages_controller.rb

Instance Method Summary collapse

Instance Method Details

#autorespondObject



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

def autorespond
  @message = WcoEmail::Message.find params[:id]
  authorize! :show, @message

  task = 'You are an administrative assistant. Write a brief email response to the following email. exclude subject. exclude footer. exclude signature. format as <p></p> html paragraphs.'
  content = @message.part_txt
  outs = Wco::AiWriter.do_call(task, content)
  puts! outs, 'outs'


  @ctx = WcoEmail::Context.new({
    bcc_self:            true,
    body:                outs,
    email_template:      WcoEmail::EmailTemplate.blank,
    from_email:          @message.to,
    lead:                @message.lead,
    reply_to_message_id: @message.id,
    # send_at:             Time.now,
    subject:             @message.subject,
  })

  if @ctx.save
    flash_notice 'Saved.'
  else
    flash_alert @ctx
  end
  redirect_to request.referrer
end

#showObject



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/wco_email/messages_controller.rb', line 35

def show
  @client ||= Aws::S3::Client.new(::SES_S3_CREDENTIALS)
  @message = WcoEmail::Message.find params[:id]
  authorize! :show, @message

  stub     = @message.stub
  raw      = @client.get_object( bucket: stub.bucket, key: stub.object_key ).body.read
  raw      = raw.encode('utf-8', invalid: :replace, undef: :replace, replace: '_' )
  @the_mail = Mail.new( raw )
end

#show_iframeObject



46
47
48
49
50
# File 'app/controllers/wco_email/messages_controller.rb', line 46

def show_iframe
  @message = WcoEmail::Message.find params[:id]
  authorize! :show, @message
  render layout: false
end