visciang / telegram

Telegram library for the Elixir language
MIT License
204 stars 27 forks source link

(RuntimeError) The tesla adapter has not been configured. #171

Closed Rim-777 closed 1 month ago

Rim-777 commented 1 month ago

Hello

I tried to run the following example within the Phoenix project and got the following error: Example:

  @moduledoc false

  require Logger

  use Telegram.ChatBot

  @session_ttl 60 * 1_000

  @impl Telegram.ChatBot
  def init(_chat) do
    count_state = 0
    {:ok, count_state, @session_ttl}
  end

  @impl Telegram.ChatBot
  def handle_update(%{"message" => %{"chat" => %{"id" => chat_id}}}, token, count_state) do
    count_state = count_state + 1

    Telegram.Api.request(token, "sendMessage",
      chat_id: chat_id,
      text: "Hey! You sent me #{count_state} messages"
    )

    {:ok, count_state, @session_ttl}
  end

  def handle_update(update, _token, count_state) do
    Logger.info("Unknown update received: #{inspect(update)}")

    {:ok, count_state, @session_ttl}
  end
end

token = "6999904422:AAFueF9-djzcUgbt8XuV52qmeR9k-A5PIkk"

if token == nil do
  IO.puts(:stderr, "Please provide a BOT_TOKEN environment variable")
  System.halt(1)
end

{:ok, _} =
  Supervisor.start_link(
    [{Telegram.Poller, bots: [{CountChatBot, token: token, max_bot_concurrency: 1_000}]}],
    strategy: :one_for_one
  )

Process.sleep(:infinity)

** (exit) shutdown: failed to start child: Telegram.Poller
    ** (EXIT) an exception was raised:
        ** (RuntimeError) The tesla adapter has not been configured. This will defaults to the built-in erlang :httpc module.

Please configure a production ready client, for instance:

config :tesla, adapter: {Tesla.Adapter.Hackney, [recv_timeout: 40_000]}

            (telegram 1.2.1) lib/poller.ex:55: Telegram.Poller.assert_tesla_adapter_config/0
            (telegram 1.2.1) lib/poller.ex:32: Telegram.Poller.start_link/1
            (stdlib 5.2) supervisor.erl:420: :supervisor.do_start_child_i/3
            (stdlib 5.2) supervisor.erl:406: :supervisor.do_start_child/2
            (stdlib 5.2) supervisor.erl:390: anonymous fn/3 in :supervisor.start_children/2
            (stdlib 5.2) supervisor.erl:1258: :supervisor.children_map/4
            (stdlib 5.2) supervisor.erl:350: :supervisor.init_children/2
            (stdlib 5.2) gen_server.erl:980: :gen_server.init_it/2```

Could you please help me find a solution?
I will appreciate any help you can provide