Module: Twilio::Rails::Models::PhoneCaller
- Extended by:
- ActiveSupport::Concern
- Included in:
- PhoneCaller
- Defined in:
- lib/twilio/rails/models/phone_caller.rb
Overview
The core identity object, uniquely identifying an individual by their phone number. All ingoing or outgoing phone calls or SMS messages are associated to a phone caller. A phone caller is automatically created when any phone call or SMS message is sent or received.
Instance Method Summary collapse
-
#inbound_calls_for(tree) ⇒ Array<Twilio::Rails::Models::PhoneCall>
All inbound phone calls for the given phone tree or tree name.
-
#location ⇒ String
A well formatted string with the city/state/country of the phone caller, if available.
-
#outbound_calls_for(tree) ⇒ Array<Twilio::Rails::Models::PhoneCall>
All outbound phone calls for the given phone tree or tree name.
-
#response_digits(prompt:, tree:) ⇒ String?
Returns the digits as a ‘String` as entered through the keypad during a phone call as `gather:`.
-
#response_for(prompt:, tree:) ⇒ Twilio::Rails::Models::Response?
Finds the most recent Response for the given prompt and tree.
-
#response_integer_digits(prompt:, tree:) ⇒ Integer?
Returns the digits as an ‘Integer` entered through the keypad during a phone call as `gather:`.
-
#response_reached?(prompt:, tree:) ⇒ true, false
Checks if this phone caller has ever reached a response in a given phone tree.
-
#sms_conversations ⇒ Array<Twilio::Rails::Models::SmsConversation>
All SMS conversations for the phone caller.
Instance Method Details
#inbound_calls_for(tree) ⇒ Array<Twilio::Rails::Models::PhoneCall>
Returns All inbound phone calls for the given phone tree or tree name.
36 37 38 39 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 36 def inbound_calls_for(tree) tree = tree.is_a?(Twilio::Rails::Phone::Tree) ? tree.name : tree phone_calls.inbound.tree(tree) end |
#location ⇒ String
Returns A well formatted string with the city/state/country of the phone caller, if available.
31 32 33 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 31 def location phone_calls.inbound.last&.location end |
#outbound_calls_for(tree) ⇒ Array<Twilio::Rails::Models::PhoneCall>
Returns All outbound phone calls for the given phone tree or tree name.
42 43 44 45 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 42 def outbound_calls_for(tree) tree = tree.is_a?(Twilio::Rails::Phone::Tree) ? tree.name : tree phone_calls.outbound.tree(tree) end |
#response_digits(prompt:, tree:) ⇒ String?
Returns the digits as a ‘String` as entered through the keypad during a phone call as `gather:`. Returns `nil` if the response is not found, if the response has no digits, or if the response was a timeout. Can include both `*` and `#` characters if the caller pressed them.
59 60 61 62 63 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 59 def response_digits(prompt:, tree:) response = responses.tree(tree).where(prompt_handle: prompt, timeout: false).last return nil unless response response.digits end |
#response_for(prompt:, tree:) ⇒ Twilio::Rails::Models::Response?
Finds the most recent Response for the given prompt and tree. This is useful for building phone trees and finding previous responses to prompts. Returns ‘nil` if no response is found.
95 96 97 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 95 def response_for(prompt:, tree:) responses.tree(tree).where(prompt_handle: prompt).last end |
#response_integer_digits(prompt:, tree:) ⇒ Integer?
Returns the digits as an ‘Integer` entered through the keypad during a phone call as `gather:`. Returns `nil` if the response is not found, if the response has no digits, if the response was a timeout, or if the response contains `*` or `#` characters. Useful for doing branching logic within a phone tree, such as “Press 2 for sales…” etc..
73 74 75 76 77 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 73 def response_integer_digits(prompt:, tree:) response = responses.tree(tree).where(prompt_handle: prompt, timeout: false).last return nil unless response response.integer_digits end |
#response_reached?(prompt:, tree:) ⇒ true, false
Checks if this phone caller has ever reached a response in a given phone tree. This is useful for building phone trees and determining if a phone caller has reached a certain point in the tree before or not.
85 86 87 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 85 def response_reached?(prompt:, tree:) response_for(prompt: prompt, tree: tree).present? end |
#sms_conversations ⇒ Array<Twilio::Rails::Models::SmsConversation>
Returns All SMS conversations for the phone caller.
48 49 50 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 48 def sms_conversations Twilio::Rails.config.sms_conversation_class.phone_number(phone_number) end |