From 23a35b99c5768528d89037bbf372723affcbf7b1 Mon Sep 17 00:00:00 2001 From: visciang Date: Sat, 5 Oct 2024 07:36:02 +0000 Subject: [PATCH] deploy: 3964c227b2083bd5fddee9bfce9bd783d561cc0b --- 404.html | 6 +-- Telegram.Api.html | 18 +++---- Telegram.Bot.Dispatch.html | 8 ++-- Telegram.Bot.Utils.html | 8 ++-- Telegram.Bot.html | 30 ++++++------ Telegram.ChatBot.html | 52 ++++++++++---------- Telegram.Poller.html | 26 +++++----- Telegram.Types.html | 8 ++-- Telegram.WebServer.Bandit.html | 8 ++-- Telegram.WebServer.Cowboy.html | 8 ++-- Telegram.Webhook.html | 34 ++++++------- api-reference.html | 8 ++-- index.html | 2 +- readme.html | 88 +++++++++++++++++----------------- search.html | 6 +-- 15 files changed, 155 insertions(+), 155 deletions(-) diff --git a/404.html b/404.html index 411be4c..00257d4 100644 --- a/404.html +++ b/404.html @@ -5,12 +5,12 @@ - + - 404 — telegram v1.2.2 + 404 — telegram v1.2.3 @@ -52,7 +52,7 @@ telegram diff --git a/Telegram.Api.html b/Telegram.Api.html index 50c7c60..31eb116 100644 --- a/Telegram.Api.html +++ b/Telegram.Api.html @@ -5,10 +5,10 @@ - + - Telegram.Api — telegram v1.2.2 + Telegram.Api — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.Api - (telegram v1.2.2) + (telegram v1.2.3)

@@ -369,15 +369,15 @@

file(token, file_path)

Download a file.

Reference: BOT Api

Example:

# send a photo
-{:ok, res} = Telegram.Api.request(token, "sendPhoto", chat_id: 12345, photo: {:file, "example/photo.jpg"})
+{:ok, res} = Telegram.Api.request(token, "sendPhoto", chat_id: 12345, photo: {:file, "example/photo.jpg"})
 # pick the 'file_obj' with the desired resolution
-[file_obj | _] = res["photo"]
+[file_obj | _] = res["photo"]
 # get the 'file_id'
-file_id = file_obj["file_id"]
+file_id = file_obj["file_id"]
 
 # obtain the 'file_path' to download the file identified by 'file_id'
-{:ok, %{"file_path" => file_path}} = Telegram.Api.request(token, "getFile", file_id: file_id)
-{:ok, file} = Telegram.Api.file(token, file_path)
+{:ok, %{"file_path" => file_path}} = Telegram.Api.request(token, "getFile", file_id: file_id) +{:ok, file} = Telegram.Api.file(token, file_path)
diff --git a/Telegram.Bot.Dispatch.html b/Telegram.Bot.Dispatch.html index 504adff..25559f7 100644 --- a/Telegram.Bot.Dispatch.html +++ b/Telegram.Bot.Dispatch.html @@ -5,10 +5,10 @@ - + - Telegram.Bot.Dispatch — telegram v1.2.2 + Telegram.Bot.Dispatch — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.Bot.Dispatch behaviour - (telegram v1.2.2) + (telegram v1.2.3)

diff --git a/Telegram.Bot.Utils.html b/Telegram.Bot.Utils.html index 77756e1..43a9ce9 100644 --- a/Telegram.Bot.Utils.html +++ b/Telegram.Bot.Utils.html @@ -5,10 +5,10 @@ - + - Telegram.Bot.Utils — telegram v1.2.2 + Telegram.Bot.Utils — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.Bot.Utils - (telegram v1.2.2) + (telegram v1.2.3)

diff --git a/Telegram.Bot.html b/Telegram.Bot.html index 71e2404..bd6d566 100644 --- a/Telegram.Bot.html +++ b/Telegram.Bot.html @@ -5,10 +5,10 @@ - + - Telegram.Bot — telegram v1.2.2 + Telegram.Bot — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.Bot behaviour - (telegram v1.2.2) + (telegram v1.2.3)

@@ -130,27 +130,27 @@

Example

-
defmodule HelloBot do
+
defmodule HelloBot do
   use Telegram.Bot
 
   @impl Telegram.Bot
-  def handle_update(
-    %{"message" => %{"text" => "/hello", "chat" => %{"id" => chat_id, "username" => username}, "message_id" => message_id}},
+  def handle_update(
+    %{"message" => %{"text" => "/hello", "chat" => %{"id" => chat_id, "username" => username}, "message_id" => message_id}},
     token
-  ) do
-    Telegram.Api.request(token, "sendMessage",
+  ) do
+    Telegram.Api.request(token, "sendMessage",
       chat_id: chat_id,
       reply_to_message_id: message_id,
-      text: "Hello #{username}!"
-    )
-  end
+      text: "Hello #{username}!"
+    )
+  end
 
-  def handle_update(_update, _token) do
+  def handle_update(_update, _token) do
     # ignore unknown updates
 
     :ok
-  end
-end
+
end +end
diff --git a/Telegram.ChatBot.html b/Telegram.ChatBot.html index dc0005d..61d5cd0 100644 --- a/Telegram.ChatBot.html +++ b/Telegram.ChatBot.html @@ -5,10 +5,10 @@ - + - Telegram.ChatBot — telegram v1.2.2 + Telegram.ChatBot — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.ChatBot behaviour - (telegram v1.2.2) + (telegram v1.2.3)

@@ -136,52 +136,52 @@

Example

-
defmodule HelloBot do
+
defmodule HelloBot do
   use Telegram.ChatBot
 
   @session_ttl 60 * 1_000
 
   @impl Telegram.ChatBot
-  def init(_chat) do
+  def init(_chat) do
     count_state = 0
-    {:ok, count_state, @session_ttl}
-  end
+    {:ok, count_state, @session_ttl}
+  end
 
   @impl Telegram.ChatBot
-  def handle_update(%{"message" => %{"chat" => %{"id" => chat_id}}}, token, count_state) do
+  def handle_update(%{"message" => %{"chat" => %{"id" => chat_id}}}, token, count_state) do
     count_state = count_state + 1
 
-    Telegram.Api.request(token, "sendMessage",
+    Telegram.Api.request(token, "sendMessage",
       chat_id: chat_id,
-      text: "Hey! You sent me #{count_state} messages"
-    )
+      text: "Hey! You sent me #{count_state} messages"
+    )
 
-    {:ok, count_state, @session_ttl}
-  end
+    {:ok, count_state, @session_ttl}
+  end
 
-  def handle_update(update, _token, count_state) do
+  def handle_update(update, _token, count_state) do
     # ignore unknown updates
 
-    {:ok, count_state, @session_ttl}
-  end
+    {:ok, count_state, @session_ttl}
+  end
 
   @impl Telegram.ChatBot
-  def handle_info(msg, _token, _chat_id, count_state) do
+  def handle_info(msg, _token, _chat_id, count_state) do
     # direct message processing
 
-    {:ok, count_state}
-  end
+    {:ok, count_state}
+  end
 
   @impl Telegram.ChatBot
-  def handle_timeout(token, chat_id, count_state) do
-    Telegram.Api.request(token, "sendMessage",
+  def handle_timeout(token, chat_id, count_state) do
+    Telegram.Api.request(token, "sendMessage",
       chat_id: chat_id,
       text: "See you!"
-    )
+    )
 
-    {:stop, count_state}
-  end
-end
+
{:stop, count_state} + end +end
diff --git a/Telegram.Poller.html b/Telegram.Poller.html index ebb6c2b..1af6b7d 100644 --- a/Telegram.Poller.html +++ b/Telegram.Poller.html @@ -5,10 +5,10 @@ - + - Telegram.Poller — telegram v1.2.2 + Telegram.Poller — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.Poller - (telegram v1.2.2) + (telegram v1.2.3)

@@ -130,18 +130,18 @@

Usage

-

In you app supervisor tree:

bot_config = [
-  token: Application.fetch_env!(:my_app, :token_counter_bot),
-  max_bot_concurrency: Application.fetch_env!(:my_app, :max_bot_concurrency)
-]
+

In you app supervisor tree:

bot_config = [
+  token: Application.fetch_env!(:my_app, :token_counter_bot),
+  max_bot_concurrency: Application.fetch_env!(:my_app, :max_bot_concurrency)
+]
 
-children = [
-  {Telegram.Poller, bots: [{MyApp.Bot, bot_config}]}
+children = [
+  {Telegram.Poller, bots: [{MyApp.Bot, bot_config}]}
   ...
-]
+]
 
-opts = [strategy: :one_for_one, name: MyApp.Supervisor]
-Supervisor.start_link(children, opts)
+
opts = [strategy: :one_for_one, name: MyApp.Supervisor] +Supervisor.start_link(children, opts)
diff --git a/Telegram.Types.html b/Telegram.Types.html index 9750476..c221513 100644 --- a/Telegram.Types.html +++ b/Telegram.Types.html @@ -5,10 +5,10 @@ - + - Telegram.Types — telegram v1.2.2 + Telegram.Types — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.Types - (telegram v1.2.2) + (telegram v1.2.3)

diff --git a/Telegram.WebServer.Bandit.html b/Telegram.WebServer.Bandit.html index f68788c..b07bcf7 100644 --- a/Telegram.WebServer.Bandit.html +++ b/Telegram.WebServer.Bandit.html @@ -5,10 +5,10 @@ - + - Telegram.WebServer.Bandit — telegram v1.2.2 + Telegram.WebServer.Bandit — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.WebServer.Bandit - (telegram v1.2.2) + (telegram v1.2.3)

diff --git a/Telegram.WebServer.Cowboy.html b/Telegram.WebServer.Cowboy.html index 1292ee0..8a5f271 100644 --- a/Telegram.WebServer.Cowboy.html +++ b/Telegram.WebServer.Cowboy.html @@ -5,10 +5,10 @@ - + - Telegram.WebServer.Cowboy — telegram v1.2.2 + Telegram.WebServer.Cowboy — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.WebServer.Cowboy - (telegram v1.2.2) + (telegram v1.2.3)

diff --git a/Telegram.Webhook.html b/Telegram.Webhook.html index ef948f3..b6a1d7d 100644 --- a/Telegram.Webhook.html +++ b/Telegram.Webhook.html @@ -5,10 +5,10 @@ - + - Telegram.Webhook — telegram v1.2.2 + Telegram.Webhook — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

Telegram.Webhook - (telegram v1.2.2) + (telegram v1.2.3)

@@ -144,34 +144,34 @@

# OR config :telegram, - webserver: Telegram.WebServer.Cowboy

and include in you dependencies one of:

{:plug_cowboy, "~> 2.5"}
+  webserver: Telegram.WebServer.Cowboy

and include in you dependencies one of:

{:plug_cowboy, "~> 2.5"}
 
 # OR
 
-{:bandit, "~> 1.0"}

+{:bandit, "~> 1.0"}

Supervision tree

-

In you app supervision tree:

webhook_config = [
+

In you app supervision tree:

webhook_config = [
   host: "myapp.public-domain.com",
   port: 443,
   local_port: 4_000
-]
+]
 
-bot_config = [
-  token: Application.fetch_env!(:my_app, :token_counter_bot),
-  max_bot_concurrency: Application.fetch_env!(:my_app, :max_bot_concurrency)
-]
+bot_config = [
+  token: Application.fetch_env!(:my_app, :token_counter_bot),
+  max_bot_concurrency: Application.fetch_env!(:my_app, :max_bot_concurrency)
+]
 
-children = [
-  {Telegram.Webhook, config: webhook_config, bots: [{MyApp.Bot, bot_config}]}
+children = [
+  {Telegram.Webhook, config: webhook_config, bots: [{MyApp.Bot, bot_config}]}
   ...
-]
+]
 
-opts = [strategy: :one_for_one, name: MyApp.Supervisor]
-Supervisor.start_link(children, opts)

+opts = [strategy: :one_for_one, name: MyApp.Supervisor] +Supervisor.start_link(children, opts)

diff --git a/api-reference.html b/api-reference.html index c70104e..d955f97 100644 --- a/api-reference.html +++ b/api-reference.html @@ -5,10 +5,10 @@ - + - API Reference — telegram v1.2.2 + API Reference — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -118,7 +118,7 @@

- API Reference telegram v1.2.2 + API Reference telegram v1.2.3

diff --git a/index.html b/index.html index 0f250b1..e789ce8 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - telegram v1.2.2 — Documentation + telegram v1.2.3 — Documentation diff --git a/readme.html b/readme.html index 0667d4b..cecdbf7 100644 --- a/readme.html +++ b/readme.html @@ -5,10 +5,10 @@ - + - Telegram — telegram v1.2.2 + Telegram — telegram v1.2.3 @@ -50,7 +50,7 @@ telegram @@ -127,11 +127,11 @@

Installation

-

The package can be installed by adding telegram to your list of dependencies in mix.exs:

def deps do
-  [
-    {:telegram, github: "visciang/telegram", tag: "xxx"}
-  ]
-end

Telegram Bot API

This module expose a light layer over the Telegram Bot API HTTP-based interface, +

The package can be installed by adding telegram to your list of dependencies in mix.exs:

def deps do
+  [
+    {:telegram, github: "visciang/telegram", tag: "xxx"}
+  ]
+end

Telegram Bot API

This module expose a light layer over the Telegram Bot API HTTP-based interface, it does not expose any "(data)binding" over the HTTP interface and tries to abstract away only the boilerplate for building / sending / serializing the API requests.

Compared to a full data-binded interface it could result less "typed frendly" but it will work with any version of the Bot API, hopefully without updates or incompatibily @@ -147,52 +147,52 @@

getMe

-
Telegram.Api.request(token, "getMe")
+
Telegram.Api.request(token, "getMe")
 
-{:ok, %{"first_name" => "Abc", "id" => 1234567, "is_bot" => true, "username" => "ABC"}}

+{:ok, %{"first_name" => "Abc", "id" => 1234567, "is_bot" => true, "username" => "ABC"}}

sendMessage

-
Telegram.Api.request(token, "sendMessage", chat_id: 876532, text: "Hello! .. silently", disable_notification: true)
+
Telegram.Api.request(token, "sendMessage", chat_id: 876532, text: "Hello! .. silently", disable_notification: true)
 
-{:ok,
-  %{"chat" => %{"first_name" => "Firstname",
+{:ok,
+  %{"chat" => %{"first_name" => "Firstname",
       "id" => 208255328,
       "last_name" => "Lastname",
       "type" => "private",
-      "username" => "xxxx"},
+      "username" => "xxxx"},
     "date" => 1505118722,
-    "from" => %{"first_name" => "Yyy",
+    "from" => %{"first_name" => "Yyy",
       "id" => 234027650,
       "is_bot" => true,
-      "username" => "yyy"},
+      "username" => "yyy"},
     "message_id" => 1402,
-    "text" => "Hello! .. silently"}}

+ "text" => "Hello! .. silently"}}

getUpdates

-
Telegram.Api.request(token, "getUpdates", offset: -1, timeout: 30)
+
Telegram.Api.request(token, "getUpdates", offset: -1, timeout: 30)
 
-{:ok,
-  [%{"message" => %{"chat" => %{"first_name" => "Firstname",
+{:ok,
+  [%{"message" => %{"chat" => %{"first_name" => "Firstname",
         "id" => 208255328,
         "last_name" => "Lastname",
         "type" => "private",
-        "username" => "xxxx"},
+        "username" => "xxxx"},
       "date" => 1505118098,
-      "from" => %{"first_name" => "Firstname",
+      "from" => %{"first_name" => "Firstname",
         "id" => 208255328,
         "is_bot" => false,
         "language_code" => "en-IT",
         "last_name" => "Lastname",
-        "username" => "xxxx"},
+        "username" => "xxxx"},
       "message_id" => 1401,
-      "text" => "Hello!"},
-    "update_id" => 129745295}]}

+ "text" => "Hello!"}, + "update_id" => 129745295}]}

@@ -207,26 +207,26 @@

sendPhoto

-
Telegram.Api.request(token, "sendPhoto", chat_id: 876532, photo: {:file, "/tmp/photo.jpg"})
-Telegram.Api.request(token, "sendPhoto", chat_id: 876532, photo: {:file_content, photo, "photo.jpg"})

+
Telegram.Api.request(token, "sendPhoto", chat_id: 876532, photo: {:file, "/tmp/photo.jpg"})
+Telegram.Api.request(token, "sendPhoto", chat_id: 876532, photo: {:file_content, photo, "photo.jpg"})

Downloading files

To download a file from the telegram server you need a file_path pointer to the file. -With that you can download the file via Telegram.Api.file.

{:ok, res} = Telegram.Api.request(token, "sendPhoto", chat_id: 12345, photo: {:file, "example/photo.jpg"})
+With that you can download the file via Telegram.Api.file.

{:ok, res} = Telegram.Api.request(token, "sendPhoto", chat_id: 12345, photo: {:file, "example/photo.jpg"})
 # pick the 'file_obj' with the desired resolution
-[file_obj | _] = res["photo"]
+[file_obj | _] = res["photo"]
 # get the 'file_id'
-file_id = file_obj["file_id"]

+file_id = file_obj["file_id"]

getFile

-
{:ok, %{"file_path" => file_path}} = Telegram.Api.request(token, "getFile", file_id: file_id)
-{:ok, file} = Telegram.Api.file(token, file_path)

+
{:ok, %{"file_path" => file_path}} = Telegram.Api.request(token, "getFile", file_id: file_id)
+{:ok, file} = Telegram.Api.file(token, file_path)

@@ -240,12 +240,12 @@

sendMessage with keyboard

-
keyboard = [
-  ["A0", "A1"],
-  ["B0", "B1", "B2"]
-]
-keyboard_markup = %{one_time_keyboard: true, keyboard: keyboard}
-Telegram.Api.request(token, "sendMessage", chat_id: 876532, text: "Here a keyboard!", reply_markup: {:json, keyboard_markup})

Telegram Bot

+
keyboard = [
+  ["A0", "A1"],
+  ["B0", "B1", "B2"]
+]
+keyboard_markup = %{one_time_keyboard: true, keyboard: keyboard}
+Telegram.Api.request(token, "sendMessage", chat_id: 876532, text: "Here a keyboard!", reply_markup: {:json, keyboard_markup})

Telegram Bot

@@ -268,13 +268,13 @@

This mode can be used in a dev environment or if your bot doesn't need to "scale". Being in pull it works well behind a firewall (or behind a home internet router). Refer to the Telegram.Poller module docs for more info.

Telegram Client Config

The Telegram HTTP Client is based on Tesla.

The Tesla.Adapter and options should be configured via the [:tesla, :adapter] application environment key. -(ref. https://hexdocs.pm/tesla/readme.html#adapters)

For example, a good default could be:

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

a dependency should be added accordingly in your mix.exs:

 defp deps do
-    [
-      {:telegram, github: "visciang/telegram", tag: "xxx"},
-      {:hackney, "~> 1.18"},
+(ref. https://hexdocs.pm/tesla/readme.html#adapters)

For example, a good default could be:

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

a dependency should be added accordingly in your mix.exs:

 defp deps do
+    [
+      {:telegram, github: "visciang/telegram", tag: "xxx"},
+      {:hackney, "~> 1.18"},
       # ...
-    ]
-  end

+ ] + end

diff --git a/search.html b/search.html index 064ec24..867e045 100644 --- a/search.html +++ b/search.html @@ -5,12 +5,12 @@ - + - Search — telegram v1.2.2 + Search — telegram v1.2.3 @@ -52,7 +52,7 @@ telegram