Update telegram bot task, user view, and type definitions

- Modified telegram bot task implementation
- Updated domain users index view
- Updated telegram-bot-ruby type shims
This commit is contained in:
Dylan Knutson
2025-08-15 05:59:11 +00:00
parent 2acf31c70a
commit b6e2e5e502
3 changed files with 37 additions and 6 deletions

View File

@@ -47,10 +47,22 @@ module Tasks
end
rescue Telegram::Bot::Exceptions::ResponseError => e
log("❌ Telegram API error: #{e.message}")
log("Please check your bot token configuration.")
if e.error_code == 429
retry_after = e.response.dig("parameters", "retry_after")&.to_i || 10
log(
"❌ Rate limit exceeded, waiting #{retry_after} seconds and trying again.",
)
sleep(retry_after)
retry
else
raise e
end
rescue Interrupt
log("User interrupted the bot")
rescue StandardError => e
log("❌ Unexpected error: #{e.message}")
log("Backtrace: #{e.backtrace&.first(5)&.join("\n")}")
raise e
ensure
log("🛑 Telegram bot stopped")
end
@@ -75,7 +87,18 @@ module Tasks
).void
end
def handle_message(bot, message)
return unless message.photo || message.document || message.video
unless message.photo || message.document || message.video
bot.api.send_message(
chat_id: message.chat.id,
text: [
"👋 Hi! I'm a visual search bot.",
"📷 Send me an <b>image</b> or <b>video</b> and I'll search for similar content in my database.",
].join("\n\n"),
parse_mode: "HTML",
reply_to_message_id: message.message_id,
)
return
end
# Start timing the total request
total_request_timer = Stopwatch.start
@@ -441,7 +464,7 @@ module Tasks
elsif message.document
# Check if document is an image
content_type = message.document.mime_type
if content_type&.start_with?("image/")
if content_type&.start_with?("image/") || content_type == "video/mp4"
message.document
else
log("❌ Document is not an image or video: #{content_type}")

View File

@@ -48,8 +48,10 @@
<div class="font-medium text-slate-900"><%= user.name_for_view %></div>
<% if user.is_a?(Domain::User::BlueskyUser) %>
<div class="text-sm text-slate-500">@<%= user.handle %></div>
<% elsif user.is_a?(Domain::User::FaUse) %>
<div class="text-sm text-slate-500">@<%= user.url_name %></div>
<% elsif user.is_a?(Domain::User::FaUser) %>
<div class="text-sm text-slate-500"><%=user.sigil_for_view%><%= user.url_name %></div>
<% else %>
<div class="text-sm text-slate-500"><%= user.name_for_view %></div>
<% end %>
</div>
<% end %>

View File

@@ -25,10 +25,16 @@ module Telegram
params(
chat_id: T.untyped,
text: String,
parse_mode: T.nilable(String),
reply_to_message_id: T.untyped,
).returns(Telegram::Bot::Types::Message)
end
def send_message(chat_id:, text:, reply_to_message_id: nil)
def send_message(
chat_id:,
text:,
parse_mode: nil,
reply_to_message_id: nil
)
end
sig do