native

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAutoRegisterMaxAttempts    = 3
	DefaultAutoRegisterInitialBackoff = time.Second
	DefaultAutoRegisterMaxBackoff     = 5 * time.Second
)
View Source
const (
	FunctionCreateAppDataTable       = "createAppDataTable"
	FunctionCreateAppDataTableSchema = "createAppDataTableSchema"
	FunctionGetAppDataTableSchema    = "getAppDataTableSchema"
	FunctionUpsertAppDataTableRows   = "upsertAppDataTableRows"
	FunctionRegisterAppNotebooks     = "registerAppNotebooks"
	FunctionGetAppNotebookVersions   = "getAppNotebookVersions"
)
View Source
const DefaultAppStoreURL = "https://app-store.channel.io"
View Source
const FunctionWriteGroupMessage = "writeGroupMessage"

Variables

This section is empty.

Functions

func AppDataTableFunctionSchema

func AppDataTableFunctionSchema(name string) (appsdk.FunctionSchema, bool)

func AppDataTableFunctionSchemas

func AppDataTableFunctionSchemas() []appsdk.FunctionSchema

func AppNotebookFunctionSchema

func AppNotebookFunctionSchema(name string) (appsdk.FunctionSchema, bool)

func AppNotebookFunctionSchemas

func AppNotebookFunctionSchemas() []appsdk.FunctionSchema

func CallNative added in v0.15.0

func CallNative[T any](ctx context.Context, c *Client, accessToken, method string, params any) (*T, error)

CallNative invokes a public AppStore Native Function and decodes its result into T. Prefer a typed Client or ProxyAPI method when one is available.

Types

type AlfTaskVersion

type AlfTaskVersion struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Version string `json:"version"`
}

type AppDataTableColumn

type AppDataTableColumn struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	Type        string `json:"type"`
	Nullable    bool   `json:"nullable,omitempty"`
	Description string `json:"description,omitempty"`
}

type AppDataTableSchema

type AppDataTableSchema struct {
	ChannelID         string               `json:"channelId,omitempty"`
	AppID             string               `json:"appId,omitempty"`
	TableName         string               `json:"tableName"`
	Columns           []AppDataTableColumn `json:"columns"`
	PrimaryKeyColumns []string             `json:"primaryKeyColumns,omitempty"`
}

type AppNotebookVersion

type AppNotebookVersion struct {
	NotebookKey      string `json:"notebookKey"`
	Version          int    `json:"version"`
	LatestRevisionID string `json:"latestRevisionId,omitempty"`
	UpdatedAt        string `json:"updatedAt,omitempty"`
}

type AutoRegisterConfig

type AutoRegisterConfig struct {
	App            *appsdk.App
	Targets        []appsdk.ExtensionRegistration
	AppID          string
	AppSecret      string
	AppStoreURL    string
	Client         *Client
	TokenManager   *TokenManager
	OnResult       func([]AutoRegisterResult)
	MaxAttempts    int
	InitialBackoff time.Duration
	MaxBackoff     time.Duration
}

type AutoRegisterResult

type AutoRegisterResult struct {
	ExtensionName string
	SystemVersion string
	Success       bool
	Error         string
}

type AutoRegistrar

type AutoRegistrar struct {
	// contains filtered or unexported fields
}

func NewAutoRegistrar

func NewAutoRegistrar(config AutoRegisterConfig) *AutoRegistrar

func (*AutoRegistrar) Register

func (r *AutoRegistrar) Register(ctx context.Context) []AutoRegisterResult

type CachedToken

type CachedToken struct {
	Token     TokenResponse `json:"token"`
	CachedAt  time.Time     `json:"cachedAt"`
	ExpiresAt time.Time     `json:"expiresAt"`
	Key       string        `json:"key"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...Option) *Client

func (*Client) CallAppFunction

func (c *Client) CallAppFunction(ctx context.Context, accessToken, appID, method string, params any, fnCtx appsdk.Context, systemVersion string) (json.RawMessage, error)

func (*Client) CallNativeFunction added in v0.15.0

func (c *Client) CallNativeFunction(ctx context.Context, accessToken, method string, params any) (json.RawMessage, error)

CallNativeFunction invokes a public AppStore Native Function and returns its raw JSON result. Use a channel-scoped token for Channel operations and an app token for app-owned operations.

func (*Client) CreateAppDataTable

func (c *Client) CreateAppDataTable(ctx context.Context, accessToken string, params CreateAppDataTableParams) (*CreateAppDataTableResponse, error)

func (*Client) CreateAppDataTableSchema

func (c *Client) CreateAppDataTableSchema(ctx context.Context, accessToken string, params CreateAppDataTableSchemaParams) (*CreateAppDataTableSchemaResponse, error)

func (*Client) CreateProxyAPI added in v0.15.0

func (c *Client) CreateProxyAPI(accessToken string) *ProxyAPI

CreateProxyAPI creates a typed Channel-operation client for a channel-scoped token.

func (*Client) GetAlfTaskVersions

func (c *Client) GetAlfTaskVersions(ctx context.Context, accessToken, appID string) (*GetAlfTaskVersionsResponse, error)

func (*Client) GetAppDataTableSchema

func (c *Client) GetAppDataTableSchema(ctx context.Context, accessToken string, params GetAppDataTableSchemaParams) (*GetAppDataTableSchemaResponse, error)

func (*Client) GetAppNotebookVersions

func (c *Client) GetAppNotebookVersions(ctx context.Context, accessToken, appID string) (*GetAppNotebookVersionsResponse, error)

func (*Client) IssueToken

func (c *Client) IssueToken(ctx context.Context, secret string, opts ...IssueTokenOptions) (*IssueTokenResponse, error)

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context, refreshToken string) (*IssueTokenResponse, error)

func (*Client) RegisterAlfTasks

func (c *Client) RegisterAlfTasks(ctx context.Context, accessToken, appID string) (*RegisterAlfTasksResponse, error)

func (*Client) RegisterAppNotebooks

func (c *Client) RegisterAppNotebooks(ctx context.Context, accessToken, appID string) (*RegisterAppNotebooksResponse, error)

func (*Client) RegisterExtension

func (c *Client) RegisterExtension(ctx context.Context, accessToken, appID, extensionName, systemVersion string) (*RegisterExtensionResponse, error)

func (*Client) UnregisterExtension

func (c *Client) UnregisterExtension(ctx context.Context, accessToken, appID, extensionName, systemVersion string) (*RegisterExtensionResponse, error)

func (*Client) UpsertAppDataTableRows

func (c *Client) UpsertAppDataTableRows(ctx context.Context, accessToken string, params UpsertAppDataTableRowsParams) (*UpsertAppDataTableRowsResponse, error)

type CreateAppDataTableParams

type CreateAppDataTableParams struct {
	AppID             string               `json:"appId"`
	TableName         string               `json:"tableName"`
	Columns           []AppDataTableColumn `json:"columns"`
	PrimaryKeyColumns []string             `json:"primaryKeyColumns,omitempty"`
}

type CreateAppDataTableResponse

type CreateAppDataTableResponse struct {
	RequestID string `json:"requestId"`
}

type CreateAppDataTableSchemaParams

type CreateAppDataTableSchemaParams struct {
	ChannelID         string               `json:"channelId"`
	AppID             string               `json:"appId"`
	TableName         string               `json:"tableName"`
	Columns           []AppDataTableColumn `json:"columns"`
	PrimaryKeyColumns []string             `json:"primaryKeyColumns,omitempty"`
}

type CreateAppDataTableSchemaResponse

type CreateAppDataTableSchemaResponse struct {
	RequestID string              `json:"requestId"`
	Schema    *AppDataTableSchema `json:"schema,omitempty"`
}

type GetAlfTaskVersionsResponse

type GetAlfTaskVersionsResponse struct {
	Success      bool             `json:"success"`
	ErrorMessage string           `json:"errorMessage,omitempty"`
	Tasks        []AlfTaskVersion `json:"tasks"`
}

type GetAppDataTableSchemaParams

type GetAppDataTableSchemaParams struct {
	ChannelID string `json:"channelId"`
	AppID     string `json:"appId"`
	TableName string `json:"tableName"`
}

type GetAppDataTableSchemaResponse

type GetAppDataTableSchemaResponse struct {
	Schema *AppDataTableSchema `json:"schema,omitempty"`
}

type GetAppNotebookVersionsResponse

type GetAppNotebookVersionsResponse struct {
	Success      bool                 `json:"success"`
	ErrorMessage string               `json:"errorMessage,omitempty"`
	Notebooks    []AppNotebookVersion `json:"notebooks"`
}

type InMemoryTokenCache

type InMemoryTokenCache struct {
	// contains filtered or unexported fields
}

func NewInMemoryTokenCache

func NewInMemoryTokenCache() *InMemoryTokenCache

func (*InMemoryTokenCache) Clear

func (*InMemoryTokenCache) Delete

func (c *InMemoryTokenCache) Delete(_ context.Context, key string) error

func (*InMemoryTokenCache) Get

func (*InMemoryTokenCache) Set

func (*InMemoryTokenCache) Stats

func (c *InMemoryTokenCache) Stats() (size int, keys []string)

type IssueTokenOptions

type IssueTokenOptions struct {
	ChannelID string
}

type IssueTokenResponse

type IssueTokenResponse struct {
	AccessToken  string `json:"accessToken"`
	RefreshToken string `json:"refreshToken"`
	ExpiresIn    int    `json:"expiresIn"`
}

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

type ProxyAPI added in v0.15.0

type ProxyAPI struct {
	// contains filtered or unexported fields
}

ProxyAPI exposes typed Channel operations using one channel-scoped access token. Create it with Client.CreateProxyAPI after obtaining the token from TokenManager.

func (*ProxyAPI) WriteGroupMessage added in v0.15.0

func (p *ProxyAPI) WriteGroupMessage(ctx context.Context, params WriteGroupMessageParams) (*WriteGroupMessageResult, error)

WriteGroupMessage writes a message with the installed app's bot profile.

type ProxyMessage added in v0.15.0

type ProxyMessage map[string]any

type RegisterAlfTasksResponse

type RegisterAlfTasksResponse struct {
	Success      bool   `json:"success"`
	ErrorMessage string `json:"errorMessage,omitempty"`
	TotalTasks   int    `json:"totalTasks"`
	CreatedCount int    `json:"createdCount"`
	UpdatedCount int    `json:"updatedCount"`
	DeletedCount int    `json:"deletedCount"`
}

type RegisterAppNotebooksResponse

type RegisterAppNotebooksResponse struct {
	Success        bool   `json:"success"`
	ErrorMessage   string `json:"errorMessage,omitempty"`
	SyncRunID      string `json:"syncRunId,omitempty"`
	Status         string `json:"status,omitempty"`
	TotalNotebooks int    `json:"totalNotebooks"`
	CreatedCount   int    `json:"createdCount"`
	UpdatedCount   int    `json:"updatedCount"`
	DeletedCount   int    `json:"deletedCount"`
}

type RegisterExtensionResponse

type RegisterExtensionResponse struct {
	Success          bool     `json:"success"`
	ErrorMessage     string   `json:"errorMessage,omitempty"`
	ValidationErrors []string `json:"validationErrors,omitempty"`
}

type TokenCache

type TokenCache interface {
	Get(ctx context.Context, key string) (*CachedToken, error)
	Set(ctx context.Context, key string, token CachedToken, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
	Clear(ctx context.Context) error
}

type TokenManager

type TokenManager struct {
	// contains filtered or unexported fields
}

func NewTokenManager

func NewTokenManager(config TokenManagerConfig) *TokenManager

func (*TokenManager) ClearCache

func (m *TokenManager) ClearCache(ctx context.Context) error

func (*TokenManager) Client

func (m *TokenManager) Client() *Client

func (*TokenManager) GetAppToken

func (m *TokenManager) GetAppToken(ctx context.Context) (*TokenResponse, error)

func (*TokenManager) GetChannelToken

func (m *TokenManager) GetChannelToken(ctx context.Context, channelID string) (*TokenResponse, error)

func (*TokenManager) InvalidateAppToken

func (m *TokenManager) InvalidateAppToken(ctx context.Context) error

func (*TokenManager) InvalidateChannelToken

func (m *TokenManager) InvalidateChannelToken(ctx context.Context, channelID string) error

func (*TokenManager) RefreshToken

func (m *TokenManager) RefreshToken(ctx context.Context, refreshToken string) (*TokenResponse, error)

type TokenManagerConfig

type TokenManagerConfig struct {
	AppID         string
	AppSecret     string
	AppStoreURL   string
	Client        *Client
	Cache         TokenCache
	RefreshBuffer time.Duration
	Debug         bool
	Logger        TokenManagerLogger
}

type TokenManagerError

type TokenManagerError struct {
	Message string
	Cause   error
}

func (*TokenManagerError) Error

func (e *TokenManagerError) Error() string

func (*TokenManagerError) Unwrap

func (e *TokenManagerError) Unwrap() error

type TokenManagerLogger

type TokenManagerLogger interface {
	Debug(msg string, args ...any)
}

type TokenResponse

type TokenResponse = IssueTokenResponse

type UpsertAppDataTableRowsParams

type UpsertAppDataTableRowsParams struct {
	ChannelID string           `json:"channelId"`
	AppID     string           `json:"appId"`
	TableName string           `json:"tableName"`
	Rows      []map[string]any `json:"rows"`
}

type UpsertAppDataTableRowsResponse

type UpsertAppDataTableRowsResponse struct {
	RequestID        string `json:"requestId"`
	AcceptedRowCount int    `json:"acceptedRowCount"`
}

type WriteGroupMessageParams added in v0.15.0

type WriteGroupMessageParams struct {
	ChannelID     string          `json:"channelId"`
	GroupID       string          `json:"groupId"`
	RootMessageID string          `json:"rootMessageId,omitempty"`
	Broadcast     bool            `json:"broadcast,omitempty"`
	DTO           WriteMessageDTO `json:"dto"`
}

type WriteGroupMessageResult added in v0.15.0

type WriteGroupMessageResult struct {
	Message ProxyMessage `json:"message"`
}

type WriteMessageDTO added in v0.15.0

type WriteMessageDTO struct {
	Blocks        []map[string]any `json:"blocks,omitempty"`
	PlainText     string           `json:"plainText,omitempty"`
	Buttons       []map[string]any `json:"buttons,omitempty"`
	Files         []map[string]any `json:"files,omitempty"`
	WebPage       map[string]any   `json:"webPage,omitempty"`
	Form          map[string]any   `json:"form,omitempty"`
	Options       []string         `json:"options,omitempty"`
	RequestID     string           `json:"requestId,omitempty"`
	BotName       string           `json:"botName,omitempty"`
	ManagerID     string           `json:"managerId,omitempty"`
	UserID        string           `json:"userId,omitempty"`
	CustomPayload map[string]any   `json:"customPayload,omitempty"`
}

Jump to

Keyboard shortcuts

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