a simple matrix package for basic actions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
emile 950971ef47
added some information regarding the functions to the README.md
3 months ago
example initial commit 3 months ago
README.md added some information regarding the functions to the README.md 3 months ago
go.mod updated the go module 3 months ago
go.sum more go module foo 3 months ago
join.go the functions handling almost everything I need 3 months ago
login.go the functions handling almost everything I need 3 months ago
send.go the functions handling almost everything I need 3 months ago
structs.go the functions handling almost everything I need 3 months ago
sync.go the functions handling almost everything I need 3 months ago

README.md

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.