-
Notifications
You must be signed in to change notification settings - Fork 0
Home
T0yB0y edited this page Apr 12, 2026
·
1 revision
- Ruby ≥ 3.2
- Токен бота (кабинет MAX → Чат-боты → Интеграция → Получить токен)
В Gemfile:
gem 'max_bot', '~> 0.3'Затем:
bundle installrequire 'max_bot'
Max::Bot.configure do |config|
config.connection_timeout = 95 # секунды (должно быть > long-poll timeout)
config.connection_open_timeout = 20
config.adapter = Faraday.default_adapter
end- Откройте dev.max.ru
- Перейдите в раздел Чат-боты → Интеграция
- Нажмите Получить токен
- Задайте переменную окружения:
export MAX_BOT_TOKEN="ваш_токен"require 'max_bot'
api = Max::Bot::Api.new(ENV.fetch('MAX_BOT_TOKEN'))
# Отправить сообщение в группу
api.send_message('Привет!', chat_id: 123)
# Отправить в личку
api.send_message('Привет!', user_id: 456)api = Max::Bot::Api.new(ENV.fetch('MAX_BOT_TOKEN'))
Max::Bot::Client.new(
api.token,
timeout: 30,
types: %w[message_created],
logger: Logger.new($stdout)
).run do |update|
next unless Max::Bot::UpdateHelpers.message_created?(update)
message = Max::Bot::UpdateHelpers.message_from(update)
text = Max::Bot::UpdateHelpers.message_text(message)
dest = Max::Bot::UpdateHelpers.message_destination(message)
next if text.to_s.empty? || dest.nil?
kind, id = dest
api.send_message("Echo: #{text}", kind => id)
endВ репозитории есть готовый пример:
export MAX_BOT_TOKEN="your_token"
bundle exec ruby examples/polling_bot.rb