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(recipient_id: nil, reply: nil) ⇒ ReplyHandler

Returns a new instance of ReplyHandler.



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

def initialize(recipient_id: nil, reply: nil)
  @recipient_id = 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



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

def audio
  check_text_length

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

#delayObject



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

def delay

end

#fileObject



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

def file
  check_text_length

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

#imageObject



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

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

def text
  check_text_length

  @translated_reply = reply['text']

  suggestions = generate_suggestions(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



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

def video
  check_text_length

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