Documentation ¶
Overview ¶
This package provides a client for sending messages via Threema.Gateway.
Index ¶
- Constants
- Variables
- func PackMessage(msg Message) ([]byte, error)
- type BlobID
- type Client
- type DeliveryReceipt
- type DeliveryReceiptType
- type E2EClient
- func (c *E2EClient) GetCapabilities(id ThreemaID) ([]string, error)
- func (c *E2EClient) GetRemainingCredits() (int, error)
- func (c *E2EClient) ID() string
- func (c *E2EClient) LookupIDByEmailHash(address string) (ThreemaID, error)
- func (c *E2EClient) LookupIDByPhoneHash(phoneNumber string) (ThreemaID, error)
- func (c *E2EClient) LookupPublicKeyByID(requestedID ThreemaID) (PublicKey, error)
- func (c *E2EClient) PublicKey() PublicKey
- func (c *E2EClient) SendImage(to ThreemaID, image io.Reader) error
- func (c *E2EClient) SendTextMessage(to ThreemaID, msg string) error
- func (c *E2EClient) SendTextMessageToEmail(address string, msg string) error
- func (c *E2EClient) SendTextMessageToPhone(phone string, msg string) error
- func (c *E2EClient) SetGatewayURL(url string)
- func (c *E2EClient) SetHTTPClient(httpClient *http.Client)
- type FileMessage
- type ImageMessage
- type Message
- type MessageID
- type MessageType
- type Nonce
- type PrivateKey
- type PublicKey
- type SharedKey
- type SimpleClient
- func (c *SimpleClient) GetCapabilities(id ThreemaID) ([]string, error)
- func (c *SimpleClient) GetRemainingCredits() (int, error)
- func (c *SimpleClient) ID() string
- func (c *SimpleClient) LookupIDByEmailHash(address string) (ThreemaID, error)
- func (c *SimpleClient) LookupIDByPhoneHash(phoneNumber string) (ThreemaID, error)
- func (c *SimpleClient) SendTextMessage(to ThreemaID, msg string) error
- func (c *SimpleClient) SendTextMessageToEmail(address string, msg string) error
- func (c *SimpleClient) SendTextMessageToPhone(phone string, msg string) error
- func (c *SimpleClient) SetGatewayURL(url string)
- func (c *SimpleClient) SetHTTPClient(httpClient *http.Client)
- type TextMessage
- type ThreemaID
Constants ¶
const ( DefaultThreemaGatewayURL = "https://msgapi.threema.ch" MaxTextMessageBytes = 3500 )
const ( TypeTextMessage MessageType = 0x01 // Content: UTF-8 encoded string TypeImageMessage = 0x02 // Unsupported, TODO TypeFileMessage = 0x17 // Unsupported, TODO TypeDeliveryReceipt = 0x80 // Unsupported, TODO Received DeliveryReceiptType = 0x01 Read = 0x02 Acknowledged = 0x03 Declined = 0x04 )
Variables ¶
var ( // Caller errors ErrInvalidPhoneNumber = errors.New("invalid phone number, must consist of at most 15 digits") ErrIDLength = errors.New("id must be exactly 8 bytes long") ErrImageTooLarge = errors.New("image too large") // API errors ErrInvalidRequest = errors.New("invalid recipient or identity not set up for chosen mode (simple/e2e)") ErrMissingBlob = errors.New("missing parameters or blob is empty") ErrCredentials = errors.New("wrong id or secret for API") ErrOutOfCredits = errors.New("out of credits") ErrNotFound = errors.New("id not found") ErrMessageTooLong = errors.New("message too long") ErrBlobTooLarge = errors.New("blob too large") ErrTemporary = errors.New("temporary API failure") ErrUnknown = errors.New("unknown API error") )
Functions ¶
func PackMessage ¶ added in v0.2.0
Packs the specified message, including random padding
Types ¶
type Client ¶
type Client interface { ID() string // Fetches the remaining credits for the ID associated with the Client. GetRemainingCredits() (int, error) LookupIDByPhoneHash(phoneNumber string) (ThreemaID, error) LookupIDByEmailHash(address string) (ThreemaID, error) SendTextMessage(id ThreemaID, apiSecret string) error SendTextMessageToPhone(phone string, apiSecret string) error SendTextMessageToEmail(address string, apiSecret string) error }
type DeliveryReceipt ¶
type DeliveryReceipt struct { Type DeliveryReceiptType MessageIDs [][8]byte }
type DeliveryReceiptType ¶ added in v0.2.0
type DeliveryReceiptType byte
type E2EClient ¶
type E2EClient struct {
// contains filtered or unexported fields
}
An E2EClient has a private key to sign and encrypt messages with.
It automatically caches ID->PubKey lookups as adivsed in the Threema.Gateway documentation.
func NewE2EClient ¶
func NewE2EClient(id ThreemaID, apiSecret string, privateKey PrivateKey) (*E2EClient, error)
func (*E2EClient) GetCapabilities ¶
Returns the capabilities of the given ID. As of 01/2021, there are five supported capabilities:
- text
- image
- video
- audio
- file
func (*E2EClient) GetRemainingCredits ¶
func (*E2EClient) LookupIDByEmailHash ¶
Looks up the Threema ID of the given e-mail address by its hash. The e-mail must be passed in plaintext, it will be normalized and hashed as necessary.
Returns ErrNotFound if the given address is unknown.
func (*E2EClient) LookupIDByPhoneHash ¶
Looks up the Threema ID of the given phone number by hash. Phone number must be passed in E.164 format. It will be normalized and hashed as neceassary
Returns ErrNotFound if the given phone number is unknown.
func (*E2EClient) LookupPublicKeyByID ¶
Looks up the public key associated with the corresponding ID.
Updates the client's cache on successful lookup.
func (*E2EClient) SendImage ¶ added in v0.2.0
Send an image to the given Threema ID.
Costs 2 credits (1 to upload image, 1 to send message)
Allowed file types (list not exhaustive)
- JPEG
- PNG
func (*E2EClient) SendTextMessage ¶
Send a text message to the given Threema ID.
The public key of the recipient is cached for up to `maxCacheEntryAge`, so multiple invocations of SendTextMessage re-use existing public keys.
The message is encrypted before sending.
func (*E2EClient) SendTextMessageToEmail ¶
Send a text message to account associated with the given email address.
E-Mail->ID translations are not cached, so specifying recipients by Threema ID is preferred.
The message is encrypted before sending.
func (*E2EClient) SendTextMessageToPhone ¶
Send a text message to the account associated with the given phone number, passed in E.164 format.
Phone->ID translations are not cached, so specifying recipients by Threema ID is preferred.
The message is encrypted before sending.
func (*E2EClient) SetGatewayURL ¶ added in v0.1.1
func (c *E2EClient) SetGatewayURL(url string)
Set the base URL for the Threema.Gateway server
func (*E2EClient) SetHTTPClient ¶ added in v0.1.1
Set the http.Client to be used
type FileMessage ¶
type ImageMessage ¶
type Message ¶ added in v0.2.0
type Message interface {
// contains filtered or unexported methods
}
Abstract interface for messages
func UnpackMessage ¶ added in v0.2.0
Tries to unpack in into a valid message type.
type MessageType ¶
type MessageType byte
type PrivateKey ¶
type PrivateKey = [32]byte
type SimpleClient ¶
type SimpleClient struct {
// contains filtered or unexported fields
}
A simple client has no private key. It can only send text messages, which are encrypted using a key held by Threema.
func NewSimpleClient ¶
func NewSimpleClient(id ThreemaID, apiSecret string) (*SimpleClient, error)
func (*SimpleClient) GetCapabilities ¶
Returns the capabilities of the given ID. As of 01/2021, there are five supported capabilities:
- text
- image
- video
- audio
- file
func (*SimpleClient) GetRemainingCredits ¶
func (*SimpleClient) ID ¶ added in v0.1.1
func (c *SimpleClient) ID() string
Returns the client's ID
func (*SimpleClient) LookupIDByEmailHash ¶
Looks up the Threema ID of the given e-mail address by its hash. The e-mail must be passed in plaintext, it will be normalized and hashed as necessary.
Returns ErrNotFound if the given address is unknown.
func (*SimpleClient) LookupIDByPhoneHash ¶
Looks up the Threema ID of the given phone number by hash. Phone number must be passed in E.164 format. It will be normalized and hashed as neceassary
Returns ErrNotFound if the given phone number is unknown.
func (*SimpleClient) SendTextMessage ¶
func (c *SimpleClient) SendTextMessage(to ThreemaID, msg string) error
Send a message to the given Threema ID.
The message is sent in plaintext and encrypted at the Threema servers.
func (*SimpleClient) SendTextMessageToEmail ¶
func (c *SimpleClient) SendTextMessageToEmail(address string, msg string) error
Send a message to account associated with the given email address.
The message is sent in plaintext and encrypted at the Threema servers.
func (*SimpleClient) SendTextMessageToPhone ¶
func (c *SimpleClient) SendTextMessageToPhone(phone string, msg string) error
Send a message to the given phone number, passed in E.164 format.
The message is sent in plaintext and encrypted at the Threema servers.
func (*SimpleClient) SetGatewayURL ¶ added in v0.1.1
func (c *SimpleClient) SetGatewayURL(url string)
Set the base URL for the Threema.Gateway server
func (*SimpleClient) SetHTTPClient ¶ added in v0.1.1
Set the http.Client to be used
type TextMessage ¶
type TextMessage struct {
Content string
}