Use htmlrender from AlonaBot
Load the configuration plugin and profile-card example, then send /profile Flan in a chat. The configuration plugin shares the endpoint and token; the business plugin sends its HTML and bundled resources directly to the rendering service.
简体中文
Run the example
Start a rendering service using the service instructions. In this directory, use the AlonaBot CLI matching the SDK version in go.mod:
alonabot check ./plugin
alonabot check ./examples/profilecard
alonabot run ./plugin ./examples/profilecard --data-dir ./tmp/bot
In the configuration page, set the htmlrender plugin's endpoint and secret token to your service. For the example, choose blitz or chromium in the profile plugin's engine setting. These source plugins use local component IDs and can be loaded from the checked-out directories.
The /profile [name] command embeds the sample card resources, escapes the supplied name, selects #card, and sends the resulting image through sdk/media.Image. Images over 1 MiB use the SDK's existing upload path.
Call from your own plugin
go get github.com/AlonaBot/htmlrender/alonabot@main
import (
"github.com/AlonaBot/AlonaBot/sdk"
"github.com/AlonaBot/AlonaBot/sdk/media"
t2i "github.com/AlonaBot/htmlrender"
render "github.com/AlonaBot/htmlrender/alonabot"
)
p.Command("card").Handle(func(c *sdk.Context) error {
connection, err := render.Connect(c)
if err != nil {
return err
}
defer connection.Close()
result, err := connection.Render(c, t2i.Request{
HTML: `<article id="card">Hello from a plugin</article>`,
Engine: t2i.Chromium,
Options: t2i.Options{Selector: "#card"},
})
if err != nil {
return err
}
segment, err := media.Image(c, result.Data)
if err != nil {
return err
}
_, err = c.Send(segment)
return err
})
Connect calls the typed htmlrender/connection Service. It returns a client holding a snapshot of endpoint and token; connect again after configuration changes. The service is available to enabled plugins, which receive the token and should handle it as a secret. The client owns its connections; callers close it when finished. Each render uses the supplied context, including its deadline and cancellation.
This module owns the AlonaBot SDK dependency. The parent rendering module retains its general-purpose API and supports clients building with CGO_ENABLED=0.
env CGO_ENABLED=0 go test -tags integration -v ./...
The integration test starts the real Core, both plugins, a test Adapter and a real Chromium-backed HTTP service. It verifies the normal profile card and a rendered image larger than 1 MiB, including the captured Adapter bytes and uploaded media reference. Chrome must be installed; CHROME_BIN selects its executable when needed. The test uses its own temporary Core data directory.