Efficient, concurrent and lightweight Telegram Bot API framework written in Elixir
The package can be installed
by adding tgapi
to your list of dependencies in mix.exs
:
def deps do
[
{:tgapi, "~> 0.2.0"}
]
end
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)
Tgapi.client(token).(:method).(params)
Tgapi.client("123456789:d2FpdCB3aHkgZGlkIHlvdSBkZWNvZGU").(:sendMessage).(
chat_id: -348924427,
text: "how are you?"
)
Tgapi.Session.put(key, value)
Tgapi.Session.put(:name, "Alex")
Tgapi.Session.get(key)
name = Tgapi.Session.get(:name)
Tgapi.Session.delete(key)
Tgapi.Session.delete(:name)