pulsesms

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0 Imports: 21 Imported by: 4

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 (
	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 added in v0.0.3

type AccountID string

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

type BasicCredentials added in v0.0.6

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 added in v0.0.4

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

type ChatID added in v0.0.7

type ChatID = string

type Client

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

func New

func New() *Client

func (*Client) AccountID added in v0.0.6

func (c *Client) AccountID() AccountID

func (*Client) Disconnect added in v0.0.9

func (c *Client) Disconnect()

func (*Client) GenerateKey added in v0.0.6

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

GenerateKey generates and configures the client's encryption key

func (*Client) GetChat added in v0.0.7

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

func (*Client) GetContactByName added in v0.0.7

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

func (*Client) GetContactByPhone added in v0.0.7

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

func (*Client) GetKeyCredentials added in v0.0.6

func (c *Client) GetKeyCredentials() KeyCredentials

func (*Client) GetMessages

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

func (*Client) IsConnected added in v0.0.7

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 added in v0.0.4

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

func (*Client) SendMessage

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

func (*Client) SetMessageHandler

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

func (*Client) Stream

func (c *Client) Stream() error

func (*Client) Sync added in v0.0.4

func (c *Client) Sync() error

type Contact added in v0.0.4

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

type DeviceID added in v0.0.3

type DeviceID = int

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

type KeyCredentials added in v0.0.6

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"`
	Type           int            `json:"message_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 added in v0.0.7

func (m Message) ChatID() ChatID

func (Message) Received added in v0.0.9

func (m Message) Received() bool

func (Message) Sent added in v0.0.9

func (m Message) Sent() bool

func (Message) UnixTime added in v0.0.9

func (m Message) UnixTime() time.Time

type MessageID added in v0.0.3

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 added in v0.0.4

type PhoneNumber = string

type Store added in v0.0.4

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