ExGram.Token (ex_gram v0.32.0) View Source

Helpers when dealing with bot's tokens

Link to this section Summary

Functions

Main logic to extract the token of the bot.

Link to this section Functions

Specs

fetch(keyword()) :: String.t() | nil

Main logic to extract the token of the bot.

The options can have the following keys:

  • token: Explicit token to be used, this ignore everything else and will use this one
  • bot: Bot name to be used, the token will be retrieved from the registry
  • registry: Optional. Registry to extract the bot's token. By default will use ExGram.Registry.

Usage:

ExGram.Token.fetch() # Will take it from the config (config :ex_gram, token: "token")

ExGram.Token.fetch(token: "MyToken") # Will use the token

ExGram.Token.fetch(bot: :my_bot) # Will look in ExGram.Registry for :my_bot token

ExGram.Token.fetch(bot: :my_bot, registry: OtherRegistry) # Will look in OtherRegistry for :My_bot token