Sha256: e533c04683365da1c3d79b00c10ee211643bbac2bc36ecb4ac0b84d5d18ff8b4

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

# coding: utf-8
# frozen_string_literal: true

module Stealth
  module Services
    module Twilio

      class ReplyHandler < Stealth::Services::BaseReplyHandler

        attr_reader :recipient_id, :reply

        def initialize(recipient_id: nil, reply: nil)
          @recipient_id = recipient_id
          @reply = reply
        end

        def text
          check_text_length

          format_response({ body: reply['text'] })
        end

        def image
          check_text_length

          format_response({ body: reply['text'], media_url: reply['image_url'] })
        end

        def audio
          check_text_length

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

        def video
          check_text_length

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

        def delay

        end

        private

          def check_text_length
            if reply['text'].present? && reply['text'].size > 1600
              raise(ArgumentError, "Text messages must be 1600 characters or less.")
            end
          end

          def format_response(response)
            sender_info = { from: Stealth.config.twilio.from_phone, to: recipient_id }
            response.merge(sender_info)
          end

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stealth-twilio-0.9.7 lib/stealth/services/twilio/reply_handler.rb
stealth-twilio-0.9.6 lib/stealth/services/twilio/reply_handler.rb
stealth-twilio-0.9.5 lib/stealth/services/twilio/reply_handler.rb
stealth-twilio-0.9.4 lib/stealth/services/twilio/reply_handler.rb
stealth-twilio-0.9.3 lib/stealth/services/twilio/reply_handler.rb
stealth-twilio-0.9.2 lib/stealth/services/twilio/reply_handler.rb