astraengine

package module
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: GPL-3.0 Imports: 6 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

AstraEngine

A production-minded Go framework for cross-platform bots and community automation.

Write portable application logic once. Run it on Telegram, VK, and Discord without hiding the native SDKs when you need them.

CI Release Go Reference Go Report Card Go version Stars License

Getting started · Architecture · Wiki · Examples · Changelog


Why AstraEngine

  • Portable where it matters. Routing, middleware, state, keyboards, attachments, pagination, and messaging share one API across platforms.
  • Native when it matters. Typed telegram.From(ctx), vk.From(ctx), and discord.From(ctx) escape hatches expose the underlying SDK without bloating the core contract.
  • Operationally honest. Configuration fails before startup, session load errors propagate, callback routing is deterministic, Admin authentication fails closed, and operational edit failures never silently create duplicate messages.

What is included

Area Available today
Runtime Commands, callbacks, text, regex and typed events; middleware, groups, rate limits, retries and graceful shutdown
Messaging Replies, edits, private delivery, inline keyboards, attachments, embeds, message references and callback acknowledgement
Navigation Cross-platform renderer-backed pagination with ownership checks and optional edge controls
State Storage-backed sessions and scenes/FSM with safe load-error propagation and same-key process serialization
Localization Immutable ICU MessageFormat catalogs, locale fallback, persisted language selection, plurals/select and locale-aware values
Platforms Telegram, VK and Discord adapters with native-client access
Persistence In-memory and PostgreSQL repositories; coordinated PostgreSQL migration execution
Extensions Plugin lifecycle, validated settings, migrations and optional Admin modules
Admin RBAC, web sessions, audit/log streams, declarative UI metadata, Control WebSocket and durable operations

The portable core never imports platform SDKs. Platform-specific behavior stays in its adapter.

Install

go get github.com/andrewkydev/astraengine/v2@latest

The release badge above always points to the current stable tag. AstraEngine v2.0.3 requires Go 1.26.4 or newer, as declared in go.mod.

Quick start

package main

import (
	"context"
	"os"
	"os/signal"
	"syscall"

	astraengine "github.com/andrewkydev/astraengine/v2"
	botctx "github.com/andrewkydev/astraengine/v2/core/context"
	"github.com/andrewkydev/astraengine/v2/platform/telegram"
)

func main() {
	ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
	defer stop()

	app := astraengine.New("example")
	app.Platform(telegram.New(telegram.Config{Token: os.Getenv("TELEGRAM_TOKEN")}))
	app.Command("start", func(ctx *botctx.Context) error {
		return ctx.SendText("Hello from AstraEngine")
	})

	if err := app.Start(ctx); err != nil && err != context.Canceled {
		panic(err)
	}
}

Keep platform tokens outside the repository. Load them from the environment or use the validated loader in configs/runtime.

Localization

Built into v2.0.3, localization uses validated ICU MessageFormat catalogs without coupling Pager, FSM, or keyboard APIs to a specific language system.

bundle, err := i18n.New("en",
	i18n.Map("en", map[string]string{"items": `{count, plural, one {# item} other {# items}}`}),
	i18n.Map("ru", map[string]string{"items": `{count, plural, one {# предмет} few {# предмета} many {# предметов} other {# предмета}}`}),
)
if err != nil { panic(err) } // every message is validated and compiled here

app.Use(state.SessionMiddleware(store.Sessions(), 24*time.Hour))
app.Use(i18n.Middleware(bundle)) // saved locale > platform locale > default locale

app.Command("items", func(ctx *botctx.Context) error {
	text, err := ctx.T("items", i18n.Args{"count": 5})
	if err != nil { return err }
	return ctx.SendText(text)
})

Use i18n.JSON(locale, reader) for flat JSON catalogs and i18n.SetLocale(ctx, "ru") to change and persist a user's language. Pager renderers, FSM handlers, and keyboard labels use the same ctx.T call; see examples/multi-platform.

Platform coverage

Capability Telegram VK Discord
Messages and callbacks ✅ ✅ ✅
Inline keyboards / buttons ✅ ✅ ✅
Replies and edits ✅ ✅ ✅
Attachments ✅ ✅ ✅
Private delivery ✅ ✅ ✅
Native SDK access ✅ ✅ ✅
Slash commands — — ✅

Discord moderation and role-management parity are still incomplete. Redis, payments, cluster queues, WASM plugins, and speculative adapters are intentionally outside the current release.

Reliability baseline

Every push to main runs:

gofmt -l .
go test ./...
go test -race ./...
go vet ./...

The latest release includes deterministic callback priority, safe session decoding, bounded VK callback/download state, Telegram inline callback protection, typed edit-unavailable errors, preflight adapter validation, PostgreSQL migration coordination, and fail-closed Admin authentication.

Package map

Package Purpose
core/app, core/router, core/context Runtime, routing and portable handler context
core/event, keyboard, payload, attachments Messaging contracts and callback payloads
state, core/fsm Storage-backed scenes and compatibility FSM APIs
i18n ICU MessageFormat catalogs, locale middleware and persisted language selection
platform/telegram, platform/vk, platform/discord Platform adapters and native escape hatches
plugin, plugins Compile-time modules, migrations and settings
storage/memory, storage/postgres Standard persistence implementations
admin/* Optional management API, authentication, Control and operations
runtime, logging, configs/runtime Process helpers, diagnostics and configuration

Documentation

Runnable examples live in examples/. The Admin frontend and demo application are maintained as separate repositories.

License

Licensed under GPLv3.

Documentation

Overview

Package astraengine exposes the public convenience API for building bots and automation apps on top of the AstraEngine runtime.

Most concrete implementations still live in subpackages such as core/app, platform/telegram, storage/postgres and plugin. The root package intentionally stays small so application code can start from astraengine.New while importing only the adapters and storage backends it actually needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App = app.App

App is the main AstraEngine runtime type.

func New

func New(name string) *App

New creates a new AstraEngine app runtime.

type Cache

type Cache = cache.Cache

Cache is the engine cache contract.

type Group

type Group = app.Group

Group is a route group with its own middleware chain.

type Handler

type Handler = middleware.Handler

Handler processes a single normalized engine event.

type Middleware

type Middleware = middleware.Middleware

Middleware wraps a Handler with cross-cutting behavior.

type Platform

type Platform = platform.Platform

Platform is implemented by concrete adapters such as Telegram, VK and Discord.

type Plugin

type Plugin = plugin.Plugin

Plugin is the engine plugin contract.

type Store

type Store = storage.Store

Store is the engine storage contract.

Directories

Path Synopsis
Package admin exposes convenient constructors for the extensible Admin API.
Package admin exposes convenient constructors for the extensible Admin API.
api
Package api provides the extensible HTTP Admin API server.
Package api provides the extensible HTTP Admin API server.
auth
Package auth defines Admin API authentication claims and verification.
Package auth defines Admin API authentication claims and verification.
control
Package control implements Astra Admin Control WebSocket protocol v1.
Package control implements Astra Admin Control WebSocket protocol v1.
observability
Package observability records handler events, audits and basic runtime metrics.
Package observability records handler events, audits and basic runtime metrics.
resources
Package resources defines declarative Admin API resource metadata.
Package resources defines declarative Admin API resource metadata.
ui
Package ui defines the declarative Astra Admin UI protocol.
Package ui defines the declarative Astra Admin UI protocol.
Package attachments provides a shared attachment model and lightweight helpers.
Package attachments provides a shared attachment model and lightweight helpers.
Package cache defines the storage-independent cache contract used by the engine.
Package cache defines the storage-independent cache contract used by the engine.
memory
Package memory implements an in-process cache for tests and single-instance bots.
Package memory implements an in-process cache for tests and single-instance bots.
nop
Package nop implements a cache that never stores values.
Package nop implements a cache that never stores values.
cmd
astrabot command
configs
runtime
Package runtime loads example and CLI configuration from environment variables.
Package runtime loads example and CLI configuration from environment variables.
core
app
Package app wires platforms, routing, middleware, plugins and storage into a runtime.
Package app wires platforms, routing, middleware, plugins and storage into a runtime.
botcmd
Package botcmd parses commands and provides alias-aware command middleware.
Package botcmd parses commands and provides alias-aware command middleware.
capability
Package capability describes optional features supported by platform adapters.
Package capability describes optional features supported by platform adapters.
command
Package command contains shared command parsing for platform adapters.
Package command contains shared command parsing for platform adapters.
context
Package context provides the handler context and cross-platform message helpers.
Package context provides the handler context and cross-platform message helpers.
errors
Package errors defines machine-readable AstraEngine errors.
Package errors defines machine-readable AstraEngine errors.
event
Package event contains the platform-neutral event model dispatched by AstraEngine.
Package event contains the platform-neutral event model dispatched by AstraEngine.
fsm
Package fsm provides lightweight mode-and-step state injection.
Package fsm provides lightweight mode-and-step state injection.
middleware
Package middleware defines handlers and composable event middleware.
Package middleware defines handlers and composable event middleware.
platform
Package platform defines adapter contracts and platform-neutral outbound messages.
Package platform defines adapter contracts and platform-neutral outbound messages.
ratelimit
Package ratelimit provides in-memory fixed-window limits and routing middleware.
Package ratelimit provides in-memory fixed-window limits and routing middleware.
router
Package router dispatches commands, callbacks and text events to handlers.
Package router dispatches commands, callbacks and text events to handlers.
examples
echo-bot command
multi-platform command
Package i18n provides immutable ICU MessageFormat catalogs and request middleware.
Package i18n provides immutable ICU MessageFormat catalogs and request middleware.
Package input normalizes message, command and callback input for handlers.
Package input normalizes message, command and callback input for handlers.
Package keyboard builds platform-neutral inline and reply keyboards.
Package keyboard builds platform-neutral inline and reply keyboards.
Package logging configures the standard library's structured slog logger.
Package logging configures the standard library's structured slog logger.
Package mentions extracts common Telegram, VK and Discord mention formats.
Package mentions extracts common Telegram, VK and Discord mention formats.
Package navigation provides callback-based pagination helpers.
Package navigation provides callback-based pagination helpers.
Package payload encodes portable callback button data.
Package payload encodes portable callback button data.
platform
discord
Package discord provides the experimental Discord adapter.
Package discord provides the experimental Discord adapter.
telegram
Package telegram implements AstraEngine's Telegram Bot API adapter.
Package telegram implements AstraEngine's Telegram Bot API adapter.
vk
Package vk implements AstraEngine's VK community bot adapter.
Package vk implements AstraEngine's VK community bot adapter.
Package plugin implements compile-time plugins, settings and migration metadata.
Package plugin implements compile-time plugins, settings and migration metadata.
plugins
auth
Package auth contains the baseline compile-time auth plugin.
Package auth contains the baseline compile-time auth plugin.
broadcast
Package broadcast contains the baseline compile-time broadcast plugin.
Package broadcast contains the baseline compile-time broadcast plugin.
roles
Package roles contains the baseline compile-time roles plugin.
Package roles contains the baseline compile-time roles plugin.
Package runtime contains optional lifecycle, scheduling and worker helpers.
Package runtime contains optional lifecycle, scheduling and worker helpers.
Package state provides persistent sessions and conversational FSM scenes.
Package state provides persistent sessions and conversational FSM scenes.
Package storage defines persistent models and repository contracts.
Package storage defines persistent models and repository contracts.
memory
Package memory implements process-local AstraEngine repositories.
Package memory implements process-local AstraEngine repositories.
postgres
Package postgres implements AstraEngine repositories using pgx and PostgreSQL.
Package postgres implements AstraEngine repositories using pgx and PostgreSQL.

Jump to

Keyboard shortcuts

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