enqueue_communicate_telegram_job.rb 914 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Schedules a backgrond communication job for new telegram articles.
  3. module Ticket::Article::EnqueueCommunicateTelegramJob
  4. extend ActiveSupport::Concern
  5. included do
  6. after_create :ticket_article_enqueue_communicate_telegram_job
  7. end
  8. private
  9. def ticket_article_enqueue_communicate_telegram_job
  10. # return if we run import mode
  11. return true if Setting.get('import_mode')
  12. # if sender is customer, do not communicate
  13. return true if !sender_id
  14. sender = Ticket::Article::Sender.lookup(id: sender_id)
  15. return true if sender.nil?
  16. return true if sender.name == 'Customer'
  17. # only apply on telegram messages
  18. return true if !type_id
  19. type = Ticket::Article::Type.lookup(id: type_id)
  20. return true if !type.name.match?(%r{\Atelegram}i)
  21. CommunicateTelegramJob.perform_later(id)
  22. end
  23. end