ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - ccsteam/ex-telegram-client: An Elixir wrapper which communicates with the Telegram-CLI.
An Elixir wrapper which communicates with the Telegram-CLI. - ccsteam/ex-telegram-client
Visit Site

GitHub - ccsteam/ex-telegram-client: An Elixir wrapper which communicates with the Telegram-CLI.

GitHub - ccsteam/ex-telegram-client: An Elixir wrapper which communicates with the Telegram-CLI.

Telegram Client

A Elixir wrapper that communicates with the Telegram-CLI.

Installation

If available in Hex, the package can be installed as:

  • Add tg_client to your list of dependencies in mix.exs:
def deps do
  [{:tg_client, "~> 0.3.0"]
end
  • Ensure tg_client is started before your application:
def application do
  [applications: [:tg_client]]
end

Usage

  • Write your own EventHandler module.
defmodule EventHandler do
  use GenEvent
  require Logger

  def handle_event(event, state) do
    Logger.debug "Unknown Event: " <> inspect(event)
    {:ok, state}
  end
end
  • Set config.
config :tg_client,
  daemon: "/usr/local/telegram-cli",
  key: "/usr/local/share/telegram-cli/tg-server.pub",
  session_env_path: "/tmp/telegram-cli/sessions",
  default_pool_size: 5,
  default_pool_max_overflow: 10,
  pool_name: :event_handler,
  event_handler: {TgClient.Event.Handler, size: 10, max_overflow: 10}

Authorization

  • Start session
{:ok, _pid} = TgClient.Session.start_link(79251008050)
  • Start session under Supervisor
{:ok, _pid} = TgClient.start_session(79251008050)
  • Connect to CLI
{:ok, :connected} = TgClient.Session.connect(79251008050)
  • Check session status
{:ok, status} = TgClient.Session.current_status(79251008050)

when status in [:offline, :waiting_for_confirmation, :waiting_for_password, :connected]

  • Confirm
:ok = TgClient.Session.confirm(79251008050, 22284)

has effect only if status is :waiting_for_confirmation

  • Put password
:ok = TgClient.Session.put_password(79251008050, "secret_password")

has effect only if status is :waiting_for_password

Commands

all commands has effect only if status is :connected

  • Dialog list
{:ok, response} = TgClient.Session.send_command(79251008050, "dialog_list", [])

when response is:

[
   {
      \"admin\":{
         \"id\":\"$01000000000000000000000000000000\",
         \"peer_type\":\"user\",
         \"peer_id\":0,
         \"print_name\":\"user#0\"
      },
      \"id\":\"$02000000e47cd0010000000000000000\",
      \"flags\":1,
      \"peer_type\":\"chat\",
      \"peer_id\":30440676,
      \"print_name\":\"йцу\",
      \"title\":\"йцу\",
      \"members_num\":3
   },
   {
      \"id\":\"$010000005d7c21050ddae73d36d42000\",
      \"peer_type\":\"user\",
      \"flags\":196609,
      \"peer_id\":86080605,
      \"first_name\":\"Собакин\",
      \"print_name\":\"Собакин_Кот\",
      \"when\": \"2016-08-31 22:45:43\",
      \"phone\":\"7800400300\",
      \"last_name\":\"Кот\"
   }
]
  • Contact list
{:ok, response} = TgClient.Session.send_command(79251008050, "contact_list", [])

when response is:

[
   {
      \"id\":\"$01000000946c090ddf6ba9457ce8c248\",
      \"peer_type\":\"user\",
      \"flags\":196609,
      \"peer_id\":218721428,
      \"first_name\":\"Дмитрий\",
      \"print_name\":\"Дмитрий_Негру\",
      \"when\": \"2016-05-20 18:12:40\",
      \"phone\":\"7800400300\",
      \"last_name\":\"Негру\"
   }
]
  • Send message [peer, text]
{:ok, response} = TgClient.Session.send_command(79251008050, "msg", ["$010000001az3av003d8059e845e429e1", "hello"])

when response is:

{
   \"result\":\"SUCCESS\"
}
  • Message history [peer, limit, offset]
{:ok, response} = TgClient.Session.send_command(79251008050, "history", ["$010000001az3av003d8059e845e429e1", "5", "0"])

when response is:

[
   {
      \"text\":\"hello\",
      \"unread\":true,
      \"event\":\"message\",
      \"id\":\"010000001ae3ab00496c0100000000003d8059e845e429e1\",
      \"from\":{
         \"username\":\"badrequest\",
         \"id\":\"$010000001ae3ab003d8059e845e429e1\",
         \"peer_type\":\"user\",
         \"flags\":524289,
         \"peer_id\":11264794,
         \"first_name\":\"Andrew\",
         \"print_name\":\"Andrew_Noskov\",
         \"when\":\"2016-09-01 14:06:33\",
         \"phone\":\"79251008050\",
         \"last_name\":\"Noskov\"
      },
      \"flags\":16643,
      \"to\":{
         \"username\":\"badrequest\",
         \"id\":\"$010000001ae3ab003d8059e845e429e1\",
         \"peer_type\":\"user\",
         \"flags\":524289,
         \"peer_id\":11264794,
         \"first_name\":\"Andrew\",
         \"print_name\":\"Andrew_Noskov\",
         \"when\":\"2016-09-01 14:06:33\",
         \"phone\":\"79251008050\",
         \"last_name\":\"Noskov\"
      },
      \"out\":true,
      \"service\":false,
      \"date\":1472727693
   }
]
  • Create secret chat [peer]
{:ok, response} = TgClient.Session.send_command(79251008050, "create_secret_chat", ["$010000001az3av003d8059e845e429e1"])

when response is:

{
   \"flags\":1,
   \"print_name\":\"!_Polya\",
   \"id\":\"$010000001az3av003d8059e845e429e1\",
   \"peer_type\":\"encr_chat\",
   \"peer_id\":1901915394,
   \"user\":{
      \"flags\":196609,
      \"id\":\"$010000001az3av003d8059e845e429e1\",
      \"print_name\":\"Polya\",
      \"peer_type\":\"user\",
      \"last_name\":\"\",
      \"peer_id\":65370635,
      \"first_name\":\"Polya\",
      \"when\":\"2016-09-01 13:35:34\",
      \"phone\":\"79251008050\"
   }
}

Configuration

  • Set config or pass default attributes
config :tg_client,
  daemon: "/usr/local/telegram-cli",
  key: "/usr/local/share/telegram-cli/tg-server.pub",
  session_env_path: "/tmp/telegram-cli/sessions",
  default_pool_size: 5,
  default_pool_max_overflow: 10,
  pool_name: :event_handler,
  event_handler: {TgClient.Event.Handler, size: 10, max_overflow: 10}

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory