2012-12-24 13:55:43 +00:00
|
|
|
class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer
|
|
|
|
observe 'ticket::_article'
|
|
|
|
|
|
|
|
def after_create(record)
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
|
|
|
# if sender is customer, do not communication
|
2013-01-01 20:29:26 +00:00
|
|
|
sender = Ticket::Article::Sender.lookup( :id => record.ticket_article_sender_id )
|
2012-12-24 13:55:43 +00:00
|
|
|
return 1 if sender == nil
|
|
|
|
return 1 if sender['name'] == 'Customer'
|
|
|
|
|
|
|
|
# only apply on emails
|
2013-01-01 20:29:26 +00:00
|
|
|
type = Ticket::Article::Type.lookup( :id => record.ticket_article_type_id )
|
2012-12-24 13:55:43 +00:00
|
|
|
return if type['name'] != 'facebook'
|
|
|
|
|
|
|
|
a = Channel::Facebook.new
|
|
|
|
a.send(
|
|
|
|
{
|
|
|
|
:from => 'me@znuny.com',
|
|
|
|
:to => 'medenhofer',
|
|
|
|
:body => record.body
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|