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.
35 36 37 38 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 35 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.
30 31 32 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 30 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.
41 42 43 44 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 41 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.
58 59 60 61 62 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 58 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.
94 95 96 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 94 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..
72 73 74 75 76 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 72 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.
84 85 86 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 84 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.
47 48 49 |
# File 'lib/twilio/rails/models/phone_caller.rb', line 47 def sms_conversations Twilio::Rails.config.sms_conversation_class.phone_number(self.phone_number) end |