phone_numbers.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Whatsapp::Account::PhoneNumbers < Whatsapp::Client
  3. attr_reader :phone_numbers_api, :business_id
  4. def initialize(access_token:, business_id: nil)
  5. super(access_token:)
  6. @business_id = business_id
  7. @phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new client
  8. end
  9. def all
  10. raise ArgumentError, __("The required parameter 'business_id' is missing.") if business_id.nil?
  11. phone_numbers = phone_numbers_api.registered_numbers(business_id.to_i).data&.phone_numbers
  12. return [] if phone_numbers.nil?
  13. phone_numbers.to_h do |phone_number|
  14. [
  15. phone_number.id,
  16. format('%{name} (%{number})', name: phone_number.verified_name, number: phone_number.display_phone_number),
  17. ]
  18. end
  19. end
  20. def get(id)
  21. phone_number = phone_numbers_api.registered_number(id.to_i).data
  22. return if phone_number.nil?
  23. {
  24. name: phone_number.verified_name,
  25. phone_number: phone_number.display_phone_number
  26. }
  27. end
  28. end