matrix

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: MIT Imports: 6 Imported by: 0

README

Matrix

go.dev reference

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.
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")
}

Documentation

Overview

Package matrix provides message notification integration for Matrix.

Usage:

package main

import (
	"log"

	"github.com/nikoksr/notify"
	"github.com/nikoksr/notify/service/matrix"
)

func main() {
	matrixSvc, err := matrix.New("fake-user-id", "fake-room-id", "fake-home-server", "fake-access-token")

	if err != nil {
		log.Fatalf("matrix.New() failed: %s", err.Error())
	}

	notifier := notify.New()
	notifier.UseServices(matrixSvc)

	err = notifier.Send(context.Background(), "subject", "message")
	if err != nil {
		log.Fatalf("notifier.Send() failed: %s", err.Error())
	}

	log.Println("notification sent")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

Matrix struct that holds necessary data to communicate with the Matrix API.

func New

func New(userID id.UserID, roomID id.RoomID, homeServer, accessToken string) (*Matrix, error)

New returns a new instance of a Matrix notification service. For more information about the Matrix api specs:

-> https://spec.matrix.org/v1.2/client-server-api

func (*Matrix) Send

func (s *Matrix) Send(ctx context.Context, _, message string) error

Send takes a message body and sends them to the previously set channel. you will need an account, access token and roomID see https://matrix.org

type Message

type Message struct {
	Body          string            `json:"body"`
	Format        string            `json:"format,omitempty"`
	FormattedBody string            `json:"formatted_body,omitempty"`
	Msgtype       event.MessageType `json:"msgtype"`
}

Message structure that reassembles the SendMessageEvent.

type ServiceOptions

type ServiceOptions struct {
	// contains filtered or unexported fields
}

ServiceOptions allow you to configure the Matrix client options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL