Phase 10: Define TypingCapable, MessageEditor, PlaceholderRecorder interfaces. Manager orchestrates outbound typing stop and placeholder editing via preSend. Migrate Telegram, Discord, Slack, OneBot to register state with Manager instead of handling locally in Send. Phase 7: Add native WebSocket Pico Protocol channel as reference implementation of all optional capability interfaces.
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package pico
|
|
|
|
import "time"
|
|
|
|
// Protocol message types.
|
|
const (
|
|
// Client → Server
|
|
TypeMessageSend = "message.send"
|
|
TypeMediaSend = "media.send"
|
|
TypePing = "ping"
|
|
|
|
// Server → Client
|
|
TypeMessageCreate = "message.create"
|
|
TypeMessageUpdate = "message.update"
|
|
TypeMediaCreate = "media.create"
|
|
TypeTypingStart = "typing.start"
|
|
TypeTypingStop = "typing.stop"
|
|
TypeError = "error"
|
|
TypePong = "pong"
|
|
)
|
|
|
|
// PicoMessage is the wire format for all Pico Protocol messages.
|
|
type PicoMessage struct {
|
|
Type string `json:"type"`
|
|
ID string `json:"id,omitempty"`
|
|
SessionID string `json:"session_id,omitempty"`
|
|
Timestamp int64 `json:"timestamp,omitempty"`
|
|
Payload map[string]any `json:"payload,omitempty"`
|
|
}
|
|
|
|
// newMessage creates a PicoMessage with the given type and payload.
|
|
func newMessage(msgType string, payload map[string]any) PicoMessage {
|
|
return PicoMessage{
|
|
Type: msgType,
|
|
Timestamp: time.Now().UnixMilli(),
|
|
Payload: payload,
|
|
}
|
|
}
|
|
|
|
// newError creates an error PicoMessage.
|
|
func newError(code, message string) PicoMessage {
|
|
return newMessage(TypeError, map[string]any{
|
|
"code": code,
|
|
"message": message,
|
|
})
|
|
}
|