cti_caller_id_detection.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Transaction::CtiCallerIdDetection
  3. =begin
  4. {
  5. object: 'Ticket',
  6. type: 'create',
  7. object_id: 123,
  8. interface_handle: 'application_server', # application_server|websocket|scheduler
  9. user_id: 123,
  10. created_at: Time.zone.now,
  11. },
  12. {
  13. object: 'User',
  14. type: 'update',
  15. object_id: 123,
  16. interface_handle: 'application_server', # application_server|websocket|scheduler
  17. changes: {
  18. 'attribute1' => [before, now],
  19. 'attribute2' => [before, now],
  20. }
  21. created_at: Time.zone.now,
  22. user_id: 123,
  23. },
  24. =end
  25. def initialize(item, params = {})
  26. @item = item
  27. @params = params
  28. end
  29. def perform
  30. # return if we run import mode
  31. return if Setting.get('import_mode')
  32. if @item[:object] == 'Ticket' && @item[:type] == 'create'
  33. ticket = Ticket.lookup(id: @item[:object_id])
  34. return if !ticket
  35. Cti::CallerId.build(ticket)
  36. end
  37. if @item[:object] == 'User'
  38. user = User.lookup(id: @item[:object_id])
  39. return if !user
  40. Cti::CallerId.build(user)
  41. end
  42. true
  43. end
  44. end