- plugin.yaml generated by summer plugin:manifest (README name kept) - TestPluginManifest guards it with kiosk.CheckT - require SummerCMS v0.6.0, the framework minimum in plugin.yaml - require sm-chat-plugin v0.1.3 instead of v0.0.0, so plugin.yaml carries a released minimum (raises sm-user-plugin to v0.1.2, which chat v0.1.3 requires)
Chat bots
A compiled slash-command plugin for SummerCMS: a host-registered command catalog, JWT-actor dispatch, and a deny-all bot-auth seam.
import _ "git.golem15.com/golem15/sm-chatbots-plugin"
Name: Bots on the shore; slash commands stay after the tide.
Module git.golem15.com/golem15/sm-chatbots-plugin, package chatbots, plugin ID golem15.chatbots, requires golem15.chat and golem15.user. Display name Chat bots / Boty czatu.
Overview
The plugin ports the WinterCMS Golem15.ChatBots plugin. Hosts register slash commands on classes.Registry; classes.Dispatcher parses a trigger from {input} and runs the command as the authenticated actor. The invoker id always comes from the JWT, never from the request body.
Table (PHP names, one idempotent baseline migration 202610180001_create_golem15_chatbots_baseline, every statement IF NOT EXISTS):
golem15_chatbots_bot_flags: per-useris_botdisplay flag (models.BotFlag), unique onuser_id(chatbots_bot_flags_user_unique).
Production Boot registers only /help via RegisterBuiltin. Hosts call Registry.Register for their own commands; Register rejects the reserved trigger help and duplicates.
The generic JSON API is chatbots.APIPrefix (/_chatbots/api/v1). Routes sit behind jwt.auth and the named bucket chatbots-api (120/min). The app mounts that guard; this plugin only names it. Frontend users only.
Features
- SlashCommand registry.
classes.Registry.Registerrejects reservedhelpand duplicates.RegisterBuiltinskips the reserved check and installsHelpCommand. - Dispatcher.
Dispatcher.Dispatch(input, actor, ctx)parses the trigger; unrecognized input, or a command notIsAvailablefor the actor, returns nil (fall through). Modesephemeralandannounce. - Deny-all BotAuthResolver.
classes.DenyAllResolve returns no user and IsElevated is false.Plugin.SetBotAuthResolverinstalls the host; nil becomes DenyAll. Boot Warns while the default remains. - HTTP API.
GET /commandslists commandsIsAvailablefor the JWT actor.POST /dispatchbody{input}runs the command as that actor; a command notIsAvailablefor the JWT actor is refused with the same 422unknown_commandas an unknown trigger. The generic API staysjwt.authfor humans; a host may later resolve a bot bearer throughSetBotAuthResolver. Deny-all means there is no bot principal until the host installs one. - Chat and User only.
Requires()isgolem15.chatandgolem15.user. The AI plugin is not a dependency. - GDPR. Boot Listens
user.Deleting(DeletingEvent) and deletesgolem15_chatbots_bot_flagsfor thatuser_idinsideev.Tx.
Usage
Look the registry up after Boot and register a host command:
reg, _ := app.Lookup[*classes.Registry]()
err := reg.Register(ping) // contracts.SlashCommand; reserved help is rejected
Install a bot-auth resolver from an application plugin after looking the plugin up (chatbots publishes it at Boot):
func (p *Plugin) Boot(app *backpack.App) error {
bots, _ := app.Lookup[*chatbots.Plugin]()
bots.SetBotAuthResolver(p.resolver) // contracts.BotAuthResolver
return nil
}
Register is the host path and still rejects reserved help plus duplicates. RegisterBuiltin is the built-in escape hatch: it skips the reserved check so /help can own that trigger. Dispatch always uses the JWT actor; a forged user_id in the body is ignored.
A blog or acme host that only needs /help leaves the registry as Boot installed it. The plugin requires Chat and User only.
The generic JSON API is chatbots.APIPrefix (/_chatbots/api/v1). Published paths:
GET /commandsPOST /dispatch({input})
API reference
| Identifier | Description |
|---|---|
chatbots.PluginID |
golem15.chatbots |
chatbots.APIPrefix |
/_chatbots/api/v1 |
chatbots.APIBucket |
Throttle bucket chatbots-api (120/min) |
contracts.SlashCommand |
Trigger, Description, IsAvailable, Handle |
contracts.BotAuthResolver |
Host bot-bearer seam; default deny-all |
classes.DenyAll |
Default resolver; Resolve empty, IsElevated false |
classes.Registry |
Slash-command registry |
classes.NewRegistry |
Empty registry |
classes.Registry.Register |
Rejects reserved help and duplicates |
classes.Registry.RegisterBuiltin |
Skips the reserved check (built-in help) |
classes.ReservedHelp |
Reserved trigger help |
classes.Dispatcher |
Parses input and runs Handle as actor |
classes.NewDispatcher |
Builds a dispatcher over a registry |
classes.Dispatcher.Dispatch |
Unrecognized or unavailable trigger returns nil |
classes.CommandResult |
Mode ephemeral or announce plus payload |
classes.Ephemeral |
Invoker-only result; no chat insert |
classes.Announce |
Persist one chat TYPE_SYSTEM message |
classes.HelpCommand |
Built-in /help catalog |
chatbots.Plugin.SetBotAuthResolver |
Host setter; nil becomes DenyAll |
models.BotFlag |
Row of golem15_chatbots_bot_flags |
Dependencies
golem15.chat(required)golem15.user(required)- SummerCMS modules: backpack, party, pact, lagoon, surf, bouncer, wire
Testing
go vet ./...
go test -short ./...
go test -run '^TestHTTPTracer$' -v .
The proof host is golem15.user + golem15.chat + golem15.chatbots + a test-only teams fixture that registers /ping. TestFixtureAbsentFromProduction keeps the fixture id and retired tokens out of production sources. TestHTTPTracer needs Docker. TestNoGolem greps production sources for the AI plugin module.