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
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if Setting.get('import_mode')
|
2012-12-24 13:55:43 +00:00
|
|
|
|
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)
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if ApplicationHandleInfo.postmaster?
|
2016-08-20 19:29:22 +00:00
|
|
|
|
|
|
|
# if sender is customer, do not communicate
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if !record.sender_id
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-12-14 09:23:14 +00:00
|
|
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if sender.nil?
|
|
|
|
return true if sender.name == 'Customer'
|
2012-12-24 13:55:43 +00:00
|
|
|
|
|
|
|
# only apply on tweets
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if !record.type_id
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-12-14 09:23:14 +00:00
|
|
|
type = Ticket::Article::Type.lookup(id: record.type_id)
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if type.nil?
|
2019-09-16 09:21:10 +00:00
|
|
|
return true if !type.name.match?(/\Atwitter/i)
|
2015-12-14 09:23:14 +00:00
|
|
|
|
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'
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2020-10-27 15:36:38 +00:00
|
|
|
CommunicateTwitterJob.perform_later(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
|