Class: Whatsapp::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/whatsapp/configuration.rb

Defined Under Namespace

Modules: Defaults

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: Defaults::HOST, version: Defaults::VERSION, api_key: nil, phone_id: nil, waba_id: nil, media_host_allowlist: Defaults::MEDIA_HOST_ALLOWLIST, verify_token: nil, app_secret: nil) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • host (String) (defaults to: Defaults::HOST)

    The API origin

  • version (String) (defaults to: Defaults::VERSION)

    The API version

  • api_key (String) (defaults to: nil)

    The API key for authentication

  • phone_id (String) (defaults to: nil)

    The phone ID associated with the WhatsApp Business Account

  • waba_id (String) (defaults to: nil)

    The WhatsApp Business Account ID

  • media_host_allowlist (Array<String>) (defaults to: Defaults::MEDIA_HOST_ALLOWLIST)

    Hosts allowed for media downloads

  • verify_token (String, nil) (defaults to: nil)

    The default webhook verification token

  • app_secret (String, nil) (defaults to: nil)

    The default webhook signing secret



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby/whatsapp/configuration.rb', line 56

def initialize(host: Defaults::HOST, version: Defaults::VERSION, api_key: nil, phone_id: nil,
  waba_id: nil, media_host_allowlist: Defaults::MEDIA_HOST_ALLOWLIST, verify_token: nil, app_secret: nil)
  @host = host
  @version = version
  @api_key = api_key
  @phone_id = phone_id
  @waba_id = waba_id
  @media_host_allowlist = media_host_allowlist
  @verify_token = verify_token
  @app_secret = app_secret
end

Instance Attribute Details

#api_keyString

Returns:

  • (String)


24
25
26
# File 'lib/ruby/whatsapp/configuration.rb', line 24

def api_key
  @api_key
end

#app_secretString?

Used to verify the X-Hub-Signature-256 header on incoming webhook POSTs.

Returns:

  • (String, nil)


46
47
48
# File 'lib/ruby/whatsapp/configuration.rb', line 46

def app_secret
  @app_secret
end

#hostString

Returns:

  • (String)


16
17
18
# File 'lib/ruby/whatsapp/configuration.rb', line 16

def host
  @host
end

#media_host_allowlistArray<String>

Returns:

  • (Array<String>)


36
37
38
# File 'lib/ruby/whatsapp/configuration.rb', line 36

def media_host_allowlist
  @media_host_allowlist
end

#phone_idString

Returns:

  • (String)


28
29
30
# File 'lib/ruby/whatsapp/configuration.rb', line 28

def phone_id
  @phone_id
end

#verify_tokenString?

The token Meta must echo back during the webhook GET verification handshake.

Returns:

  • (String, nil)


41
42
43
# File 'lib/ruby/whatsapp/configuration.rb', line 41

def verify_token
  @verify_token
end

#versionString

Returns:

  • (String)


20
21
22
# File 'lib/ruby/whatsapp/configuration.rb', line 20

def version
  @version
end

#waba_idString

Returns:

  • (String)


32
33
34
# File 'lib/ruby/whatsapp/configuration.rb', line 32

def waba_id
  @waba_id
end

Instance Method Details

#inspectString

Redacts the api_key, app_secret, and verify_token so they never leak into logs or console output.

Returns:

  • (String)


70
71
72
73
74
75
76
77
# File 'lib/ruby/whatsapp/configuration.rb', line 70

def inspect
  redacted_api_key = api_key.nil? ? "nil" : "[REDACTED]"
  redacted_app_secret = app_secret.nil? ? "nil" : "[REDACTED]"
  redacted_verify_token = verify_token.nil? ? "nil" : "[REDACTED]"
  "#<#{self.class.name} host=#{host.inspect} version=#{version.inspect} " \
    "api_key=#{redacted_api_key} phone_id=#{phone_id.inspect} waba_id=#{waba_id.inspect} " \
    "verify_token=#{redacted_verify_token} app_secret=#{redacted_app_secret}>"
end