Class: Twilio::Rails::Phone::UpdateResponseOperation

Inherits:
BaseOperation show all
Defined in:
app/operations/twilio/rails/phone/update_response_operation.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/operations/twilio/rails/phone/update_response_operation.rb', line 9

def execute
  response = phone_call.responses.find(response_id)

  if params["Digits"].present?
    response.digits = params["Digits"]
  end

  if params["TranscriptionText"].present? && params["TranscriptionStatus"] == "completed"
    response.transcription = params["TranscriptionText"]
    response.transcribed = true
  end

  if params["SpeechResult"].present?
    response.transcription = params["SpeechResult"]
    response.transcribed = true
  end

  response.save! if response.changed?

  if params["RecordingSid"]
    Twilio::Rails::Phone::ReceiveRecordingOperation.call(phone_call_id: phone_call.id, response_id: response.id, params: params)
    response.reload # This attaches to the other end of the association so this instance doesn't know about it without a reload
  end

  response
end