49 lines
1.5 KiB
Ruby
49 lines
1.5 KiB
Ruby
# typed: true
|
|
# frozen_string_literal: true
|
|
T.bind(self, T.all(Rake::DSL, Object))
|
|
|
|
namespace :telegram do
|
|
desc "Start the Telegram bot for visual image search"
|
|
task bot: %i[set_logger_stdout environment] do |t, args|
|
|
puts "🤖 Starting Telegram Visual Search Bot".bold
|
|
puts "Press Ctrl+C to stop the bot cleanly".yellow
|
|
|
|
task = Tasks::TelegramBotTask.new
|
|
task.run
|
|
end
|
|
|
|
desc "Test Telegram bot configuration"
|
|
task test_config: %i[environment] do |t, args|
|
|
bot_token = GlobalState.get("telegram-bot-token")
|
|
|
|
if bot_token.nil?
|
|
puts "❌ Telegram bot token not configured".red
|
|
puts "Go to /state/telegram-config to configure the bot token."
|
|
exit 1
|
|
end
|
|
|
|
puts "✅ Telegram bot token is configured".green
|
|
puts "Token: #{bot_token[0..10]}..." + "*" * (bot_token.length - 11)
|
|
|
|
# Test connection to Telegram API
|
|
begin
|
|
require "telegram/bot"
|
|
|
|
Telegram::Bot::Client.run(bot_token) do |bot|
|
|
me = bot.api.get_me
|
|
puts "✅ Successfully connected to Telegram API".green
|
|
puts "Bot username: @#{me.username}" if me.username
|
|
puts "Bot name: #{me.first_name}"
|
|
puts "Bot ID: #{me.id}"
|
|
break # Exit after getting bot info
|
|
end
|
|
rescue Telegram::Bot::Exceptions::ResponseError => e
|
|
puts "❌ Failed to connect to Telegram API: #{e.message}".red
|
|
exit 1
|
|
rescue StandardError => e
|
|
puts "❌ Unexpected error: #{e.message}".red
|
|
exit 1
|
|
end
|
|
end
|
|
end
|