Sha256: 24e9de23c61627c4bd26f72a5420059a903e93009a4a76ebb49f95c62b62c274

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Xip
  module Services
    module Twilio
      class MessageHandler < Xip::Services::BaseMessageHandler
        attr_reader :service_message, :params, :headers

        def initialize(params:, headers:)
          @params = params
          @headers = headers
        end

        def coordinate
          Xip::Services::HandleMessageJob.perform_async(
            'twilio',
            params,
            headers
          )

          # Relay our acceptance
          [204, 'No Content']
        end

        def process
          @service_message = ServiceMessage.new(service: 'twilio')
          service_message.sender_id = params['From']
          service_message.target_id = params['To']
          service_message.message = params['Body']

          # Check for media attachments
          attachment_count = params['NumMedia'].to_i

          attachment_count.times do |i|
            service_message.attachments << {
              type: params["MediaContentType#{i}"],
              url: params["MediaUrl#{i}"]
            }
          end

          service_message
        end

      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
xip-twilio-1.3.6 lib/xip/services/twilio/message_handler.rb
xip-twilio-1.3.5 lib/xip/services/twilio/message_handler.rb
xip-twilio-1.3.4 lib/xip/services/twilio/message_handler.rb
xip-twilio-1.3.3 lib/xip/services/twilio/message_handler.rb