about summary refs log tree commit diff

matrix

This is a minimal implementation of the endpoints matrix provides for communication inbetween the client and the server.

Functions

The basic functions availible are described below. I'm pretty sure that I won't update these farily often, so you're better of just using go doc for searching through the functionnns.

Login

func Login(username, password, homeserver string) (Authinfo, error)

Used to get an authinfo struct containing information needed by other function for functioning properly, such as the auth key needed to send messages.

Send

func Send(authinfo Authinfo, roomID string, message string) error
func SendImage(authinfo Authinfo, roomID string, image map[string]interface{}) error

Send and message or and image to a room you are in. (Sending images is done by providing a map with information on the image:

    image := map[string]interface{}{
        "msgtype": "m.image",
        "url":     mxc://matrix.emile.space/askhdlkajshdlkajhdslkjh,
        "info": map[string]interface{}{
            "h":        1080,
            "w":        1920,
            "mimetype": "image/jpeg",
            "size":     1337,
        },
        "body": "some text associated with the image",
}

Most important: the url, that actually isn't a url but a mxc URI. To get one upload your image using the upload function, you'll get that uri in the response.

Sync

func Sync(authinfo Authinfo) (RespSync, error)
func SyncPartial(authinfo Authinfo, nextBatch string, eventsChannel chan PackagedEvent) (RespSync, error)

There are two syncs available: Sync and syncPartial. Sync is used to syncronize the first time in order to get all events created. SyncPartial uses a token returned by the Sync function to fetch all events created since that token was given out (sort of a timestamp).

This allows incremental fetches.

Upload

func Upload(authinfo Authinfo, filename string, file *bytes.Buffer) (UploadResponse, error)

The upload function uploads the given buffer to the homeserver that is provided in the authinfo object. The response contains the mxc URI that can be used to send the uploaded image to another participant.