communicate_telegram.rb 792 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::Article::CommunicateTelegram < 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. # if sender is customer, do not communicate
  8. return if !record.sender_id
  9. sender = Ticket::Article::Sender.lookup(id: record.sender_id)
  10. return if sender.nil?
  11. return if sender['name'] == 'Customer'
  12. # only apply on telegram messages
  13. return if !record.type_id
  14. type = Ticket::Article::Type.lookup(id: record.type_id)
  15. return if type['name'] !~ /\Atelegram/i
  16. Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateTelegram::BackgroundJob.new(record.id))
  17. end
  18. end