# `ExGram.Token`
[🔗](https://github.com/rockneurotiko/ex_gram/blob/0.65.0/lib/ex_gram/token.ex#L1)

Helpers for working with bot tokens.

This module provides the `fetch/1` function to retrieve bot tokens from various
sources: explicit options, the bot registry, or application configuration.

See `ExGram.Bot` for how tokens are registered during bot startup.

# `fetch`

```elixir
@spec 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 (ignores everything else)
  * `:bot` - Bot name (atom) to retrieve token from registry
  * `:registry` - Optional. Registry to extract the bot's token (default: `Registry.ExGram`)

## Examples

    ExGram.Token.fetch() # From config :ex_gram, :token

    ExGram.Token.fetch(token: "MyToken") # Explicit token

    ExGram.Token.fetch(bot: :my_bot) # From Registry.ExGram

    ExGram.Token.fetch(bot: :my_bot, registry: OtherRegistry)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
