signal

package
v0.0.0-...-ab76223 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package signal provides a minimal wrapper for the signal-cli functionality and data types that we need.

Index

Constants

This section is empty.

Variables

View Source
var SignalAttachmentsDir string = fmt.Sprintf("%s/attachments", SignalDir)
View Source
var SignalAvatarsDir string = fmt.Sprintf("%s/avatars", SignalDir)
View Source
var SignalDataDir string = fmt.Sprintf("%s/data", SignalDir)
View Source
var SignalDir string = ".local/share/signal-cli"

SignalDir is where signal-cli saves its local data

Functions

func Exec

func Exec(args ...string) ([]byte, error)

Exec invokes signal-cli with the supplied args and returns the bytes that writes to stdout

func GetSignalAvatarsFolder

func GetSignalAvatarsFolder() (string, error)

GetSignalAvatarsFolder returns the user's signal-cli avatars folder

func GetSignalFolder

func GetSignalFolder() (string, error)

GetSignalFolder returns the user's signal-cli local storage

Types

type Attachment

type Attachment struct {
	ContentType string `json:"contentType"`
	Filename    string `json:"filename"`
	ID          string `json:"id"`
	Size        int    `json:"size"`
}

type CallMessage

type CallMessage interface{}

type DataMessage

type DataMessage struct {
	Timestamp        int64         `json:"timestamp"`
	Message          string        `json:"message"`
	ExpiresInSeconds int64         `json:"expiresInSeconds"`
	Attachments      []*Attachment `json:"attachments"`
	GroupInfo        *GroupInfo    `json:"groupInfo"`
}

type Envelope

type Envelope struct {
	Source         string          `json:"source"`
	Timestamp      int64           `json:"timestamp"`
	IsReceipt      bool            `json:"isReceipt"`
	SyncMessage    *SyncMessage    `json:"syncMessage"`
	CallMessage    *CallMessage    `json:"callMessage"`
	ReceiptMessage *ReceiptMessage `json:"receiptMessage"`
	DataMessage    *DataMessage    `json:"dataMessage"`
	SourceDevice   int             `json:"sourceDevice"`
}

type ErrorCallback

type ErrorCallback func(error)

type GroupInfo

type GroupInfo struct {
	GroupID string   `json:"groupId"`
	Members []string `json:"members"`
	Name    string   `json:"name"`
	Type    string   `json:"type"`
}

type Message

type Message struct {
	Envelope *Envelope `json:"envelope"`
}

type MessageCallback

type MessageCallback func(*Message) error

type MockSignal

type MockSignal struct {
	*Signal
	// contains filtered or unexported fields
}

MockSignal implements siggo's SignalAPI interface without actually calling signal-cli for anything

func NewMockSignal

func NewMockSignal(userNumber string, exampleData []byte) *MockSignal

func (*MockSignal) Close

func (ms *MockSignal) Close()

func (*MockSignal) Receive

func (ms *MockSignal) Receive() error

func (*MockSignal) ReceiveForever

func (ms *MockSignal) ReceiveForever()

func (*MockSignal) RequestGroupInfo

func (ms *MockSignal) RequestGroupInfo() ([]SignalGroupInfo, error)

func (*MockSignal) Send

func (ms *MockSignal) Send(dest, msg string) (int64, error)

Send just sends a fake message, by putting it on the "wire"

func (*MockSignal) SendDbus

func (ms *MockSignal) SendDbus(dest, msg string, attachments ...string) (int64, error)

func (*MockSignal) SendGroupDbus

func (ms *MockSignal) SendGroupDbus(groupID, msg string, attachments ...string) (int64, error)

func (*MockSignal) Version

func (ms *MockSignal) Version() (string, error)

Version just returns the last known compatible version of signal-cli

type ReceiptCallback

type ReceiptCallback func(*Message) error

type ReceiptMessage

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

type ReceivedCallback

type ReceivedCallback func(*Message) error

type SentCallback

type SentCallback func(*Message) error

type SentMessage

type SentMessage struct {
	Timestamp        int64         `json:"timestamp"`
	Message          string        `json:"message"`
	ExpiresInSeconds int64         `json:"expiresInSeconds"`
	Attachments      []*Attachment `json:"attachments"`
	GroupInfo        *GroupInfo    `json:"groupInfo"`
	Destination      string        `json:"destination"`
	Mentions         interface{}   `json:"mentions"`
	ViewOnce         bool          `json:"viewOnce"`
}

type Signal

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

Signal represents a signal-cli session for a given user. It can be run in daemon mode by calling the `Daemon` method. It can also be used to send and receive manually using `Receive` and `Send`.

func NewSignal

func NewSignal(uname string) *Signal

NewSignal returns a new signal instance for the specified user.

func (*Signal) Close

func (s *Signal) Close()

Close cleans up any subprocesses

func (*Signal) Daemon

func (s *Signal) Daemon() error

Daemon starts the dbus daemon and receives forever.

func (*Signal) GetContactList

func (s *Signal) GetContactList() ([]*SignalContact, error)

GetContactList attempts to read an existing contact list from the signal user directory.

func (*Signal) GetGroupList

func (s *Signal) GetGroupList() ([]*SignalGroup, error)

GetGroupList attempts to read an existing contact list from the signal user directory.

func (*Signal) GetRecipientStore

func (s *Signal) GetRecipientStore() (*SignalRecipientStore, error)

GetRecipientStore gets the recipient store. This is where the contacts list is kept in signal-cli >= 0.8.2

func (*Signal) GetUserData

func (s *Signal) GetUserData() (*SignalUserData, error)

GetUserData returns the user data for the current user. this is where the contact list is kept for signal-cli < 0.8.2

func (s *Signal) Link(deviceName string) error

Link will attempt to link to an existing registered device.

func (*Signal) OnError

func (s *Signal) OnError(callback ErrorCallback)

OnError registers a callback to be executed whenever an error occurs.

func (*Signal) OnMessage

func (s *Signal) OnMessage(callback MessageCallback)

OnMessage registers a callback to be executed upon any incoming message of any kind (that we know how to process).

func (*Signal) OnReceipt

func (s *Signal) OnReceipt(callback ReceiptCallback)

OnReceipt registers a callback to be executed whenever a message receipt (for example a Read receipt or a Delivery receipt) is received.

func (*Signal) OnReceived

func (s *Signal) OnReceived(callback ReceivedCallback)

OnReceived registers a callback to be executed whenver an incoming message is received.

func (*Signal) OnSent

func (s *Signal) OnSent(callback SentCallback)

OnSent registers a callback to be executed whenver a sent message appears on the wire (currently, this is when a different linked device sends a message).

func (*Signal) ProcessWire

func (s *Signal) ProcessWire(wire []byte) error

ProcessWire processes a single wire message, executing any callbacks we have registered.

func (*Signal) Receive

func (s *Signal) Receive() error

Receive receives and processes all outstanding messages

func (*Signal) ReceiveForever

func (s *Signal) ReceiveForever()

ReceiveForever receives contiuously. WARNING: this will continuously start and stop the JVM and is not recommended unless you want to simulate the Electon app's recource useage.

func (*Signal) RequestGroupInfo

func (s *Signal) RequestGroupInfo() ([]SignalGroupInfo, error)

RequestGroupInfo requests info for all groups from the Signal network

func (*Signal) Send

func (s *Signal) Send(dest, msg string) (int64, error)

Send transmits a message to the specified number Destination is a phone number with country code. signal-cli likes to have a `+` before the number, so we add one if it isn't there.

func (*Signal) SendDbus

func (s *Signal) SendDbus(dest, msg string, attachments ...string) (int64, error)

SendDbus does the same thing as Send but it goes through a running daemon. Returns the message ID

func (*Signal) SendGroupDbus

func (s *Signal) SendGroupDbus(groupID, msg string, attachments ...string) (int64, error)

SendGroupDbus does the same thing as SendDbus but to a group

func (*Signal) Version

func (s *Signal) Version() (string, error)

Version returns the current version of signal-cli

type SignalContact

type SignalContact struct {
	Name                  string `json:"name"`
	Number                string `json:"number"`
	Color                 string `json:"color"`
	MessageExpirationTime int    `json:"messageExpirationTime"`
	ProfileKey            string `json:"profileKey"`
	Blocked               bool   `json:"blocked"`
	InboxPosition         *int   `json:"inboxPosition"`
	Archived              bool   `json:"archived"`
}

SignalContact is the data signal-cli saves for each contact in SignalDataDir/<phonenumber>. This structure no longer exists as of signal-cli >= 0.8.2

type SignalGroup

type SignalGroup struct {
	GroupID          string `json:"groupId"`
	MasterKey        string `json:"masterKey"`
	Blocked          bool   `json:"blocked"`
	PermissionDenied bool   `json:"permissionDenied"`
}

SignalGroup is the data that signal-cli saves for each group in SignalDataDir/<phonenumber>

type SignalGroupInfo

type SignalGroupInfo struct {
	ID                    string              `json:"id"`
	Name                  string              `json:"name"`
	IsMember              bool                `json:"isMember"`
	IsBlocked             bool                `json:"isBlocked"`
	Description           string              `json:"description"`
	Members               []SignalGroupMember `json:"members"`
	Admins                []SignalGroupMember `json:"admins"`
	PendingMembers        []interface{}       `json:"pendingMembers"`
	RequestingMembers     []interface{}       `json:"requestingMembers"`
	GroupInviteLink       interface{}         `json:"groupInviteLink"`
	PermissionAddMember   string              `json:"permissionAddMember"`
	PermissionEditDetails string              `json:"permissionEditDetails"`
	PermissionSendMessage string              `json:"permissionSendMessage"`
}

SignalGroupInfo is the data that is retrived for each group when we call `signal-cli listGroups` As far as I know right now that is the only way to get the group names. They don't appear to be saved in signal-cli's data.

type SignalGroupMember

type SignalGroupMember struct {
	UUID   string `json:"uuid"`
	Number string `json:"number"`
}

SignalGroupMember is a member of a signal group

type SignalRecipient

type SignalRecipient struct {
	ID                   int         `json:"id"`
	Number               string      `json:"number"`
	UUID                 string      `json:"uuid"`
	Profile              interface{} `json:"profile"`
	ProfileKey           string      `json:"profileKey"`
	ProfileKeyCredential interface{} `json:"profileKeyCredential"`
	Contact              struct {
		Name                  string `json:"name"`
		Color                 string `json:"color"`
		MessageExpirationTime int    `json:"messageExpirationTime"`
		Blocked               bool   `json:"blocked"`
		Archived              bool   `json:"archived"`
	} `json:"contact"`
}

SignalRecipient is the format used in the `recipients-store` file.

func (*SignalRecipient) AsContact

func (r *SignalRecipient) AsContact() *SignalContact

type SignalRecipientStore

type SignalRecipientStore struct {
	Recipients []*SignalRecipient `json:"recipients"`
}

SignalRecipientStore

func (*SignalRecipientStore) AsContacts

func (r *SignalRecipientStore) AsContacts() []*SignalContact

type SignalUserData

type SignalUserData struct {
	ContactStore struct {
		Contacts []*SignalContact `json:"contacts"`
	} `json:"contactStore"`
	GroupStore struct {
		Groups []*SignalGroup `json:"groups"`
	} `json:"groupStore"`
}

SignalUserData is the data signal saves for a given user in SignalDataDir/<phonenumber>

type SyncMessage

type SyncMessage struct {
	SentMessage  *SentMessage `json:"sentMessage"`
	Type         interface{}  `json:"type"`
	ReadMessages interface{}  `json:"readMessages"`
}

Jump to

Keyboard shortcuts

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