receiver

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMessageTypeUnknown = errors.New("message type is unknown")

ErrMessageTypeUnknown is returned if message type (string) is not known.

View Source
var ErrNotifierClosed = errors.New("notifier is closed")

ErrNotifierClosed is returned when handlers are no longer accepting work.

Functions

func InitNotifier added in v0.3.0

func InitNotifier(ctx context.Context) (*Notifier, NotifierTrigger)

Types

type Attachment

type Attachment struct {
	ContentType     string  `json:"contentType"`
	ID              string  `json:"id"`
	Filename        *string `json:"filename"`
	Size            int     `json:"size"`
	Width           *int    `json:"width"`
	Height          *int    `json:"height"`
	Caption         *string `json:"caption"`
	UploadTimestamp *int64  `json:"uploadTimestamp"`
}

Attachment defines the attachment structure of a message.

type Client

type Client struct {
	MessageNotifier *Notifier
	// contains filtered or unexported fields
}

Client represents the Signal API client, and is returned by the New() function.

func New

func New(ctx context.Context, uri *url.URL, messageTypes ...string) (*Client, error)

New creates a new Signal API client and returns it. An error is returned if a websocket fails to open with the Signal's API /v1/receive.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) Flush

func (c *Client) Flush() []Message

Flush empties out the internal queue of messages and returns them.

func (*Client) LocalAddr added in v0.3.0

func (c *Client) LocalAddr() *net.TCPAddr

LocalAddr returns connection local address.

func (*Client) Pop

func (c *Client) Pop() *Message

Pop returns the oldest message in the queue or null if no message was found.

func (*Client) ReceiveLoop

func (c *Client) ReceiveLoop(ctx context.Context) error

ReceiveLoop is a blocking call and it loop over receiving messages over the websocket and record them internally to be consumed by either Pop() or Flush().

type DataMessage

type DataMessage struct {
	Timestamp        int64   `json:"timestamp"`
	Message          *string `json:"message"`
	ExpiresInSeconds int     `json:"expiresInSeconds"`
	ViewOnce         bool    `json:"viewOnce"`
	GroupInfo        *struct {
		GroupID   string `json:"groupId"`
		GroupName string `json:"groupName"`
		Revision  int64  `json:"revision"`
		Type      string `json:"type"`
	} `json:"groupInfo,omitempty"`
	Quote *struct {
		ID           int          `json:"id"`
		Author       string       `json:"author"`
		AuthorNumber string       `json:"authorNumber"`
		AuthorUUID   string       `json:"authorUuid"`
		Text         string       `json:"text"`
		Attachments  []Attachment `json:"attachments"`
	} `json:"quote,omitempty"`
	Mentions []struct {
		Name   string `json:"name"`
		Number string `json:"number"`
		UUID   string `json:"uuid"`
		Start  int    `json:"start"`
		Length int    `json:"length"`
	} `json:"mentions,omitempty"`
	Sticker *struct {
		PackID    string `json:"packId"`
		StickerID int    `json:"stickerId"`
	} `json:"sticker,omitempty"`
	Attachments  []Attachment `json:"attachments,omitempty"`
	RemoteDelete *struct {
		Timestamp int64 `json:"timestamp"`
	} `json:"remoteDelete,omitempty"`
}

DataMessage represents a data message.

type Envelope

type Envelope struct {
	Source         string          `json:"source"`
	SourceNumber   string          `json:"sourceNumber"`
	SourceUUID     string          `json:"sourceUuid"`
	SourceName     string          `json:"sourceName"`
	SourceDevice   int             `json:"sourceDevice"`
	Timestamp      int64           `json:"timestamp"`
	ReceiptMessage *ReceiptMessage `json:"receiptMessage,omitempty"`
	TypingMessage  *TypingMessage  `json:"typingMessage,omitempty"`
	DataMessage    *DataMessage    `json:"dataMessage,omitempty"`
	SyncMessage    *struct{}       `json:"syncMessage,omitempty"`
}

Envelope represents a message envelope.

type Message

type Message struct {
	Account  string   `json:"account"`
	Envelope Envelope `json:"envelope"`
}

Message defines the message structure received from the Signal API.

func (Message) MessageTypes

func (m Message) MessageTypes() []MessageType

MessageTypes returns the types of a message.

func (Message) MessageTypesStrings

func (m Message) MessageTypesStrings() []string

MessageTypes returns the types of a message encoded as a string.

type MessageType

type MessageType uint8

MessageType represents a type of a message.

const (
	MessageTypeUnknown MessageType = iota

	// MessageTypeReceipt represents a message that has a receipt.
	MessageTypeReceipt

	// MessageTypeTyping represents a message that has a typing.
	MessageTypeTyping

	// MessageTypeData represents a message that has data.
	MessageTypeData

	// MessageTypeDataMessage represents a message that has data and has a message.
	MessageTypeDataMessage

	// MessageTypeSync represents a message that has a sync.
	MessageTypeSync
)

func AllMessageTypes

func AllMessageTypes() []MessageType

AllMessageTypes returns all valid message types.

func ParseMessageType

func ParseMessageType(mt string) (MessageType, error)

ParseMessageType parses a message type given its representation as a string.

func (MessageType) String

func (mt MessageType) String() string

String returns the string representation of a message type.

type Notifier added in v0.4.0

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

func (*Notifier) HandlersRegistered added in v0.4.0

func (u *Notifier) HandlersRegistered() <-chan int

func (*Notifier) RegisterHandler added in v0.4.0

func (u *Notifier) RegisterHandler(_ context.Context, handler handleable)

func (*Notifier) Shutdown added in v0.4.0

func (u *Notifier) Shutdown(ctx context.Context) error

type NotifierPayload added in v0.4.0

type NotifierPayload struct {
	Message     *Message
	IsConnected *bool
}

func PrepareNotifierPayload added in v0.4.0

func PrepareNotifierPayload(message *Message, isConnected bool) NotifierPayload

type NotifierTrigger added in v0.4.0

type NotifierTrigger func(ctx context.Context, payload NotifierPayload) error

type ReceiptMessage

type ReceiptMessage struct {
	When       int64   `json:"when"`
	IsDelivery bool    `json:"isDelivery"`
	IsRead     bool    `json:"isRead"`
	IsViewed   bool    `json:"isViewed"`
	Timestamps []int64 `json:"timestamps"`
}

ReceiptMessage represents a receipt message.

type TypingMessage

type TypingMessage struct {
	Action    string `json:"action"`
	Timestamp int64  `json:"timestamp"`
}

TypingMessage represents a typing message.

Jump to

Keyboard shortcuts

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