v0.5.0

Reply Handler

Last updated


This page explains when the ReplyHandler runs, where its return value is sent, and how panics are handled.

Contract


  1. type ReplyHandler func(ctx context.Context, input Input) string

Each platform package declares this type with its own Input. Reply(handler) stores one handler; calling it again replaces the previous one. The SDK goroutine that received the event calls the handler and waits for it, so a slow handler delays that event's reply.
Return valueResult
Non-empty stringSent as a plain-text reply (see targets below)
""Nothing is sent; use this when the handler sends media, interactive prompts, or several messages itself

What triggers the handler


PlatformEvents
TelegramEvery message update (text, caption, photo, document; groups included, no mention check); SendSelect button taps; SendMultiSelect Done taps
DiscordEvery MessageCreate except the bot's own messages; SendInput modal submits; SendSelect / SendMultiSelect picks
LINEMessage events of type text, image, video, audio, and file (groups and rooms included, no mention check)

Other event types are ignored.

Where the reply goes


PlatformTriggerReply target
TelegramMessageSame chat, as a reply to the user's message
TelegramSelect / multi-selectSame chat, as a reply to the prompt message
DiscordMessageSame channel, as a reply to the user's message
DiscordModal submit / selectReply to the replyTo passed to SendInput / SendSelect; the prompt message when replyTo was ""
LINEAnyReplyMessage with the event's one-time reply token

Handler context


Platformctx passed to the handler
TelegramContext supplied by the polling loop (derived from the Start context)
DiscordThe bot's internal context created in Start; events received while not running are dropped
LINEPer webhook request: the bot context with a 30-second timeout, shared by every event in that request

Panics


A panic inside the handler is recovered and logged with slog.Warn("reply handler panic"); the SDK goroutine keeps running.
PlatformPanic value is a stringAny other panic value
TelegramThat string is sent as the replyNothing is sent
LINEThat string is sent as the replyNothing is sent
DiscordNothing is sentNothing is sent


中文