Библиотека для работы с JSON-API мессенджера MAX на языке Elixir. Реализует основные методы для работы с ботом.
- Получение информации о боте
- Получение обновлений через long polling
- Отправка сообщений пользователям
- Полная поддержка обработки ошибок
- Конфигурируемые параметры запросов
- Подробные тесты с моками
Добавьте зависимость в ваш mix.exs:
def deps do
[
{:ex_max_bot, git: "https://github.com/d4rk5eed/ex_max_bot.git", tag: "v0.0.1"}
]
endЗатем выполните:
mix deps.gettoken = "ВАШ_ТОКЕН_БОТА"case ExMaxBot.get_bot_info(token) do
{:ok, bot_info} ->
IO.inspect(bot_info)
# %{user_id: 2345}
{:error, reason} ->
IO.error("Ошибка: #{reason}")
end# Получение обновлений с таймаутом 30 секунд и последней известной позицией
opts = [timeout: 30, marker: 0]
case ExMaxBot.get_updates(token, opts) do
{:ok, %{"marker" => marker, "updates" => updates}} ->
Enum.each(updates, fn update ->
if update["type"] == "message_created" do
IO.puts("Новое сообщение: #{update["text"]}")
end
end)
{:error, reason} ->
IO.error("Ошибка получения обновлений: #{reason}")
enduser_id = 12345 # можно получить через get_bot_info
message = "Привет! Это тестовое сообщение."
case ExMaxBot.send_message(token, user_id, message) do
{:ok, %{"message" => msg}} ->
IO.puts("Сообщение отправлено. ID: #{msg["body"]["mid"]}")
{:error, reason} ->
IO.error("Ошибка отправки: #{reason}")
endБиблиотека включает полный набор тестов:
mix testТесты используют моки для эмуляции различных сценариев работы API:
- Успешные запросы
- Ошибочные ответы API
- Сетевые ошибки
- Специфические коды состояния (200, 204, 404, 500)
Библиотека распространяется под лицензией MIT. См. файл LICENSE для получения подробной информации.
A client library for MAX messenger JSON API implemented in Elixir. Provides core functionality for bot integration.
- Get bot information
- Receive updates via long polling
- Send messages to users
- Comprehensive error handling
- Configurable request parameters
- Detailed tests with mocks
Add the dependency to your mix.exs:
def deps do
[
{:ex_max_bot, git: "https://github.com/d4rk5eed/ex_max_bot.git", tag: "v0.0.1"}
]
endThen run:
mix deps.gettoken = "YOUR_BOT_ACCESS_TOKEN"case ExMaxBot.get_bot_info(token) do
{:ok, bot_info} ->
IO.inspect(bot_info)
# %{user_id: 2345}
{:error, reason} ->
IO.error("Error: #{reason}")
endopts = [timeout: 30, marker: 0]
case ExMaxBot.get_updates(token, opts) do
{:ok, %{"marker" => marker, "updates" => updates}} ->
Enum.each(updates, fn update ->
if update["type"] == "message_created" do
IO.puts("New message: #{update["text"]}")
end
end)
{:error, reason} ->
IO.error("Error fetching updates: #{reason}")
enduser_id = 12345
message = "Hello! This is a test message."
case ExMaxBot.send_message(token, user_id, message) do
{:ok, %{"message_id" => msg_id}} ->
IO.puts("Message sent. ID: #{msg_id}")
{:error, reason} ->
IO.error("Sending error: #{reason}")
endThe library includes comprehensive tests:
mix testTests use mocks to simulate various API scenarios:
- Successful requests
- API error responses
- Network failures
- Specific status codes (200, 204, 404, 500)
Distributed under the MIT License. See LICENSE for more information.