Class: Xip::Services::Twilio::ReplyHandler
- Inherits:
-
BaseReplyHandler
- Object
- BaseReplyHandler
- Xip::Services::Twilio::ReplyHandler
- Defined in:
- lib/xip/services/twilio/reply_handler.rb
Constant Summary collapse
- ALPHA_ORDINALS =
('A'..'Z').to_a.freeze
Instance Attribute Summary collapse
-
#recipient_id ⇒ Object
readonly
Returns the value of attribute recipient_id.
-
#reply ⇒ Object
readonly
Returns the value of attribute reply.
Instance Method Summary collapse
- #audio ⇒ Object
- #delay ⇒ Object
- #file ⇒ Object
- #image ⇒ Object
-
#initialize(recipient_id: nil, reply: nil) ⇒ ReplyHandler
constructor
A new instance of ReplyHandler.
- #text ⇒ Object
- #video ⇒ Object
Constructor Details
#initialize(recipient_id: nil, reply: nil) ⇒ ReplyHandler
Returns a new instance of ReplyHandler.
12 13 14 15 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 12 def initialize(recipient_id: nil, reply: nil) @recipient_id = recipient_id @reply = reply end |
Instance Attribute Details
#recipient_id ⇒ Object (readonly)
Returns the value of attribute recipient_id.
10 11 12 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 10 def recipient_id @recipient_id end |
#reply ⇒ Object (readonly)
Returns the value of attribute reply.
10 11 12 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 10 def reply @reply end |
Instance Method Details
#audio ⇒ Object
57 58 59 60 61 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 57 def audio check_text_length format_response({ body: reply['text'], media_url: reply['audio_url'] }) end |
#delay ⇒ Object
75 76 77 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 75 def delay end |
#file ⇒ Object
69 70 71 72 73 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 69 def file check_text_length format_response({ body: reply['text'], media_url: reply['file_url'] }) end |
#image ⇒ Object
51 52 53 54 55 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 51 def image check_text_length format_response({ body: reply['text'], media_url: reply['image_url'] }) end |
#text ⇒ Object
17 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/xip/services/twilio/reply_handler.rb', line 17 def text check_text_length translated_reply = reply['text'] suggestions = generate_suggestions(suggestions: reply['suggestions']) = (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 .present? .each do || translated_reply = [ translated_reply, ].join("\n\n") end end format_response({ body: translated_reply }) end |
#video ⇒ Object
63 64 65 66 67 |
# File 'lib/xip/services/twilio/reply_handler.rb', line 63 def video check_text_length format_response({ body: reply['text'], media_url: reply['video_url'] }) end |