Documentation
¶
Index ¶
- Variables
- func BindToInstance(inst *object.Instance, builtins map[string]*object.Builtin)
- func BuildCtxDict(c *Ctx) *object.Dict
- func EncodeBase64(data []byte) string
- func ParseCommand(text string) (cmd string, args []string)
- func SharedBuiltins() map[string]*object.Builtin
- type Bot
- type Ctx
- func (c *Ctx) Answer(goCtx context.Context, text string) error
- func (c *Ctx) Download(goCtx context.Context) ([]byte, error)
- func (c *Ctx) Reply(goCtx context.Context, text string, opts *SendOptions) error
- func (c *Ctx) ReplyRich(goCtx context.Context, msg *RichMessage) error
- func (c *Ctx) Typing(goCtx context.Context) error
- type FileInfo
- type Handler
- type Keyboard
- type KeyboardButton
- type RichMessage
- type ScriptSender
- type SendOptions
- type Sender
- type Update
Constants ¶
This section is empty.
Variables ¶
var KeyboardBuiltin = &object.Builtin{ Fn: func(ctx context.Context, kwargs object.Kwargs, args ...object.Object) object.Object { if err := errors.ExactArgs(args, 1); err != nil { return err } return args[0] }, HelpText: `keyboard(rows) - Build a platform-agnostic button keyboard; rows is a list of lists of {text, data} or {text, url} dicts`, }
KeyboardBuiltin is a free-standing (non-client-bound) builtin that passes rows through. Added directly to each platform library so it is available as telegram.keyboard(...) / discord.keyboard(...) without being bound to a client instance.
Functions ¶
func BindToInstance ¶
BindToInstance injects all shared builtins as instance fields so scripts can call client.command(...), client.run(), etc. Each builtin is wrapped to prepend the instance as args[0], matching the module-level calling convention.
func BuildCtxDict ¶
BuildCtxDict builds the Scriptling dict passed to handlers.
func EncodeBase64 ¶
EncodeBase64 encodes bytes to a base64 string.
func ParseCommand ¶
ParseCommand splits text into command + args if it starts with "/".
func SharedBuiltins ¶
SharedBuiltins returns the map of Scriptling builtins that are identical across all platforms.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot holds the routing table and dispatch logic shared across all platform clients. Platform clients embed *Bot and call dispatch after normalising a raw event.
func (*Bot) Dispatch ¶
Dispatch routes a normalised Update to the appropriate registered handler. Called by the platform client after normalising a raw event.
func (*Bot) OnCallback ¶
OnCallback registers a handler for callback (button) events whose data has the given prefix. Use "" to match all callbacks.
type Ctx ¶
Ctx is passed to every handler. It wraps the Update and provides reply helpers so handlers don't need to manage dest/token themselves.
func (*Ctx) Answer ¶
Answer acknowledges a callback (button press). On Telegram: calls answerCallbackQuery (toast notification). On Discord: responds to the interaction (visible reply if text non-empty, silent ack if empty).
type FileInfo ¶
type FileInfo struct {
ID string
Name string
MimeType string
Size int64
URL string // download URL (Discord/Slack); empty for Telegram (use ID)
}
FileInfo holds normalised file metadata.
type Keyboard ¶
type Keyboard [][]KeyboardButton
Keyboard is a platform-agnostic button grid. Each inner slice is a row of buttons.
type KeyboardButton ¶
type KeyboardButton struct {
Text string
Data string // callback_data (Telegram) / custom_id (Discord)
URL string // link button — opens URL instead of firing a callback
}
KeyboardButton is a single button in a platform-agnostic keyboard. If URL is set it is a link button; otherwise Data is the callback payload.
type RichMessage ¶
type RichMessage struct {
Title string // bold heading
Body string // main text
Color string // "red", "green", "blue", hex "#ff0000" — Discord embed color; ignored elsewhere
Image string // URL or file path — attached as photo/embed image
URL string // click-through link — Discord embed URL; ignored elsewhere
}
RichMessage is a platform-agnostic rich content message. Each client translates it to the native format.
type ScriptSender ¶
type ScriptSender interface {
Sender
// Bot framework accessors — called by the shared library functions
BotCommand(name, helpText string, h Handler)
BotOnCallback(prefix string, h Handler)
BotOnMessage(h Handler)
BotOnFile(h Handler)
BotAuth(h Handler)
BotRun(ctx context.Context) error
}
ScriptSender is the interface the shared Scriptling library calls on the wrapped client instance. It mirrors Sender but operates on the Scriptling object.Instance that scripts hold.
func ClientFrom ¶
ClientFrom extracts the ScriptSender from args[0] (the instance self).
type SendOptions ¶
SendOptions carries optional send parameters.
type Sender ¶
type Sender interface {
SendMessage(ctx context.Context, dest, text string, opts *SendOptions) error
SendRichMessage(ctx context.Context, dest string, msg *RichMessage) error
EditMessage(ctx context.Context, dest, msgID, text string) error
DeleteMessage(ctx context.Context, dest, msgID string) error
SendFile(ctx context.Context, dest, source, fileName, caption string, isB64 bool) error
SendTyping(ctx context.Context, dest string) error
AckCallback(ctx context.Context, id, token, text string) error
Download(ctx context.Context, ref string) ([]byte, error)
Platform() string
Capabilities() []string
}
Sender is the interface the shared bot calls back into the platform client for.
type Update ¶
type Update struct {
Dest string
MessageID string
UserID string
UserName string
Text string
Command string // "/start" if text begins with /, else ""
Args []string // words after the command
IsCallback bool
CallbackID string
CallbackToken string // Discord/Slack interaction token; empty on Telegram
CallbackData string
File *FileInfo
}
Update is the normalised event passed to all handlers regardless of platform. Dest is the reply target — chat_id (Telegram) or channel_id (Discord/Slack) as a string.