Documentation
¶
Overview ¶
Package channel provides an abstraction for external messaging channels (e.g. WeChat, Telegram) that connect to the jcode agent as lightweight notification + remote prompt sidecars.
Index ¶
- func ApprovalMessage(toolName, toolArgs, hint string) string
- func BusyMessage() string
- func DoneMessage(summary string, err error) string
- func FormatBLE(event NotifyEvent) (cmd, val string)
- func GoodbyeMessage(t time.Time) string
- func LoginReminderMessage() string
- func RichDone(summary string, err error, t time.Time) string
- func RichIdle(t time.Time) string
- func RichWorking(t time.Time) string
- func WelcomeMessage(t time.Time) string
- type Channel
- type ChannelNotifier
- type EventType
- type LoginSession
- type Notifier
- type NotifyEvent
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApprovalMessage ¶
ApprovalMessage returns a formatted approval notification.
func BusyMessage ¶
func BusyMessage() string
BusyMessage returns a message for when a task is already in progress.
func DoneMessage ¶
DoneMessage returns a formatted task completion notification.
func FormatBLE ¶ added in v0.3.1
func FormatBLE(event NotifyEvent) (cmd, val string)
FormatBLE returns the BLE device command (cmd + val) for a notify event. The val field can display ~10 characters on the device.
func GoodbyeMessage ¶
GoodbyeMessage returns a time-aware goodbye message.
func LoginReminderMessage ¶ added in v0.2.2
func LoginReminderMessage() string
LoginReminderMessage returns a reminder that the user must send a message to activate the 24-hour session window on WeChat iLink Bot.
func RichWorking ¶ added in v0.3.1
RichWorking returns a varied "agent is working" message.
func WelcomeMessage ¶
WelcomeMessage returns a time-aware welcome message.
Types ¶
type Channel ¶
type Channel interface {
// ID returns the channel identifier (e.g. "wechat").
ID() string
// State returns the current lifecycle state.
State() State
// Login initiates the authentication flow (e.g. QR scan).
// Returns a login session that can be waited on.
Login() (*LoginSession, error)
// Logout clears credentials and stops the channel.
Logout() error
// Enable starts push notifications and inbound message polling.
Enable() error
// Disable stops push notifications and polling but keeps credentials.
Disable() error
// SendText sends a text message to the connected user.
SendText(text string) error
}
Channel is the interface that all messaging channel implementations must satisfy.
type ChannelNotifier ¶ added in v0.3.1
type ChannelNotifier struct {
// contains filtered or unexported fields
}
ChannelNotifier wraps a Channel as a Notifier, sending rich-text lifecycle notifications (working, idle, done) via the channel's SendText.
Approval events are skipped because channels like WeChat handle approvals separately with a delay mechanism in NotifyingHandler.
func NewChannelNotifier ¶ added in v0.3.1
func NewChannelNotifier(ch Channel) *ChannelNotifier
NewChannelNotifier wraps an existing Channel as a Notifier.
func (*ChannelNotifier) Available ¶ added in v0.3.1
func (n *ChannelNotifier) Available() bool
func (*ChannelNotifier) Close ¶ added in v0.3.1
func (n *ChannelNotifier) Close()
func (*ChannelNotifier) Name ¶ added in v0.3.1
func (n *ChannelNotifier) Name() string
func (*ChannelNotifier) Notify ¶ added in v0.3.1
func (n *ChannelNotifier) Notify(event NotifyEvent)
type EventType ¶ added in v0.3.1
type EventType int
EventType identifies the kind of lifecycle event sent to notifiers.
type LoginSession ¶
type LoginSession struct {
// QRCodeURL is a URL that renders a QR code image for scanning.
QRCodeURL string
// QRCodeContent is the raw content to encode as a QR code in terminal.
QRCodeContent string
// SessionKey identifies this login attempt.
SessionKey string
// WaitFunc blocks until login completes or times out. Returns nil on success.
WaitFunc func() error
}
LoginSession represents an in-progress login that requires user action (e.g. QR scan).
type Notifier ¶ added in v0.3.1
type Notifier interface {
// Name returns a human-readable identifier (e.g. "ble", "wechat").
Name() string
// Available reports whether the notifier is ready to send.
Available() bool
// Notify pushes a lifecycle event. Implementations format the event
// for their own display (short text for BLE, rich text for WeChat, etc.).
// Must be best-effort and never block the caller for long.
Notify(event NotifyEvent)
// Close releases resources. Safe to call multiple times.
Close()
}
Notifier is a lightweight one-way notification sender. Unlike Channel, it requires no login/configuration flow — it just sends short text messages to an external device or service. Implementations must be safe for concurrent use.
type NotifyEvent ¶ added in v0.3.1
type NotifyEvent struct {
Type EventType
Tool string // tool name (for EventApproval)
Err error // non-nil on failure (for EventDone)
}
NotifyEvent is the structured event passed to Notifier.Notify.
type State ¶
type State int
State represents the lifecycle state of a channel.
const ( // StateNone means the channel has never been configured (no credentials). StateNone State = iota // StateDisabled means the channel has credentials but push/receive is off. StateDisabled // StateEnabled means the channel is actively pushing notifications and receiving messages. StateEnabled )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ble provides a channel.Notifier that sends short status messages to a JCODE-* BLE IoT device using the Nordic UART Service (NUS).
|
Package ble provides a channel.Notifier that sends short status messages to a JCODE-* BLE IoT device using the Nordic UART Service (NUS). |