Phase 1: quick flow fixes

- One message per job: the status message is deleted once the file is
  sent, or shortened to "Sent." when Telegram keeps it.
- No reply quotes in private chats; groups keep them.
- Queue status only mentions the position when the wait is above
  QUEUE_NOTICE_THRESHOLD_SECONDS or somebody is ahead. Status edits are
  throttled to one per 2.5 s per message; a state that arrives too soon
  is shown later instead of dropped. The wait estimate is 0 with a free
  slot.
- Caption with title (uploader and date when generic), uploader,
  duration, a short source link without tracking parameters and an
  optional "via @bot" line (CAPTION_ATTRIBUTION). Uploaded videos get a
  320 px JPEG thumbnail; merged MP4s are written with faststart.
- Buttons under the result: Audio (MP3), Other quality, Thumbnail,
  Delete. Requester only in groups.
- Language resolved once per update and passed in the context. A
  fallback to English is logged as a bug; a test walks every screen in
  Spanish and Dutch. Language picker on the first /start.
- Sizes without a zero decimal ("50 MB").
- First link of a new user shows the card once and sets the default to
  "best that fits my limit".
- Errors offer the next step (Try again, Smaller quality, Upgrade, Open
  app); passing lookup failures are retried once.
- Up to MULTI_LINK_MAX links per message; a link sent a moment ago gets
  "already sent" with a Send again button.
- Mini App menu button, labelled per private chat in the user's
  language.
- Personal /settings in private chats with an "Add me to a group"
  button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 20:08:58 +00:00
co-authored by Claude Opus 5.5
parent 3c153af97f
commit 6843053582
52 changed files with 3369 additions and 271 deletions
+1
View File
@@ -36,6 +36,7 @@ type API interface {
EditMessageWidgetData(ctx context.Context, params *telego.EditMessageWidgetDataParams) error
AnswerWidgetQuery(ctx context.Context, params *telego.AnswerWidgetQueryParams) error
GetChatMember(ctx context.Context, params *telego.GetChatMemberParams) (telego.ChatMember, error)
SetChatMenuButton(ctx context.Context, params *telego.SetChatMenuButtonParams) error
}
var _ API = (*telego.Bot)(nil)
+24 -2
View File
@@ -118,6 +118,7 @@ type Server struct {
failures map[string][]scriptedError
members map[string]string
sent map[int]map[string]any // messages the bot sent, by message ID
langs map[int64]string // the language_code each user last sent
// confirmed is the highest update ID the bot acknowledged by asking for
// a later offset. Like Telegram, confirmed updates are never sent again.
confirmed int
@@ -282,10 +283,31 @@ func (s *Server) PushMessage(chatID, userID int64, text string, opts ...MsgOpt)
for _, o := range opts {
o(msg)
}
// Telegram sends the language of the user's app with every update, so
// later button presses of this user carry the same one.
if code, ok := msg["from"].(map[string]any)["language_code"].(string); ok {
s.langOf()[userID] = code
}
s.pushLocked(map[string]any{"message": msg})
return s.msgID
}
// langOf is the language_code each user last sent. Callers hold s.mu.
func (s *Server) langOf() map[int64]string {
if s.langs == nil {
s.langs = map[int64]string{}
}
return s.langs
}
// userLang is the language_code to send for a user. Callers hold s.mu.
func (s *Server) userLang(userID int64) string {
if code, ok := s.langOf()[userID]; ok {
return code
}
return "en"
}
// PushCallback queues a button press on a message.
func (s *Server) PushCallback(chatID, userID int64, messageID int, data string) string {
s.mu.Lock()
@@ -304,7 +326,7 @@ func (s *Server) PushCallback(chatID, userID int64, messageID int, data string)
}
s.pushLocked(map[string]any{"callback_query": map[string]any{
"id": id,
"from": map[string]any{"id": userID, "is_bot": false, "first_name": "User", "language_code": "en"},
"from": map[string]any{"id": userID, "is_bot": false, "first_name": "User", "language_code": s.userLang(userID)},
"chat_instance": "ci",
"data": data,
"message": msg,
@@ -321,7 +343,7 @@ func (s *Server) PushWidgetQuery(chatID, userID int64, messageID int, data strin
id := "wq" + strconv.Itoa(s.msgID)
s.pushLocked(map[string]any{"widget_query": map[string]any{
"id": id,
"from": map[string]any{"id": userID, "is_bot": false, "first_name": "User", "language_code": "en"},
"from": map[string]any{"id": userID, "is_bot": false, "first_name": "User", "language_code": s.userLang(userID)},
"chat": chatObject(chatID),
"message_id": messageID,
"chat_instance": "ci" + strconv.FormatInt(chatID, 10),