alonabot

package module
v0.0.0-...-d97e320 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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.

Verify Core and media delivery

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.

Documentation

Overview

Package alonabot 为插件提供共享连接配置和直连渲染客户端。

Index

Constants

This section is empty.

Variables

View Source
var ConnectionService = service.JSON[ConnectionRequest, Connection]("htmlrender/connection")

ConnectionService 声明 htmlrender 插件提供的共享连接信息。

Functions

func Connect

func Connect(ctx context.Context) (*client.Client, error)

Connect 读取连接配置快照,返回由调用方持有和关闭的 HTTP 客户端。 配置变化后重新调用 Connect,已创建的客户端继续使用原快照。

Types

type Connection

type Connection struct {
	Endpoint string `json:"endpoint"`
	Token    string `json:"token"`
}

Connection 携带服务地址和凭据;调用方应按 secret 处理 Token。

type ConnectionRequest

type ConnectionRequest struct{}

ConnectionRequest 请求当前渲染服务的连接配置。

Directories

Path Synopsis
examples
profilecard
Package profilecard 演示通过共享配置直连服务并回复资料卡。
Package profilecard 演示通过共享配置直连服务并回复资料卡。
Package plugin 提供 htmlrender 共享配置插件。
Package plugin 提供 htmlrender 共享配置插件。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL