Skip to content

🍺 📠 *BYOB* (Build your own bot) - Build a matrix bot that acts on !commands

Notifications You must be signed in to change notification settings

pinpox/matrix-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status GoDoc Go Report Card codecov Matrix

matrix-bot

BYOB (Build your own bot) - Build a matrix bot that acts on !commands screenshot

Usage

Here is a minimal example on how to build a custom bot that replies to a message "!ping" with "pong". After starting it, you can invite it to any matrix room and it will join.

package main

import 	"github.com/pinpox/matrix-bot"

// PingPongBot is a custom bot that will reply to !ping with "pong"
type PingPongBot struct {
	*matrixbot.MatrixBot
}

func main() {

	pass := "supersecretpass"
	user := "myawesomebot"

	bot, err := matrixbot.NewMatrixBot(user, pass)

	if err != nil {
		panic(err)
	}

	mypingPongBot := PingPongBot{bot}
  
        // Register a command like this
	bot.RegisterCommand("!ping", 0, mypingPongBot.handlePing)

	for {
		//Loop forever. If you don't have anything that keeps running, the bot will exit.
	}
}

// Handles the !ping message
func (mybot *PingPongBot) handlePing(message, room, sender string) {
	mybot.SendToRoom(room, "pong!")
}

For a more complete example you can look at the Gitea Matrix Bot

About

🍺 📠 *BYOB* (Build your own bot) - Build a matrix bot that acts on !commands

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages