Module: TelegramBotEngine
- Defined in:
- lib/telegram_bot_engine.rb,
lib/telegram_bot_engine/engine.rb,
lib/telegram_bot_engine/version.rb,
lib/telegram_bot_engine/dispatch.rb,
lib/telegram_bot_engine/registry.rb,
app/models/telegram_bot_engine/bot.rb,
lib/telegram_bot_engine/authorizer.rb,
app/models/telegram_bot_engine/event.rb,
lib/telegram_bot_engine/configuration.rb,
app/jobs/telegram_bot_engine/delivery_job.rb,
lib/telegram_bot_engine/webhook_registrar.rb,
app/models/telegram_bot_engine/allowed_user.rb,
app/models/telegram_bot_engine/subscription.rb,
lib/telegram_bot_engine/subscriber_commands.rb,
app/jobs/telegram_bot_engine/application_job.rb,
app/controllers/telegram_bot_engine/admin/base_controller.rb,
app/controllers/telegram_bot_engine/admin/bots_controller.rb,
app/controllers/telegram_bot_engine/admin/events_controller.rb,
app/controllers/telegram_bot_engine/admin/allowlist_controller.rb,
app/controllers/telegram_bot_engine/admin/dashboard_controller.rb,
app/controllers/telegram_bot_engine/admin/subscriptions_controller.rb
Defined Under Namespace
Modules: Admin, Registry, SubscriberCommands, WebhookRegistrar Classes: AllowedUser, ApplicationJob, Authorizer, Bot, Configuration, DeliveryJob, Dispatch, Engine, Event, Subscription
Constant Summary collapse
- VERSION =
"0.6.1"
Class Method Summary collapse
-
.broadcast(text, bot: nil, **options) ⇒ Object
Broadcast to all active subscribers via background jobs, delivered through ‘bot`.
-
.client_for(bot) ⇒ Object
The Telegram::Bot::Client for a Bot record, resolved from the DB and cached by bot id (token-rotation safe).
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
-
.notify(chat_id:, text:, bot: nil, **options) ⇒ Object
Send to a specific chat via background job, delivered through ‘bot`.
- .reset_config! ⇒ Object
Class Method Details
.broadcast(text, bot: nil, **options) ⇒ Object
Broadcast to all active subscribers via background jobs, delivered through ‘bot`. `bot:` omitted ⇒ the default bot ⇒ today’s behavior, unchanged (docs/0001 §3.3).
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/telegram_bot_engine.rb', line 35 def broadcast(text, bot: nil, **) bot ||= TelegramBotEngine::Bot.default subscriber_count = 0 TelegramBotEngine::Subscription.active.for_bot(bot).find_each do |subscription| TelegramBotEngine::DeliveryJob.perform_later( bot.id, subscription.chat_id, text, ) subscriber_count += 1 end TelegramBotEngine::Event.log( event_type: "delivery", action: "broadcast", bot_id: bot.id, details: { bot: bot.slug, subscriber_count: subscriber_count, text_preview: text.to_s[0, 100] } ) end |
.client_for(bot) ⇒ Object
The Telegram::Bot::Client for a Bot record, resolved from the DB and cached by bot id (token-rotation safe). See TelegramBotEngine::Registry / docs/0001 §3.2.
29 30 31 |
# File 'lib/telegram_bot_engine.rb', line 29 def client_for(bot) Registry.client_for(bot) end |
.config ⇒ Object
19 20 21 |
# File 'lib/telegram_bot_engine.rb', line 19 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
15 16 17 |
# File 'lib/telegram_bot_engine.rb', line 15 def configure yield(config) end |
.notify(chat_id:, text:, bot: nil, **options) ⇒ Object
Send to a specific chat via background job, delivered through ‘bot`. `bot:` omitted ⇒ the default bot ⇒ today’s behavior, unchanged (docs/0001 §3.3).
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/telegram_bot_engine.rb', line 57 def notify(chat_id:, text:, bot: nil, **) bot ||= TelegramBotEngine::Bot.default TelegramBotEngine::DeliveryJob.perform_later(bot.id, chat_id, text, ) TelegramBotEngine::Event.log( event_type: "delivery", action: "notify", chat_id: chat_id, bot_id: bot.id, details: { bot: bot.slug, text_preview: text.to_s[0, 100] } ) end |
.reset_config! ⇒ Object
23 24 25 |
# File 'lib/telegram_bot_engine.rb', line 23 def reset_config! @config = Configuration.new end |