communicate_twitter.rb 1.1 KB

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
  3. observe 'ticket::_article'
  4. def after_create(record)
  5. # return if we run import mode
  6. return if Setting.get('import_mode')
  7. # only do send email if article got created via application_server (e. g. not
  8. # if article and sender type is set via *.postmaster)
  9. return if ApplicationHandleInfo.postmaster?
  10. # if sender is customer, do not communicate
  11. return if !record.sender_id
  12. sender = Ticket::Article::Sender.lookup(id: record.sender_id)
  13. return if sender.nil?
  14. return if sender['name'] == 'Customer'
  15. # only apply on tweets
  16. return if !record.type_id
  17. type = Ticket::Article::Type.lookup(id: record.type_id)
  18. return if type['name'] !~ /\Atwitter/i
  19. raise Exceptions::UnprocessableEntity, 'twitter to: parameter is missing' if record.to.blank? && type['name'] == 'twitter direct-message'
  20. Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateTwitter::BackgroundJob.new(record.id))
  21. end
  22. end