Documentation
¶
Overview ¶
Package router includes the router for handling events from whatsapp web api.
Index ¶
- func Matcher(r *Route) func(string) bool
- type Context
- func (c *Context) DeleteBulkMessages(chat types.JID, messages []types.MessageID) error
- func (c *Context) DeleteMessage(chat types.JID, message types.MessageID) error
- func (c *Context) Get(key string) any
- func (c *Context) GetGroupInfo(jid types.JID) (*types.GroupInfo, error)
- func (c *Context) JoinGroup(link string) error
- func (c *Context) LeaveGroup(jid types.JID) error
- func (c *Context) MarkAsRead() error
- func (c *Context) Reply(message string) error
- func (c *Context) SendAdvanceMessage(to types.JID, message *waproto.Message) error
- func (c *Context) SendMessage(to types.JID, message string) error
- func (c *Context) SendMessageWithMention(to types.JID, message string, mention []string) error
- func (c *Context) Set(key string, value any)
- type HandlerFunc
- type MiddlewareFunc
- type Route
- func (r *Route) AddRoute(route *Route) error
- func (r *Route) Desc() string
- func (r *Route) EventHandler(cli *whatsrhyno.Client) func(evt interface{})
- func (r *Route) Find(name string) *Route
- func (r *Route) On(name string, hf HandlerFunc) *Route
- func (r *Route) OnMatch(name string, matcher func(string) bool, hf HandlerFunc) *Route
- func (r *Route) SetAfterMessageHandler(handler HandlerFunc)
- func (r *Route) SetBeforeMessageHandler(handler HandlerFunc)
- func (r *Route) SetGlobalMessageHandler(handler HandlerFunc)
- func (r *Route) SetGroupChangedHandler(handler func(*Context))
- func (r *Route) SetJoinedGroupHandler(handler func(*Context))
- func (r *Route) SetNotFoundHandler(handler HandlerFunc)
- func (r *Route) Use(mf ...MiddlewareFunc) *Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
DeleteBulkMessages deletes the messages.
func (*Context) DeleteMessage ¶
DeleteMessage deletes the message.
func (*Context) GetGroupInfo ¶
GetGroupInfo gets the group info.
func (*Context) JoinGroup ¶
JoinGroup joins the group by the given link.
func (*Context) LeaveGroup ¶
LeaveGroup leaves the group.
func (*Context) MarkAsRead ¶
MarkAsRead marks the current message as read.
func (*Context) SendAdvanceMessage ¶
SendAdvanceMessage sends a proto message to specific JID.
func (*Context) SendMessage ¶
SendMessage sends a basic string message to a specific JID.
func (*Context) SendMessageWithMention ¶
SendMessageWithMention sends a message to a specific JID with a mention.
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 ¶
AddRoute adds a route to the route. Will return an error if the route already exists.
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) OnMatch ¶
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 ¶
SetGroupChangedHandler sets the function that will be called when the group info is changed.
func (*Route) SetJoinedGroupHandler ¶
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.