https://github.com/pinpox/matrix-bot
:beer: :fax: *BYOB* (Build your own bot) - Build a matrix bot that acts on !commands
https://github.com/pinpox/matrix-bot
bot chat chatbot golang matrix-org
Last synced: 11 months ago
JSON representation
:beer: :fax: *BYOB* (Build your own bot) - Build a matrix bot that acts on !commands
- Host: GitHub
- URL: https://github.com/pinpox/matrix-bot
- Owner: pinpox
- Created: 2019-04-14T20:43:53.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-13T16:24:38.000Z (over 2 years ago)
- Last Synced: 2025-04-30T14:25:27.165Z (11 months ago)
- Topics: bot, chat, chatbot, golang, matrix-org
- Language: Go
- Homepage: https://pablo.tools
- Size: 63.5 KB
- Stars: 23
- Watchers: 2
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/pinpox/matrix-bot)
[](https://godoc.org/github.com/pinpox/matrix-bot)
[](https://goreportcard.com/report/github.com/pinpox/matrix-bot)
[](https://codecov.io/gh/pinpox/matrix-bot)

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

## 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.
```go
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](https://github.com/pinpox/gitea-matrix-bot)