enqueue_communicate_whatsapp_job.rb 842 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Ticket::Article::EnqueueCommunicateWhatsappJob
  3. extend ActiveSupport::Concern
  4. included do
  5. after_create :ticket_article_enqueue_communicate_whatsapp_job
  6. end
  7. private
  8. def ticket_article_enqueue_communicate_whatsapp_job
  9. # return if we run import mode
  10. return true if Setting.get('import_mode')
  11. # if sender is customer, do not communicate
  12. return true if !sender_id
  13. sender = Ticket::Article::Sender.lookup(id: sender_id)
  14. return true if sender.nil?
  15. return true if sender.name == 'Customer'
  16. # only apply on whatsapp messages
  17. return true if !type_id
  18. type = Ticket::Article::Type.lookup(id: type_id)
  19. return true if type.name != 'whatsapp message'
  20. CommunicateWhatsappJob.perform_later(id)
  21. end
  22. end