preload.rb 703 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Service::Channel::Whatsapp
  3. class Preload < Service::Base
  4. attr_reader :business_id, :access_token
  5. def initialize(business_id:, access_token:)
  6. super()
  7. @business_id = business_id
  8. @access_token = access_token
  9. end
  10. def execute
  11. {
  12. phone_numbers: formatted_phone_numbers
  13. }
  14. end
  15. private
  16. def formatted_phone_numbers
  17. fetch_numbers.map { |phone_number| { label: phone_number.last, value: phone_number.first } }
  18. end
  19. def fetch_numbers
  20. Whatsapp::Account::PhoneNumbers
  21. .new(business_id:, access_token:)
  22. .all
  23. end
  24. end
  25. end