mirror of
https://github.com/nikoksr/notify.git
synced 2025-01-26 03:20:21 +02:00
d2dfd10850
* feat(service): implemented matrix service * docs(readme): add matrix service * chore(format) Reformatted with gofumpt * docs(readme): updated readme and added doc * chore(rename): Rename functions to be compliant with project style * chore(formatting): Reformatted docs * docs(changes): Modified the service and path to it in the documentation. * chore(format): Reformated with Gofump
49 lines
1.0 KiB
Markdown
49 lines
1.0 KiB
Markdown
# Matrix
|
|
|
|
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/nikoksr/notify/service/matrix)
|
|
|
|
## Prerequisites
|
|
|
|
You will need to following information to be able to send messages to Matrix.
|
|
|
|
- Home server url
|
|
- User ID
|
|
- AccessToken
|
|
- Room ID
|
|
|
|
## Usage
|
|
|
|
In the current implementation, using this service requires 2 steps:
|
|
|
|
1. Provide the necessary credentials explicitly
|
|
2. Use the Send message to send a message to the specified room.
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/nikoksr/notify"
|
|
"github.com/nikoksr/notify/service/matrix"
|
|
)
|
|
|
|
func main() {
|
|
matrixSvc, err := matrix.New("user-id", "room-id", "home-server", "access-token")
|
|
if err != nil {
|
|
log.Fatalf("matrix.New() failed: %s", err.Error())
|
|
}
|
|
|
|
notifier := notify.New()
|
|
notifier.UseServices(matrixSvc)
|
|
|
|
err = notifier.Send(context.Background(), "", "message")
|
|
if err != nil {
|
|
log.Fatalf("notifier.Send() failed: %s", err.Error())
|
|
}
|
|
|
|
log.Println("notification sent")
|
|
}
|
|
```
|