-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsms_conversation.rb
29 lines (25 loc) · 1.08 KB
/
sms_conversation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true
module Twilio
module Rails
module Models
# A conversation via SMS. Has many {Twilio::Rails::Models::Message}s. Each message has a direction and can be
# unrolled into a full conversation.
module SMSConversation
extend ActiveSupport::Concern
included do
has_many :messages, -> { order(created_at: :asc) }, dependent: :destroy, class_name: Twilio::Rails.config.message_class_name
scope :recent, -> { reorder(created_at: :desc).limit(10) }
scope :phone_number, ->(number) { where(from_number: number) }
end
# @return [Twilio::Rails::Models::PhoneCaller] The phone caller associated with this conversation.
def phone_caller
Twilio::Rails.config.phone_caller_class.for(from_number)
end
# @return [String] A well formatted string with the city/state/country of the phone number if available.
def location
Twilio::Rails::Formatter.location(city: from_city, country: from_country, province: from_province)
end
end
end
end
end