pulsesms

package module
v0.0.0-...-af550c7 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

README

pulsesms

A golang API client for Pulse SMS.

This library is currently very minimal. It only serves to receive new messages, retrieve existing messages, and send messages into a conversation.

The main purpose of this library is to be used in a matrix bridge. Future improvements may be made to extend the bridge functionality or become more useful overall.

See the example for how to use the client.

Documentation

Index

Constants

View Source
const (
	ReceivedMessage       MessageAction = 0
	SentMessage                         = 1
	ReadConversation                    = 2
	RemovedMessage                      = 3
	UpdatedConversation                 = 4
	DismissedNotification               = 5
	ConnectionError                     = 999
)
View Source
const (
	EndpointLogin              = "accounts/login/"
	EndpointUpdateSetting      = "accounts/update_setting"
	EndpointMessages           = "messages/"
	EndpointRemoveMessage      = "messages/remove/"
	EndpointAddMessage         = "messages/add/"
	EndpointNewThread          = "messages/forward_to_phone"
	EndpointFolders            = "folders/"
	EndpointRemoveFolder       = "folders/remove/"
	EndpointConversations      = "conversations/"
	EndpointConversation       = "conversations/"
	EndpointUpdateConversation = "conversations/update/"
	EndpointRead               = "conversations/read/"
	EndpointArchive            = "conversations/archive/"
	EndpointUnarchive          = "conversations/unarchive/"
	EndpoinntDelete            = "conversations/remove/"
	EndpointDismiss            = "accounts/dismissed_notification/"
	Endpointsettings           = "accounts/settings/"
	EndpointWebsocket          = "stream"
	EndpointMedia              = "media/"
	EndpointContacts           = "contacts/simple/"
	EndpointRemoveContact      = "contacts/remove_ids/"
	EndpointBlacklists         = "blacklists"
	EndpointRemoveBlacklist    = "blacklists/remove/"
	EndpointCreateBlacklist    = "blacklists/add/"
	EndpointScheduled          = "scheduled_messages"
	EndpointRemoveScheduled    = "scheduled_messages/remove/"
	EndpointCreateScheduled    = "scheduled_messages/add/"
	EndpointAccountStats       = "accounts/count"
	EndpointDrafts             = "drafts"
	EndpointDraftsConversation = "drafts/"
	EndpointCreateDrafts       = "drafts/add/"
	EndpointRemoveDrafts       = "drafts/remove/"
	EndpointReplaceDrafts      = "drafts/replace/"
	EndpointDevices            = "devices"
	EndpointRemoveDevice       = "devices/remove/"
	EndpointTemplates          = "templates"
	EndpointCreateTemplate     = "templates/add/"
	EndpointUpdateTemplate     = "templates/update/"
	EndpointRemoveTemplate     = "templates/remove/"
	EndpointAutoReplies        = "auto_replies"
	EndpointRemoveAutoReply    = "auto_replies/remove/"
)

Variables

This section is empty.

Functions

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int, after int) []byte

Types

type AccountID

type AccountID string

AccountID is a PulseSMS account ID this reflects the Pulse SMS subscriber, not a contact or "sms user"

type BasicCredentials

type BasicCredentials struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

LoginCredentials is used for basic username/password login These are required to obtain KeyCredentials required for encryption

type Chat

type Chat struct {
	ID              ChatID
	Name            string
	ModifyTag       string
	Read            bool
	LastMessageTime int64
	MutedUntil      int64
	IsMarkedSpam    bool
	IsArchived      bool
	IsPinned        bool
	Members         []PhoneNumber
	// Source          map[string]string
	ReceivedAt time.Time
}

type ChatID

type ChatID = string

type Client

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

func New

func New() *Client

func (*Client) AccountID

func (c *Client) AccountID() AccountID

func (*Client) Disconnect

func (c *Client) Disconnect()

func (*Client) GenerateKey

func (c *Client) GenerateKey(creds KeyCredentials) error

GenerateKey generates and configures the client's encryption key

func (*Client) GetChat

func (c *Client) GetChat(chatID ChatID) (Chat, bool)

func (*Client) GetContactByName

func (c *Client) GetContactByName(name string) (Contact, bool)

func (*Client) GetContactByPhone

func (c *Client) GetContactByPhone(phone PhoneNumber) (Contact, bool)

func (*Client) GetKeyCredentials

func (c *Client) GetKeyCredentials() KeyCredentials

func (*Client) GetMessages

func (c *Client) GetMessages(conversationID int, offset int) ([]Message, error)

func (*Client) IsConnected

func (c *Client) IsConnected() bool

func (*Client) Login

func (c *Client) Login(creds BasicCredentials) error

Login authenticates with pulse and setups up client encryption

func (*Client) Send

func (c *Client) Send(data string, chatID ChatID) error

func (*Client) SendMessage

func (c *Client) SendMessage(m Message, chatID string) error

func (*Client) SetKeyCredentials

func (c *Client) SetKeyCredentials(accountID AccountID, password string, salt1 string, salt2 string) error

func (*Client) SetMessageHandler

func (c *Client) SetMessageHandler(f func(Message, MessageAction))

func (*Client) Stream

func (c *Client) Stream() error

func (*Client) Sync

func (c *Client) Sync() error

func (*Client) SyncContacts

func (c *Client) SyncContacts() error

type Contact

type Contact struct {
	PhoneNumber PhoneNumber
	Notify      string
	Name        string
	Short       string
}

type DeviceID

type DeviceID = int

DeviceID is the generated internal ID of the device used to interact with a PulseSMS account

type KeyCredentials

type KeyCredentials struct {
	// the account id required to access API resources
	AccountID AccountID

	// hash of account password and pepper (salt2)
	PasswordHash string

	// salt used
	Salt string
}

KeyCredentials are the inputs used to generate an encryption key Note these can only be generated after calling Login

type Message

type Message struct {
	ID             MessageID      `json:"id,omitempty"`
	ConversationID conversationID `json:"conversation_id,omitempty"`
	DeviceID       DeviceID       `json:"device_id,omitempty"`
	MessageType    int            `json:"message_type,omitempty"`
	Type           int            `json:"type,omitempty"`
	Data           string         `json:"data,omitempty"`
	Timestamp      int64          `json:"timestamp,omitempty"`
	MimeType       string         `json:"mime_type,omitempty"`
	Read           bool           `json:"read,omitempty"`
	Seen           bool           `json:"seen,omitempty"`
	From           string         `json:"message_from,omitempty"`
	Archive        bool           `json:"archive,omitempty"`
	SentDevice     DeviceID       `json:"sent_device,omitempty"`
	SimStamp       string         `json:"sim_stamp,omitempty"`
	Snippet        string         `json:"snippet,omitempty"`
}

func (Message) ChatID

func (m Message) ChatID() ChatID

func (Message) Received

func (m Message) Received() bool

func (Message) Sent

func (m Message) Sent() bool

func (Message) UnixTime

func (m Message) UnixTime() time.Time

type MessageAction

type MessageAction int64

type MessageID

type MessageID = int

MessageID is the internal ID of a Pulse SMS message

type NotificationMessage

type NotificationMessage struct {
	Operation string  `json:"operation,omitempty"`
	Content   Message `json:"content,omitempty"`
}

type PhoneNumber

type PhoneNumber = string

type Store

type Store struct {
	sync.Mutex
	Contacts map[PhoneNumber]Contact
	Chats    map[ChatID]Chat
}

type WSMessage

type WSMessage struct {
	Identifier string              `json:"identifier,omitempty"`
	Message    NotificationMessage `json:"message,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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