2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-12-24 13:55:43 +00:00
|
|
|
class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
|
|
|
|
observe 'ticket::_article'
|
|
|
|
|
|
|
|
def after_create(record)
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
2016-08-20 19:29:22 +00:00
|
|
|
# only do send email if article got created via application_server (e. g. not
|
|
|
|
# if article and sender type is set via *.postmaster)
|
2017-11-23 08:09:44 +00:00
|
|
|
return if ApplicationHandleInfo.postmaster?
|
2016-08-20 19:29:22 +00:00
|
|
|
|
|
|
|
# if sender is customer, do not communicate
|
2016-08-23 18:46:04 +00:00
|
|
|
return if !record.sender_id
|
2015-12-14 09:23:14 +00:00
|
|
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
2015-07-02 15:13:04 +00:00
|
|
|
return if sender.nil?
|
|
|
|
return if sender['name'] == 'Customer'
|
2012-12-24 13:55:43 +00:00
|
|
|
|
|
|
|
# only apply on tweets
|
2016-08-23 18:46:04 +00:00
|
|
|
return if !record.type_id
|
2015-12-14 09:23:14 +00:00
|
|
|
type = Ticket::Article::Type.lookup(id: record.type_id)
|
|
|
|
return if type['name'] !~ /\Atwitter/i
|
|
|
|
|
2018-04-13 14:19:48 +00:00
|
|
|
raise Exceptions::UnprocessableEntity, 'twitter to: parameter is missing' if record.to.blank? && type['name'] == 'twitter direct-message'
|
2016-06-25 20:30:22 +00:00
|
|
|
Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateTwitter::BackgroundJob.new(record.id))
|
2012-12-24 13:55:43 +00:00
|
|
|
end
|
2015-12-14 09:23:14 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|