types

package
Version: v0.0.0-...-67a82fc Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(u string) error

BaseURL sets the base URL of NEB to the url given. This URL must be accessible from the public internet.

func PollingServiceTypes

func PollingServiceTypes() (types []string)

PollingServiceTypes returns a list of service types which meet the Poller interface

func RegisterAuthRealm

func RegisterAuthRealm(factory func(string, string) AuthRealm)

RegisterAuthRealm registers a factory for creating AuthRealm instances.

func RegisterService

func RegisterService(factory func(string, id.UserID, string) Service)

RegisterService registers a factory for creating Service instances.

Types

type AuthRealm

type AuthRealm interface {
	ID() string
	Type() string
	Init() error
	Register() error
	OnReceiveRedirect(w http.ResponseWriter, req *http.Request)
	AuthSession(id string, userID id.UserID, realmID string) AuthSession
	RequestAuthSession(userID id.UserID, config json.RawMessage) interface{}
}

AuthRealm represents a place where a user can authenticate themselves. This may static (like github.com) or a specific domain (like matrix.org/jira)

func CreateAuthRealm

func CreateAuthRealm(realmID, realmType string, realmJSON []byte) (AuthRealm, error)

CreateAuthRealm creates an AuthRealm of the given type and realm ID. Returns an error if the realm couldn't be created or the JSON cannot be unmarshalled.

type AuthSession

type AuthSession interface {
	ID() string
	UserID() id.UserID
	RealmID() string
	Authenticated() bool
	Info() interface{}
}

AuthSession represents a single authentication session between a user and an auth realm.

type BotOptions

type BotOptions struct {
	RoomID      id.RoomID
	UserID      id.UserID
	SetByUserID id.UserID
	Options     map[string]interface{}
}

BotOptions for a given bot user in a given room

type Command

type Command struct {
	Path      []string
	Arguments []string
	Help      string
	Command   func(roomID id.RoomID, userID id.UserID, arguments []string) (content interface{}, err error)
}

A Command is something that a user invokes by sending a message starting with '!' followed by a list of strings that name the command, followed by a list of argument strings. The argument strings may be quoted using '\"' and '\” in the same way that they are quoted in the unix shell.

func (*Command) Matches

func (command *Command) Matches(arguments []string) bool

Matches if the arguments start with the path of the command.

type DefaultService

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

DefaultService NO-OPs the implementation of optional Service interface methods. Feel free to override them.

func NewDefaultService

func NewDefaultService(serviceID string, serviceUserID id.UserID, serviceType string) DefaultService

NewDefaultService creates a new service with implementations for ServiceID(), ServiceType() and ServiceUserID()

func (*DefaultService) Commands

func (s *DefaultService) Commands(cli MatrixClient) []Command

Commands returns no commands.

func (*DefaultService) Expansions

func (s *DefaultService) Expansions(cli MatrixClient) []Expansion

Expansions returns no expansions.

func (*DefaultService) OnReceiveWebhook

func (s *DefaultService) OnReceiveWebhook(w http.ResponseWriter, req *http.Request, cli MatrixClient)

OnReceiveWebhook does nothing but 200 OK the request.

func (*DefaultService) PostRegister

func (s *DefaultService) PostRegister(oldService Service)

PostRegister does nothing.

func (*DefaultService) Register

func (s *DefaultService) Register(oldService Service, cli MatrixClient) error

Register does nothing and returns no error.

func (*DefaultService) ServiceID

func (s *DefaultService) ServiceID() string

ServiceID returns the service's ID. In order for this to return the ID, DefaultService MUST have been initialised by NewDefaultService, the zero-initialiser is NOT enough.

func (*DefaultService) ServiceType

func (s *DefaultService) ServiceType() string

ServiceType returns the type of service. See each individual service package for the ServiceType constant to find out what this value actually is. In order for this to return the Type, DefaultService MUST have been initialised by NewDefaultService, the zero-initialiser is NOT enough.

func (*DefaultService) ServiceUserID

func (s *DefaultService) ServiceUserID() id.UserID

ServiceUserID returns the user ID that the service sends events as. In order for this to return the service user ID, DefaultService MUST have been initialised by NewDefaultService, the zero-initialiser is NOT enough.

type Expansion

type Expansion struct {
	Regexp *regexp.Regexp
	Expand func(roomID id.RoomID, userID id.UserID, matchingGroups []string) interface{}
}

An Expansion is something that actives when the user sends any message containing a string matching a given pattern. For example an RFC expansion might expand "RFC 6214" into "Adaptation of RFC 1149 for IPv6" and link to the appropriate RFC.

type MatrixClient

type MatrixClient interface {
	// Join a room by ID or alias. Content can optionally specify the request body.
	JoinRoom(roomIDorAlias, serverName string, content interface{}) (resp *mautrix.RespJoinRoom, err error)
	// Send a message event to a room.
	SendMessageEvent(roomID id.RoomID, eventType event.Type, contentJSON interface{},
		extra ...mautrix.ReqSendEvent) (resp *mautrix.RespSendEvent, err error)
	// Upload an HTTP URL.
	UploadLink(link string) (*mautrix.RespMediaUpload, error)
}

MatrixClient represents an object that can communicate with a Matrix server in certain ways that services require.

type Poller

type Poller interface {
	// OnPoll is called when the poller should poll. Return the timestamp when you want to be polled again.
	// Return 0 to never be polled again.
	OnPoll(client MatrixClient) time.Time
}

Poller represents a thing which can poll. Services should implement this method signature to support polling.

type Service

type Service interface {
	// Return the user ID of this service.
	ServiceUserID() id.UserID
	// Return an opaque ID used to identify this service.
	ServiceID() string
	// Return the type of service. This string MUST NOT change.
	ServiceType() string
	Commands(cli MatrixClient) []Command
	Expansions(cli MatrixClient) []Expansion
	OnReceiveWebhook(w http.ResponseWriter, req *http.Request, cli MatrixClient)
	// A lifecycle function which is invoked when the service is being registered. The old service, if one exists, is provided,
	// along with a Client instance for ServiceUserID(). If this function returns an error, the service will not be registered
	// or persisted to the database, and the user's request will fail. This can be useful if you depend on external factors
	// such as registering webhooks.
	Register(oldService Service, client MatrixClient) error
	// A lifecycle function which is invoked after the service has been successfully registered and persisted to the database.
	// This function is invoked within the critical section for configuring services, guaranteeing that there will not be
	// concurrent modifications to this service whilst this function executes. This lifecycle hook should be used to clean
	// up resources which are no longer needed (e.g. removing old webhooks).
	PostRegister(oldService Service)
}

A Service is the configuration for a bot service.

func CreateService

func CreateService(serviceID, serviceType string, serviceUserID id.UserID, serviceJSON []byte) (Service, error)

CreateService creates a Service of the given type and serviceID. Returns an error if the Service couldn't be created.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL