Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 2 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 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-13T16:24:38.000Z (over 1 year ago)
- Last Synced: 2024-04-21T01:05:33.864Z (10 months ago)
- Topics: bot, chat, chatbot, golang, matrix-org
- Language: Go
- Homepage: https://pablo.tools
- Size: 63.5 KB
- Stars: 19
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/pinpox/matrix-bot.svg?branch=master)](https://travis-ci.org/pinpox/matrix-bot)
[![GoDoc](https://godoc.org/github.com/pinpox/matrix-bot?status.svg)](https://godoc.org/github.com/pinpox/matrix-bot)
[![Go Report Card](https://goreportcard.com/badge/github.com/pinpox/gitea-matrix-bot)](https://goreportcard.com/report/github.com/pinpox/matrix-bot)
[![codecov](https://codecov.io/gh/pinpox/matrix-bot/branch/master/graph/badge.svg)](https://codecov.io/gh/pinpox/matrix-bot)
![Matrix](https://img.shields.io/matrix/matrix-bot:matrix.org.svg?label=%23matrix-bot%3Amatrix.org)# matrix-bot
BYOB (Build your own bot) - Build a matrix bot that acts on !commands
![screenshot](scrot.png "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.```go
package mainimport "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)