Packages
telegex
1.9.0-rc.0
1.9.0-rc.0
1.8.0
1.7.0
1.6.0
1.5.0
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.3-dev
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
1.0.0-rc.10
1.0.0-rc.9
1.0.0-rc.8
1.0.0-rc.7
1.0.0-rc.6
1.0.0-rc.5
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.1.0-rc.11
0.1.0-rc.10
0.1.0-rc.9
0.1.0-rc.8
0.1.0-rc.7
0.1.0-rc.6
0.1.0-rc.5
0.1.0-rc.4
0.1.0-rc.3
0.1.0-rc.2
0.1.0-rc.1
0.0.4
0.0.3
0.0.2
0.0.1
A Telegram bot framework, with its client-side based on data and code generation, boasts unparalleled adaptation speed and correctness for new versions.
Current section
Files
Jump to
Current section
Files
lib/telegex/instance.ex
defmodule Telegex.Instance do
@moduledoc """
Independent configuration and information for bot instances.
**Note: This module is not officially implemented at the moment, reserved for multi-instance support.**
"""
use GenServer
require Logger
use TypedStruct
typedstruct module: State do
field :bot, Telegex.Type.User.t()
end
def start_link(_) do
GenServer.start_link(__MODULE__, %State{}, name: __MODULE__)
end
@spec token() :: String.t()
def token, do: Telegex.Global.token()
@impl true
def init(state) do
{:ok, state}
end
@doc """
Call the `Telegex.get_me/0` function to get and cache the bot's own user information.
"""
@spec fetch_me :: {:ok, Telegex.Type.User.t()} | {:error, Telegex.Type.error()}
def fetch_me do
GenServer.call(__MODULE__, :fetch_me, :infinity)
end
@doc """
Get the cached bot's own user information.
"""
@spec bot :: Telegex.Type.User.t()
def bot do
GenServer.call(__MODULE__, :bot)
end
@impl true
def handle_call(:fetch_me, _from, state) do
case Telegex.get_me() do
{:ok, bot} = r ->
{:reply, r, %{state | bot: bot}}
{:error, _} = r ->
{:reply, r, state}
end
end
@impl true
def handle_call(:bot, _from, %{bot: bot} = state) do
{:reply, bot, state}
end
end