package main import ( "encoding/json" "log/slog" "net/http" "git.dev.alexdunmow.com/block/pluginsdk/plugin" "git.dev.alexdunmow.com/block/pluginsdk/route" ) const pluginName = "callbacks-77c1d0" // Registration is the plugin entry registration. var Registration = plugin.PluginRegistration{ Name: pluginName, Version: "1.0.0", HTTPHandler: newHTTPHandler, } const listRecent = `-- name: ListRecentCallers :many SELECT id, mobile FROM callers ORDER BY id LIMIT 20 ` type Queries struct{} func (Queries) ListRecentCallers() []string { return nil } func newHTTPHandler(deps plugin.CoreServices) http.Handler { r := route.New(pluginName) r.Form("/request", handleRequest) r.Handle(http.MethodGet, "/recent", route.Public, handleRecent) return r } func handleRequest(w http.ResponseWriter, r *http.Request) { email := r.PostFormValue("email") notes := r.PostFormValue("notes") slog.Info("call-back requested", "email", email, "notes", notes) w.WriteHeader(http.StatusNoContent) } func handleRecent(w http.ResponseWriter, r *http.Request) { _ = json.NewEncoder(w).Encode(Queries{}.ListRecentCallers()) }