summaryrefslogtreecommitdiff
path: root/app/models/acd_agent.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/acd_agent.rb')
-rw-r--r--app/models/acd_agent.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/models/acd_agent.rb b/app/models/acd_agent.rb
new file mode 100644
index 0000000..a00ac4b
--- /dev/null
+++ b/app/models/acd_agent.rb
@@ -0,0 +1,39 @@
+class AcdAgent < ActiveRecord::Base
+ DESTINATION_TYPES = ['SipAccount']
+ STATUSES = ['active', 'inactive']
+
+ attr_accessible :uuid, :name, :status, :automatic_call_distributor_id, :last_call, :calls_answered, :destination_type, :destination_id
+
+ belongs_to :automatic_call_distributor
+
+ belongs_to :destination, :polymorphic => true
+
+ after_save :set_presence
+
+ def to_s
+ self.name || I18n.t('acd_agents.name') + ' ID ' + self.id.to_s
+ end
+
+ private
+ def set_presence
+ dialplan_function = nil
+
+ state = 'early'
+ if self.status == 'active'
+ state = 'confirmed'
+ elsif self.status == 'inactive'
+ state = 'terminated'
+ end
+
+ require 'freeswitch_event'
+ event = FreeswitchEvent.new("PRESENCE_IN")
+ event.add_header("proto", "sip")
+ event.add_header("from", "f-acdmtg-#{self.id}@#{SipDomain.first.host}")
+ event.add_header("event_type", "presence")
+ event.add_header("alt_event_type", "dialog")
+ event.add_header("presence-call-direction", "outbound")
+ event.add_header("answer-state", state)
+ event.add_header("unique-id", "acd_agent_#{self.id}")
+ return event.fire()
+ end
+end