Help us shape the future of Go! Take the 2026 Go Developer Survey

native

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 10 Imported by: 1

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"
	FunctionGetAppNotebookVersions   = "getAppNotebookVersions"
)
View Source
const (
	FunctionGetOAuthFlow    = "getOAuthFlow"
	FunctionResumeOAuthFlow = "resumeOAuthFlow"
	FunctionCancelOAuthFlow = "cancelOAuthFlow"
)

OAuth flow operations require the initiating manager's authenticated WAM session. An app or channel token cannot grant that authority.

View Source
const DefaultAppStoreURL = "https://app-store.channel.io"
View Source
const FunctionPatchMessage = "patchMessage"
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 CancelOAuthFlowParams added in v0.15.13

type CancelOAuthFlowParams struct {
	Language *string `json:"language,omitempty"`
	FlowID   string  `json:"flowId"`
}

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) 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 GetOAuthFlowParams added in v0.15.13

type GetOAuthFlowParams struct {
	Language *string `json:"language,omitempty"`
	FlowID   string  `json:"flowId"`
}

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 OAuthFlow added in v0.15.13

type OAuthFlow struct {
	Steps            []*OAuthFlowStep `json:"steps,omitempty"`
	ID               string           `json:"id"`
	Phase            string           `json:"phase"`
	ExpiresAt        string           `json:"expiresAt"`
	Key              *string          `json:"key,omitempty"`
	TargetAuthScope  *string          `json:"targetAuthScope,omitempty"`
	AuthorizationURL *string          `json:"authorizationURL,omitempty"`
	CanResume        *bool            `json:"canResume,omitempty"`
}

type OAuthFlowResult added in v0.15.13

type OAuthFlowResult struct {
	Flow *OAuthFlow `json:"flow,omitempty"`
}

type OAuthFlowStep added in v0.15.13

type OAuthFlowStep = sdkv1.OAuthFlowStep

OAuthFlow is manager-visible onboarding state, never a provider credential.

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

type PatchMessageBody added in v0.25.0

type PatchMessageBody struct {
	Options         []string `json:"options,omitempty"`
	State           string   `json:"state,omitempty"`
	MediumSyncState string   `json:"mediumSyncState,omitempty"`
	ErrorCode       int32    `json:"errorCode,omitempty"`
}

PatchMessageBody contains fields supported by the message PATCH contract. Include a field in UpdateMask to apply it; a zero value clears that field.

type PatchMessageParams added in v0.25.0

type PatchMessageParams struct {
	ChannelID string           `json:"channelId"`
	ChatID    string           `json:"chatId"`
	ChatType  string           `json:"chatType"`
	MessageID string           `json:"messageId"`
	Body      PatchMessageBody `json:"body"`
	// Protobuf JSON field mask, for example "mediumSyncState,errorCode".
	UpdateMask string `json:"updateMask"`
}

type PatchMessageResult added in v0.25.0

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

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) PatchMessage added in v0.25.0

func (p *ProxyAPI) PatchMessage(ctx context.Context, params PatchMessageParams) (*PatchMessageResult, error)

PatchMessage updates an existing message with the specified delivery fields. The channel token must have the explicitly granted patchMessage permission.

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 RegisterExtensionResponse

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

type ResumeOAuthFlowParams added in v0.15.13

type ResumeOAuthFlowParams struct {
	Language    *string `json:"language,omitempty"`
	FlowID      string  `json:"flowId"`
	ResumeNonce *string `json:"resumeNonce,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 TokenCacheLocker added in v0.15.2

type TokenCacheLocker interface {
	WithLock(ctx context.Context, key string, fn func(context.Context) error) error
}

TokenCacheLocker is an optional extension for caches shared by multiple replicas. WithLock must invoke fn exactly once while holding a storage-backed lock for key and return fn's error unchanged.

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