v0.5.0

Status Messages

Last updated


SendStatus and FinishStatus keep one editable "thinking" message per Telegram chat or Discord channel while your handler works. LINE has no status API.

Signatures


  1. // core/telegram
  2. func (b *Bot) SendStatus(ctx context.Context, chatID int64, replyTo int, text string, opts ...StatusOption) error
  3. func (b *Bot) FinishStatus(ctx context.Context, chatID int64) error
  4. // core/discord
  5. func (b *Bot) SendStatus(ctx context.Context, channelID, replyTo, text string, opts ...StatusOption) error
  6. func (b *Bot) FinishStatus(ctx context.Context, channelID string) error

Options


OptionPlatformEffectDefault
WithStatusEmoji(emoji)Telegram, DiscordReaction added to the replyTo message🤔 (also used when emoji is "")
WithStatusSendType(t SendType)TelegramParse mode for the status text (TypeMarkdown = MarkdownV2, TypeHTML)plain text

The emoji and parse mode are captured by the first SendStatus call for that chat or channel; options passed later are ignored. replyTo is taken from the latest call until the status message has been created, then fixed. On Telegram the emoji must be one Telegram allows as a reaction; the library does not validate it.

Update flow


StepBehavior
First flushAdds the reaction to replyTo (failure is only logged), then sends the status text as a reply to replyTo. With replyTo zero / "", both the reaction and the reply link are skipped
Later callsEdit the same message
RateAt most one send or edit per second per chat/channel. A call inside that window stores the text and a timer flushes the latest text; intermediate texts are dropped
Same textSkipped without an API call. Telegram's message is not modified error is also ignored
Return valueThe send/edit error when the call flushed immediately; nil when the text was queued

Finish


FinishStatus stops the pending timer, removes the bot's reaction from replyTo (failure is only logged), and deletes the status message. It returns nil when there is no status for that chat or channel.
If a send or edit is in flight, FinishStatus waits for it and the cleanup runs right after it; it returns early with ctx.Err() if your ctx ends first. Close() stops all status timers without deleting messages.

Example


  1. bot.Reply(func(ctx context.Context, in telegram.Input) string {
  2. bot.SendStatus(ctx, in.ChatID, in.MessageID, "Searching...")
  3. result := work(ctx)
  4. bot.SendStatus(ctx, in.ChatID, in.MessageID, "Writing answer...")
  5. bot.FinishStatus(ctx, in.ChatID)
  6. return result
  7. })


中文