2021-03-01 08:18:40 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
# Schedules a backgrond communication job for new telegram articles.
|
|
|
|
module Ticket::Article::EnqueueCommunicateTelegramJob
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
after_create :ticket_article_enqueue_communicate_telegram_job
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ticket_article_enqueue_communicate_telegram_job
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return true if Setting.get('import_mode')
|
|
|
|
|
|
|
|
# if sender is customer, do not communicate
|
|
|
|
return true if !sender_id
|
|
|
|
|
|
|
|
sender = Ticket::Article::Sender.lookup(id: sender_id)
|
|
|
|
return true if sender.nil?
|
|
|
|
return true if sender.name == 'Customer'
|
|
|
|
|
|
|
|
# only apply on telegram messages
|
|
|
|
return true if !type_id
|
|
|
|
|
|
|
|
type = Ticket::Article::Type.lookup(id: type_id)
|
2021-05-12 11:37:44 +00:00
|
|
|
return true if !type.name.match?(%r{\Atelegram}i)
|
2021-03-01 08:18:40 +00:00
|
|
|
|
|
|
|
CommunicateTelegramJob.perform_later(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|