Documentation
¶
Overview ¶
Package bot stores profile-local Bot/Group settings, contact execution permissions, and external IM channel configurations independently of session history or product-specific task boards.
Index ¶
- Constants
- Variables
- func ChannelSecretField(key string) bool
- func NormalizeContactKey(raw string) string
- func TruncateUTF8Bytes(s string, maxBytes int) string
- func ValidSenderAvatar(raw string) bool
- type ChannelConfig
- func (c ChannelConfig) ChannelKey() string
- func (c ChannelConfig) ExternalMemberByID(senderID string) (ExternalMember, bool)
- func (c ChannelConfig) IMAccountKey() string
- func (c ChannelConfig) PublicChannel() ChannelConfig
- func (c *ChannelConfig) RetainChannelSecrets(old ChannelConfig)
- func (c ChannelConfig) Validate() error
- type ChannelDriver
- type ChannelEffect
- type ChannelKind
- type ChannelReceipt
- type ExternalMember
- type ExternalMemberRole
- type IMChannelStatus
- type StateSnapshot
- type Store
- func (s *Store) BindReceiptTurn(channelID, eventID string, turn protocol.TurnID) error
- func (s *Store) ContactPermission(target string) protocol.Permission
- func (s *Store) ContactPermissions() (map[string]protocol.Permission, error)
- func (s *Store) DeleteChannel(id string, expectedRevision uint64) error
- func (s *Store) DeleteReceipt(channelID, eventID string) error
- func (s *Store) FindReceiptByTurn(turn protocol.TurnID) (ChannelConfig, ChannelReceipt, bool, error)
- func (s *Store) IMCursor(account string) (string, error)
- func (s *Store) ListChannels() ([]ChannelConfig, error)
- func (s *Store) ListPublicChannels() ([]ChannelConfig, error)
- func (s *Store) MarkEffectDelivered(effectID string) error
- func (s *Store) MarkEffectFailed(effectID, errMsg string) error
- func (s *Store) PendingEffects(channelID string) ([]ChannelEffect, error)
- func (s *Store) QueueTurnReplyEffect(ch ChannelConfig, r ChannelReceipt, turn protocol.TurnID, text string) (ChannelEffect, bool, error)
- func (s *Store) RecordReceipt(r ChannelReceipt) (bool, error)
- func (s *Store) SaveChannel(in ChannelConfig, expectedRevision uint64) (ChannelConfig, error)
- func (s *Store) SaveIMCursor(account, cursor string) error
- func (s *Store) SetContactPermission(target string, perm protocol.Permission) error
Constants ¶
const ( // ModuleID is the stable native Node module ID for Harness modules/bot. ModuleID = "bot" // DefaultAssociationNamespace is the default native discussion namespace // owned by Harness modules/bot. Products may override it for profile // compatibility via botnode.WithAssociationNamespace. DefaultAssociationNamespace = "sailry-bot" // BotDeskAssociation identifies a 1-on-1 Bot contact conversation. BotDeskAssociation = "bot_desk" // SquadDeskAssociation identifies a multi-Bot Group conversation. SquadDeskAssociation = "squad_desk" // DefaultBotID identifies the built-in default Bot when present. DefaultBotID = "default" )
Variables ¶
var ( ErrChannelNotFound = errors.New("channel not found") ErrRevisionConflict = errors.New("revision conflict") )
var ChannelDrivers = []ChannelDriver{ {ID: "feishu", Label: "Feishu", Fields: []string{"app_id", "app_secret"}}, {ID: "wecom", Label: "WeCom", Fields: []string{"bot_id", "secret"}}, {ID: "weixin", Label: "WeChat (ClawBot)", Fields: []string{"bot_token"}, OptionalFields: []string{"bot_id", "base_url"}, QRLogin: true}, {ID: "dingtalk", Label: "DingTalk", Fields: []string{"app_id", "app_secret"}}, {ID: "slack", Label: "Slack", Fields: []string{"app_token", "bot_token"}}, {ID: "discord", Label: "Discord", Fields: []string{"bot_token"}}, {ID: "telegram", Label: "Telegram", Fields: []string{"bot_token"}}, }
ChannelDrivers lists all built-in external IM channel transports supported by Harness modules/bot. Issue/feedback trackers (GitHub, Linear, Sentry) belong in product modules such as Sailry Code, never here.
Functions ¶
func ChannelSecretField ¶
ChannelSecretField reports whether config key holds a secret credential.
func NormalizeContactKey ¶
NormalizeContactKey canonicalizes a contact key ("role:<uuid>", "team:<uuid>", or "bot:<id>"). It returns "" for unrecognized values.
func TruncateUTF8Bytes ¶
TruncateUTF8Bytes truncates s to at most maxBytes without splitting a UTF-8 rune.
func ValidSenderAvatar ¶
ValidSenderAvatar reports whether raw is a safe https avatar URL.
Types ¶
type ChannelConfig ¶
type ChannelConfig struct {
ID string `json:"id"`
Revision uint64 `json:"revision"`
Kind ChannelKind `json:"kind"`
Driver string `json:"driver,omitempty"`
PackageID string `json:"package_id,omitempty"`
Name string `json:"name,omitempty"`
Target string `json:"target,omitempty"`
TargetRecipient string `json:"target_recipient"`
Enabled bool `json:"enabled"`
Config map[string]string `json:"config,omitempty"`
ConfiguredSecrets []string `json:"configured_secrets,omitempty"`
AllowOwnerCommands bool `json:"allow_owner_commands,omitempty"`
OwnerExternalID string `json:"owner_external_id,omitempty"`
ExternalMembers []ExternalMember `json:"external_members,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
}
ChannelConfig stores one external IM channel binding for a Bot or Group.
func (ChannelConfig) ChannelKey ¶
func (c ChannelConfig) ChannelKey() string
ChannelKey returns the canonical package/driver key for status lookups.
func (ChannelConfig) ExternalMemberByID ¶
func (c ChannelConfig) ExternalMemberByID(senderID string) (ExternalMember, bool)
ExternalMemberByID resolves senderID against ExternalMembers (and legacy OwnerExternalID).
func (ChannelConfig) IMAccountKey ¶
func (c ChannelConfig) IMAccountKey() string
IMAccountKey returns a stable, non-secret hash identifying the underlying IM bot connection so multiple bindings can share one socket/cursor.
func (ChannelConfig) PublicChannel ¶
func (c ChannelConfig) PublicChannel() ChannelConfig
PublicChannel returns a copy of c with all secret credentials removed from Config and recorded only by key name in ConfiguredSecrets.
func (*ChannelConfig) RetainChannelSecrets ¶
func (c *ChannelConfig) RetainChannelSecrets(old ChannelConfig)
RetainChannelSecrets preserves existing secret credentials when an edit leaves secret fields blank for the same driver and app/bot identity.
func (ChannelConfig) Validate ¶
func (c ChannelConfig) Validate() error
Validate checks a ChannelConfig before persistence.
type ChannelDriver ¶
type ChannelDriver struct {
ID string `json:"id"`
Label string `json:"label"`
Fields []string `json:"fields"`
OptionalFields []string `json:"optional_fields,omitempty"`
QRLogin bool `json:"qr_login,omitempty"`
}
ChannelDriver describes the configuration a built-in IM transport requires.
func BuiltinChannelDriver ¶
func BuiltinChannelDriver(id string) (ChannelDriver, bool)
BuiltinChannelDriver looks up a built-in IM driver by ID.
type ChannelEffect ¶
type ChannelEffect struct {
ID string `json:"id"`
ChannelID string `json:"channel_id"`
Event string `json:"event"`
ExternalID string `json:"external_id,omitempty"`
Target string `json:"target,omitempty"`
ThreadID string `json:"thread_id,omitempty"`
ReplyTo string `json:"reply_to,omitempty"`
Title string `json:"title,omitempty"`
Summary string `json:"summary,omitempty"`
Detail string `json:"detail,omitempty"`
Turn protocol.TurnID `json:"turn,omitzero"`
Delivered bool `json:"delivered,omitempty"`
Attempts int `json:"attempts,omitempty"`
LastError string `json:"last_error,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
}
ChannelEffect is a queued outbound IM delivery (typically a turn_reply).
type ChannelKind ¶
type ChannelKind string
ChannelKind distinguishes built-in IM drivers from plugin-supplied channels.
const ( ChannelKindBuiltin ChannelKind = "channel" ChannelKindPlugin ChannelKind = "plugin" )
type ChannelReceipt ¶
type ChannelReceipt struct {
ChannelID string `json:"channel_id"`
EventID string `json:"event_id"`
ExternalID string `json:"external_id,omitempty"`
Target string `json:"target,omitempty"`
ThreadID string `json:"thread_id,omitempty"`
ReplyTo string `json:"reply_to,omitempty"`
SenderID string `json:"sender_id,omitempty"`
Turn protocol.TurnID `json:"turn,omitzero"`
CreatedAt int64 `json:"created_at,omitempty"`
}
ChannelReceipt records an admitted inbound IM message so duplicate deliveries are ignored and completed turns can route their reply back to the exact chat and thread.
type ExternalMember ¶
type ExternalMember struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Role ExternalMemberRole `json:"role"`
}
ExternalMember binds an external IM user ID to a local role.
type ExternalMemberRole ¶
type ExternalMemberRole string
ExternalMemberRole classifies an external IM participant.
const ( ExternalMemberOwner ExternalMemberRole = "owner" ExternalMemberMember ExternalMemberRole = "member" )
type IMChannelStatus ¶
type IMChannelStatus struct {
ChannelKey string `json:"channel_key"`
ConnectionKey string `json:"connection_key"`
Connected bool `json:"connected"`
BotName string `json:"bot_name,omitempty"`
LastError string `json:"last_error,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
}
IMChannelStatus reports the live connection state of one IM channel worker.
type StateSnapshot ¶
type StateSnapshot struct {
ContactPermissions map[string]protocol.Permission `json:"contact_permissions"`
Channels []ChannelConfig `json:"channels"`
BuiltinDrivers []ChannelDriver `json:"builtin_drivers"`
ChannelStatuses []IMChannelStatus `json:"channel_statuses,omitempty"`
}
StateSnapshot is returned by the "get_state" native module action.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists profile-local Bot/Group settings and IM channel state.
func (*Store) BindReceiptTurn ¶
BindReceiptTurn attaches a queued TurnID to an already-recorded receipt.
func (*Store) ContactPermission ¶
func (s *Store) ContactPermission(target string) protocol.Permission
ContactPermission returns the saved execution permission for target, or protocol.PermissionSmart when unset.
func (*Store) ContactPermissions ¶
func (s *Store) ContactPermissions() (map[string]protocol.Permission, error)
ContactPermissions returns a copy of all saved contact permissions.
func (*Store) DeleteChannel ¶
DeleteChannel removes a channel by ID and expected revision.
func (*Store) DeleteReceipt ¶
DeleteReceipt removes an uncommitted inbound IM receipt so a transient admission failure can be retried on redelivery instead of being lost.
func (*Store) FindReceiptByTurn ¶
func (s *Store) FindReceiptByTurn(turn protocol.TurnID) (ChannelConfig, ChannelReceipt, bool, error)
FindReceiptByTurn looks up the IM channel and receipt that triggered turn.
func (*Store) ListChannels ¶
func (s *Store) ListChannels() ([]ChannelConfig, error)
ListChannels returns all stored channels (including secrets for Node-internal driver execution). Call PublicChannel() before returning to clients.
func (*Store) ListPublicChannels ¶
func (s *Store) ListPublicChannels() ([]ChannelConfig, error)
ListPublicChannels returns all stored channels with secret credentials redacted.
func (*Store) MarkEffectDelivered ¶
MarkEffectDelivered marks an outbound effect as delivered.
func (*Store) MarkEffectFailed ¶
MarkEffectFailed records a failed delivery attempt on an outbound effect.
func (*Store) PendingEffects ¶
func (s *Store) PendingEffects(channelID string) ([]ChannelEffect, error)
PendingEffects returns undelivered outbound effects for channelID.
func (*Store) QueueTurnReplyEffect ¶
func (s *Store) QueueTurnReplyEffect(ch ChannelConfig, r ChannelReceipt, turn protocol.TurnID, text string) (ChannelEffect, bool, error)
QueueTurnReplyEffect enqueues an outbound plain-text IM reply for a completed turn, deduplicated by (ChannelID, Turn).
func (*Store) RecordReceipt ¶
func (s *Store) RecordReceipt(r ChannelReceipt) (bool, error)
RecordReceipt records an inbound IM event if not already recorded. Returns (true, nil) if newly recorded, (false, nil) if duplicate.
func (*Store) SaveChannel ¶
func (s *Store) SaveChannel(in ChannelConfig, expectedRevision uint64) (ChannelConfig, error)
SaveChannel creates or updates a ChannelConfig with revision CAS and secret retention on edit. Returns the saved config with secrets redacted.
func (*Store) SaveIMCursor ¶
SaveIMCursor persists the polling cursor for an IM account.
func (*Store) SetContactPermission ¶
func (s *Store) SetContactPermission(target string, perm protocol.Permission) error
SetContactPermission saves the execution permission (ask/smart/full) for a Bot or Group contact.