Add server behavior
Server code lives in the plugin directory and imports the Go Plugin SDK. It must not import apps/server/internal.
Receive Host services
Section titled “Receive Host services”Implement plugin.Initializer when the plugin needs Tilecast services:
func (p *Plugin) Init(_ context.Context, host plugin.Host) error { p.host = host p.db = host.DB return nil}Host.DB is for the plugin’s own tables. Use the other Host services for core state.
Common services include Installation, Audit, Manifests, Targets, Takeovers, ManagedPresentations, BackgroundJobs, Screens, Organization, Clock, Logger, DataSources, Users, PluginAssets, and Fonts.
If a plugin needs a core table that is not represented by a Host service, don’t query that table directly. Extend the API deliberately.
Register HTTP routes
Section titled “Register HTTP routes”Implement plugin.RouteProvider and register routes below one of the manifest’s api.basePaths.
Choose the access level that matches the endpoint:
AccessVieweris for enrolled read-onlyGETandHEADrequests.AccessManagerrequires Owner or Administrator and CSRF on mutations.AccessSessionrequires an enrolled session and leaves resource-specific authorization to the plugin.AccessCapability("name")requires a plugin capability that the manifest declares inaccess.capabilities, or a core capability such asAccessCapability("screen.read"). Owner and Administrator hold every plugin capability; custom roles hold the ones an operator grants. See the access control contract.
Use plugin.PrincipalFrom for the signed-in user and plugin.DecodeJSON for strict JSON requests.
Use HandleWithRateLimit with plugin.RateLimitOperations for an operation that needs the shared operations limiter.
Keep matching paths in api/openapi.yaml. plugins:generate composes the fragments into Tilecast’s canonical OpenAPI document.
Report status and removal blockers
Section titled “Report status and removal blockers”StatusReporter supplies configured, active, instance-count, and attention state to the plugin catalog.
RemovalGuard runs inside the Remove transaction. Return blockers when the operator must delete, disable, or wait for plugin-owned resources before removing the installation row.
Removing an installation does not delete plugin data.
Run background work
Section titled “Run background work”A WorkerProvider returns named workers. Automatic work should check the plugin installation and Host.BackgroundJobs.Allowed().
The second gate pauses background changes during backup and restore. An explicit operator action does not use that gate.
Forms uses a worker. A plugin on Plugin Manifest API 3 can use a durable timer instead: Emergency Alerts polls the National Weather Service from one.
Seed Demo Mode
Section titled “Seed Demo Mode”Implement DemoSeeder when the plugin should add useful sample data to Demo Mode. Countdown Bar uses it to add a lunch countdown.
Keep demo seeding thin. It should use the same plugin behavior that normal product code uses.
Use a connection (Plugin Manifest API 3)
Section titled “Use a connection (Plugin Manifest API 3)”A version 3 plugin sends HTTP requests through http.fetch@1. It names a connection record, usually the value of a connection field, and Tilecast checks the origin and every address, follows only approved redirects, and limits the body and the time.
response, err := p.services.Fetch(ctx, plugin.HTTPRequest{ Connection: uuid.MustParse(settings["calendar"].(string)), Method: http.MethodGet, URL: "/v1/events?limit=50", Headers: []plugin.HTTPHeader{ {Name: "Accept", Value: "application/json"}, {Name: "Authorization", Secret: &plugin.SecretHeader{ Scope: plugin.ScopeOrganization, Key: "apiToken", Prefix: "Bearer "}}, },})if plugin.IsServiceError(err, plugin.FetchPlaintextSecretRefused) { // The operator has not allowed a secret over plain HTTP.}- A path such as
/v1/eventsworks when the connection has one origin. Otherwise send the full URL. - A
Secretheader names one of your own secret fields. Tilecast adds the value; your code never sees it. - Failures are stable codes such as
origin_not_allowed,private_network_refused,redirect_refused,timeout, andresponse_too_large. They never include resolver or TLS details. npm run plugins:checkrefuseshttp.Client,net.Dial, and similar calls in a version 3 plugin. Usehttp.fetch@1for provider traffic.
Test against plugintest.Services with a handler that answers http.fetch@1/request, so your tests never reach the internet.
Keep state and schedule work (Plugin Manifest API 3)
Section titled “Keep state and schedule work (Plugin Manifest API 3)”Declare storage.kv@1 to keep small values, such as a sync cursor, and timers.schedule@1 (plus timers.cancel@1) to run code later. Don’t create your own tables or goroutines for this.
// A cursor survives restarts and reinstalls.cursor, err := p.services.KVGet(ctx, "calendar:"+instanceID)if errors.Is(err, plugin.ErrKVNotFound) { cursor = nil // start a full sync}
// Store it only if nobody else moved it meanwhile.swapped, err := p.services.KVCompareAndSet(ctx, "calendar:"+instanceID, cursor, next)
// Run HandleTimer again in five minutes. The same key replaces the old timer._, err = p.services.ScheduleTimer(ctx, "sync:"+instanceID, time.Now().Add(5*time.Minute), []byte(instanceID))Implement HandleTimer(ctx context.Context, timer plugin.Timer) error on your plugin. Tilecast calls it with no signed-in person, for at most 30 seconds, and calls it at least once: after a crash or an error the same timer can run again, so make the handler safe to repeat. Returning an error retries the timer with a growing delay, from 5 seconds up to 15 minutes. After eight failed attempts Tilecast parks the timer: the plugin’s Status page shows it, and an Owner can retry or discard it.
Limits: keys up to 128 bytes, values up to 64 KiB, 1 MiB of values per plugin, timer payloads up to 4 KiB, and 1,000 pending timers. Values are kept when the plugin is removed; removing the plugin deletes its pending timers. If you bump definitionVersion, Tilecast drops timers from the old definition, so schedule the ones you need again. See Plugin storage and timers and Plugin delivery for every rule.
Publish a feed (Plugin Manifest API 3)
Section titled “Publish a feed (Plugin Manifest API 3)”Publish the complete set of records each time. Tilecast replaces the dataset and keeps operator changes according to each field’s policy.
revision, err := p.services.FeedRevision(ctx, "items", instanceID)published, err := p.services.PublishFeed(ctx, plugin.FeedPublication{ Feed: "items", Instance: instanceID, Replaces: revision, Records: []plugin.FeedRecord{{ID: "item-123", Values: map[string]any{"name": "Tea", "price": 3.5, "photo": "https://images.example.com/tea.png"}}}, Connections: map[string]uuid.UUID{"images": imagesConnectionID},})if errors.Is(err, plugin.ErrFeedConflict) { // Another publication won. Read the revision again and retry once.}Use stable record IDs from the provider. A publication holds at most 2,000 records and 512 KiB. Tilecast fetches images after the publication commits; you never download image bytes yourself.
Publish and receive events (Plugin Manifest API 3)
Section titled “Publish and receive events (Plugin Manifest API 3)”Declare the events you publish and the events you receive in the manifest’s events member, and add events.publish@1 to services if you publish. Each published event has a name, a version, a title, and payload fields from the configuration schema (scalar controls only, never a secret or personal field).
occurrence, err := p.services.PublishEvent(ctx, "period_started@1", "room-12", map[string]any{"period": "3", "minutes": 50})Tilecast adds your plugin ID, so other plugins subscribe to plugin.<your plugin id>.period_started@1. The payload must match the declared fields and be at most 4 KiB. The subject (up to 128 bytes) names the thing whose events must stay in order, such as a room.
PublishEvent runs in its own transaction, separate from your storage.kv@1 or feed writes. Save your own state first and publish after it succeeds.
To receive events, list them in events.subscribes (core events such as takeover.started@1, or another plugin’s full event names) and implement:
func (p *Plugin) HandleEvent(ctx context.Context, event plugin.Event) errorTilecast calls it at least once for each delivery, in order for each subject, with no signed-in person, for at most 30 seconds. The same DeliveryID can arrive again, so make the handler safe to repeat; OccurrenceID is the same for every subscriber of one event. Returning an error retries the delivery like a timer.
Never change an event’s payload under the same version: add a new version instead. Tilecast records each version’s payload shape the first time it’s published and refuses to publish a version whose fields, types, or limits changed. Changing labels or descriptions is fine. See Plugin events for the full contract.
Receive webhooks (Plugin Manifest API 3)
Section titled “Receive webhooks (Plugin Manifest API 3)”Declare inbound endpoints in the manifest’s webhooks member. Tilecast owns the address, /api/v1/hooks/<plugin id>/<webhook id>; your plugin never registers a public route of its own. Pick one authentication mode for each webhook:
token: a system on your network, such as a door controller, sendsAuthorization: Bearer tch_…. People create and revoke tokens on the plugin’s Webhooks page.signature: a SaaS provider signs each request. Declarestandard-webhooks, orhmac-sha256with the provider’s header, encoding, and signed string (body,timestamp.body, orurl.body). Pointsignature.secretat an organization setting with thesecretcontrol. Tilecast checks the signature; your code never sees the secret. Declare where the provider puts its delivery ID (deliveryId), so Tilecast can drop repeats.fetch-back: Tilecast keeps only an event ID from the request, and your handler reads the event from the provider through one of your connections.
A signed webhook must list its delivery ID header in the signed headers, so a sender can’t change it without breaking the signature, and the plugin needs a studio route and api.basePaths so people can enter the secret. A fetch-back event ID pattern may use only syntax that Go and JavaScript read the same way: literals, \d, \w, character classes, groups, |, the quantifiers *, +, ? and {n,m}, and the ^ and $ anchors. Lookaround, backreferences, . and \s are refused, so the manifest validates the same everywhere.
Set ackStatus to 200 if the provider retries anything else (Planning Center does); the default is 202. Either way, Tilecast answers only after it has stored the request.
func (p *Plugin) HandleWebhook(ctx context.Context, webhook plugin.Webhook) errorTilecast calls it at least once, in order for each webhook, with no signed-in person, for at most 30 seconds. DeliveryID stays the same across retries; ExternalID is the provider’s ID; Body is the exact raw body; Headers holds only the headers you listed in forwardHeaders. Treat a webhook as “something changed, go read it” and keep polling as well: a webhook only makes an update arrive sooner, and many Servers have no public HTTPS address at all.
For a provider no declaration fits, use the verify scheme and implement VerifyWebhook. It gets one second and can’t call http.fetch@1. See Plugin webhooks for every rule and limit.
Provide a notification channel or a Content Health check (Plugin Manifest API 3)
Section titled “Provide a notification channel or a Content Health check (Plugin Manifest API 3)”Fill a core provider slot in the manifest’s providers member. A notification channel (providers.notifications.channels) implements:
func (p *Plugin) DeliverNotification(ctx context.Context, n plugin.Notification) errorTilecast calls it for notifications it already decided to send; you never pick recipients, categories, or timing. Return plugin.ErrChannelUnavailable if the channel is off, wrap a permanent refusal with plugin.PermanentNotificationError, and return any other error to have the outbox retry. Implement NotificationChannelReady too, so a channel that isn’t set up gets no deliveries at all.
A Content Health check (providers.contentHealth.checks, with the item kinds it reads) implements:
func (p *Plugin) CheckContent(ctx context.Context, item plugin.ContentItem) ([]plugin.Condition, error)Tilecast passes one changed playlist, Layout, Widget, or media item at a time, as a read-only model. Return named conditions with a severity and a short reason; Tilecast opens, deduplicates, and recovers the incidents. An error keeps the item’s earlier conditions and tries again later. Checks run on their own schedule, about once a minute, and never delay a notification. An open incident keeps its highest severity until the condition recovers. A plugin.Notification carries the time of the event, not the time it was queued. See Plugin provider slots.
Read content and Activity (Plugin Manifest API 3)
Section titled “Read content and Activity (Plugin Manifest API 3)”A plugin that needs to know what exists or what played declares a read service in services, and only the ones it needs:
content.read@2reads playlists, Layouts, Widgets, media, Data Sources, schedules, and screen groups.activity.read@1reads proof of play, playback compliance, and what each screen is showing now.
Both work in a route, a worker or timer, and a host callback. When a person calls your route from Studio, the read uses that person’s access, exactly like Studio. When your plugin runs by itself, the read covers the whole installation, because the person who installed the plugin approved that service on its review. It is not administrator access: it reads only that one service, and it never borrows the access of whoever configured the plugin.
var page struct { Items []json.RawMessage `json:"items"` NextCursor string `json:"nextCursor"`}err := p.services.ContentReadV2PlaylistsList(ctx, map[string]any{"limit": 50}, &page)// Pass page.NextCursor back as "cursor" for the next page, with the same filters.Lists return at most 250 items and use an opaque cursor. Answers never include file paths, secrets, Data Source payloads, or Activity diagnostics. For the exact models and rules, see the plugin read services reference.