Class: Stealth::Services::Bandwidth::ReplyHandler

Inherits:
Stealth::Services::BaseReplyHandler
  • Object
show all
Defined in:
lib/stealth/services/bandwidth/reply_handler.rb

Constant Summary collapse

ALPHA_ORDINALS =
('A'..'Z').to_a.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reply: nil, **args) ⇒ ReplyHandler

Returns a new instance of ReplyHandler.



13
14
15
16
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 13

def initialize(reply: nil, **args)
  @recipient_id = args[:recipient_id]
  @reply = reply
end

Instance Attribute Details

#recipient_idObject (readonly)

Returns the value of attribute recipient_id.



11
12
13
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 11

def recipient_id
  @recipient_id
end

#replyObject (readonly)

Returns the value of attribute reply.



11
12
13
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 11

def reply
  @reply
end

#translated_replyObject (readonly)

Returns the value of attribute translated_reply.



11
12
13
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 11

def translated_reply
  @translated_reply
end

Instance Method Details

#audioObject



57
58
59
60
61
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 57

def audio
  check_text_length

  format_response({ text: reply[:text], media: [reply[:audio_url]] })
end

#delayObject



75
76
77
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 75

def delay

end

#fileObject



69
70
71
72
73
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 69

def file
  check_text_length

  format_response({ text: reply[:text], media: [reply[:file_url]] })
end

#imageObject



51
52
53
54
55
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 51

def image
  check_text_length

  format_response({ text: reply[:text], media: [reply[:image_url]] })
end

#textObject



18
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
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 18

def text
  check_text_length
  @translated_reply = reply[:text]

  suggestions = reply[:suggestions]

  buttons = generate_buttons(buttons: reply[:buttons])
  if suggestions.present?
    @translated_reply = [
      @translated_reply,
      'Reply with:'
    ].join("\n\n")

    suggestions.each_with_index do |suggestion, i|
      @translated_reply = [
        @translated_reply,
        "\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}"
      ].join("\n")
    end
  end

  if buttons.present?
    buttons.each do |button|
      @translated_reply = [
        @translated_reply,
        button
      ].join("\n\n")
    end
  end

  format_response({ text: @translated_reply })
end

#videoObject



63
64
65
66
67
# File 'lib/stealth/services/bandwidth/reply_handler.rb', line 63

def video
  check_text_length

  format_response({ text: reply[:text], media: [reply[:video_url]] })
end