router

package
v0.0.0-...-6a4b17f Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package router includes the router for handling events from whatsapp web api.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Matcher

func Matcher(r *Route) func(string) bool

Matcher returns the matcher function of the route.

Types

type Context

type Context struct {
	Cli         *whatsmeow.Client
	IsPrivate   bool
	Msg         *events.Message
	GroupInfo   *events.GroupInfo
	JoinedGroup *events.JoinedGroup
	Args        []string
	Str         string
	Routes      []*Route

	Mut sync.Mutex
	// contains filtered or unexported fields
}

Context is the default context for the router.

func (*Context) DeleteBulkMessages

func (c *Context) DeleteBulkMessages(chat types.JID, messages []types.MessageID) error

DeleteBulkMessages deletes the messages.

func (*Context) DeleteMessage

func (c *Context) DeleteMessage(chat types.JID, message types.MessageID) error

DeleteMessage deletes the message.

func (*Context) Get

func (c *Context) Get(key string) any

Get gets a variable from the context.

func (*Context) GetGroupInfo

func (c *Context) GetGroupInfo(jid types.JID) (*types.GroupInfo, error)

GetGroupInfo gets the group info.

func (*Context) JoinGroup

func (c *Context) JoinGroup(link string) error

JoinGroup joins the group by the given link.

func (*Context) LeaveGroup

func (c *Context) LeaveGroup(jid types.JID) error

LeaveGroup leaves the group.

func (*Context) MarkAsRead

func (c *Context) MarkAsRead() error

MarkAsRead marks the current message as read.

func (*Context) Reply

func (c *Context) Reply(message string) error

Reply reply to the message.

func (*Context) SendAdvanceMessage

func (c *Context) SendAdvanceMessage(to types.JID, message *waproto.Message) error

SendAdvanceMessage sends a proto message to specific JID.

func (*Context) SendMessage

func (c *Context) SendMessage(to types.JID, message string) error

SendMessage sends a basic string message to a specific JID.

func (*Context) SendMessageWithMention

func (c *Context) SendMessageWithMention(to types.JID, message string, mention []string) error

SendMessageWithMention sends a message to a specific JID with a mention.

func (*Context) Set

func (c *Context) Set(key string, value any)

Set sets a variable to the context.

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc is the function that will be called when the route is called.

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc is the function that will be called before the route is called.

type Route

type Route struct {
	Name        string // name of the route
	Description string // description of the route
	Handler     HandlerFunc
	Middleware  []MiddlewareFunc
	Matcher     func(string) bool
	Routes      []*Route

	// AutoRead will mark the message from group as read as soon the message received.
	AutoRead bool
}

Route represent the router object of the application.

func (*Route) AddRoute

func (r *Route) AddRoute(route *Route) error

AddRoute adds a route to the route. Will return an error if the route already exists.

func (*Route) Desc

func (r *Route) Desc() string

Desc returns the description of the route.

func (*Route) EventHandler

func (r *Route) EventHandler(cli *whatsrhyno.Client) func(evt interface{})

EventHandler is the function that will be called when the event is emited.

func (*Route) Find

func (r *Route) Find(name string) *Route

Find finds the route by name.

func (*Route) On

func (r *Route) On(name string, hf HandlerFunc) *Route

On Register a new route.

func (*Route) OnMatch

func (r *Route) OnMatch(name string, matcher func(string) bool, hf HandlerFunc) *Route

OnMatch adds a handler to the route.

func (*Route) SetAfterMessageHandler

func (r *Route) SetAfterMessageHandler(handler HandlerFunc)

SetAfterMessageHandler sets the function that will be called after the message is sent.

func (*Route) SetBeforeMessageHandler

func (r *Route) SetBeforeMessageHandler(handler HandlerFunc)

SetBeforeMessageHandler sets the function that will be called before the message is sent.

func (*Route) SetGlobalMessageHandler

func (r *Route) SetGlobalMessageHandler(handler HandlerFunc)

SetGlobalMessageHandler sets the function that will be called when the message is not a command.

func (*Route) SetGroupChangedHandler

func (r *Route) SetGroupChangedHandler(handler func(*Context))

SetGroupChangedHandler sets the function that will be called when the group info is changed.

func (*Route) SetJoinedGroupHandler

func (r *Route) SetJoinedGroupHandler(handler func(*Context))

SetJoinedGroupHandler sets the function that will be called when the current user joined a group.

func (*Route) SetNotFoundHandler

func (r *Route) SetNotFoundHandler(handler HandlerFunc)

SetNotFoundHandler sets the function that will be called when the command is not found.

func (*Route) Use

func (r *Route) Use(mf ...MiddlewareFunc) *Route

Use adds a middleware to the route.

Jump to

Keyboard shortcuts

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