Skip to content

witer33/elixirtgapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tgapi

Efficient, concurrent and lightweight Telegram Bot API framework written in Elixir

Installation

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

def deps do
  [
    {:tgapi, "~> 0.2.0"}
  ]
end

A clean example

token = "TOKEN"
botClient = Tgapi.client(token)

Tgapi.start(token, fn update ->
  case update do
    %{"message" => %{"text" => "/start", "chat" => %{"id" => chatID}}} -> 
      botClient.(:sendMessage).(
        chat_id: chatID,
        text: "helo",
        reply_markup: Tgapi.inline_keyboard([[%{text: "hey", callback_data: "nice"}]])
      )
    
    %{"message" => %{"text" => _, "chat" => %{"id" => chatID}}} -> 
      botClient.(:sendMessage).(chat_id: chatID, text: "?")
    
    _ -> nil
  end
end)

Process.sleep(:infinity)

Telegram method call

Tgapi.client(token).(:method).(params)

Example

Tgapi.client("123456789:d2FpdCB3aHkgZGlkIHlvdSBkZWNvZGU").(:sendMessage).(
  chat_id: -348924427,
  text: "how are you?"
)

Storage system

PUT

Tgapi.Session.put(key, value)

Example

Tgapi.Session.put(:name, "Alex")

GET

Tgapi.Session.get(key)

Example

name = Tgapi.Session.get(:name)

DELETE

Tgapi.Session.delete(key)

Example

Tgapi.Session.delete(:name)

About

Efficient, concurrent and lightweight Telegram Bot API framework written in Elixir.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages