Bots
Other3 providersChat-bot subsystem — one command/message registry across platforms.
togo install togo-framework/botInstall
togo install togo-framework/bot
togo install togo-framework/bot-telegram # or bot-discord / bot-slack
bot is togo's chat-bot subsystem. It defines a small Bot driver contract
plus a command / message handler registry so your app registers bot commands
once and they work across Telegram, Discord and Slack. Real platforms ship as
driver plugins; select one with the BOT_DRIVER env var.
Platform | Plugin | Library |
|---|---|---|
| Telegram | bot-telegram | go-telegram-bot-api |
| Discord | bot-discord | discordgo |
| Slack | bot-slack | slack-go (Socket Mode) |
Usage
Blank-import the base and a driver, then register handlers:
import (
"context"
_ "github.com/togo-framework/bot"
_ "github.com/togo-framework/bot-telegram"
"github.com/togo-framework/bot"
)
func init() {
// /weather <city>
bot.OnCommand("weather", func(ctx context.Context, b *bot.Service, m bot.Message) (string, error) {
if len(m.Args) == 0 {
return "usage: /weather <city>", nil
}
return "☀️ sunny in " + m.Args[0], nil
})
// Catch-all for non-command messages
bot.OnMessage(func(ctx context.Context, b *bot.Service, m bot.Message) (string, error) {
return "you said: " + m.Text, nil
})
}
Pick the platform at runtime:
BOT_DRIVER=telegram
TELEGRAM_BOT_TOKEN=123456:ABC...A built-in /ping → pong 🏓 command is registered out of the box.
Sending proactively
From anywhere you have the kernel:
if svc, ok := bot.FromKernel(k); ok {
_ = svc.Send(ctx, channelID, "deploy finished ✅")
}
Contract
type Bot interface {
Start(ctx context.Context) error // receive loop (blocks)
Stop() error // shut down
Send(ctx context.Context, channel, msg string) error
}
type Handler func(ctx context.Context, b *Service, m Message) (string, error)
func RegisterDriver(name string, f DriverFactory) // drivers call this in init()
func OnCommand(name string, h Handler) // register "/name"
func OnMessage(h Handler) // register a catch-all
func FromKernel(k *togo.Kernel) (*Service, bool) // grab the runtime
Writing a new platform driver? Implement Bot, call bot.RegisterDriver in
init(), and invoke the dispatch func you're handed for every inbound message.
See bot-telegram for the canonical ~120-line example.
License
MIT © togo-framework
<div align="center"> <h3>Premium sponsors</h3> <p> <a href="https://id8media.com"><strong>ID8 Media</strong></a> · <a href="https://one-studio.co"><strong>One Studio</strong></a> </p> <p><sub>Support togo — <a href="https://github.com/sponsors/fadymondy">become a sponsor</a>.</sub></p> </div>