https://github.com/sawadashota/keybaser
Keybase Bot Framework
https://github.com/sawadashota/keybaser
bot chatbot go keybase
Last synced: 3 months ago
JSON representation
Keybase Bot Framework
- Host: GitHub
- URL: https://github.com/sawadashota/keybaser
- Owner: sawadashota
- License: mit
- Created: 2019-09-12T13:21:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-17T12:12:11.000Z (about 6 years ago)
- Last Synced: 2023-08-10T02:44:45.110Z (over 2 years ago)
- Topics: bot, chatbot, go, keybase
- Language: Go
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Keybaser [](https://github.com/sawadashota/keybaser/actions) [](https://godoc.org/github.com/sawadashota/keybaser) [](https://codecov.io/gh/sawadashota/keybaser) [](https://goreportcard.com/report/github.com/sawadashota/keybaser) [](https://golangci.com/r/github.com/sawadashota/keybaser)
[](https://opensource.org/licenses/MIT)
===
Built on top of the Keybase API [github.com/keybase/go-keybase-chat-bot](https://github.com/keybase/go-keybase-chat-bot) with the idea to simplify the Real-Time Messaging feature to easily create Keybase Bots, likely [github.com/shomali11/slacker](https://github.com/shomali11/slacker)
Features
---
Features are almost same as [github.com/shomali11/slacker](https://github.com/shomali11/slacker)
* Easy definitions of commands and their input
* Available bot initialization, errors and default handlers
* Simple parsing of String, Integer, Float and Boolean parameters
* Contains support for `context.Context`
*Built-in `help` command
* supports authorization
* bot responds to mentions and direct messages
* handlers run concurrently via goroutine
* Full access to the Keybase API [github.com/keybase/go-keybase-chat-bot](https://github.com/keybase/go-keybase-chat-bot)
Dependencies
---
* `commander` [github.com/shomali11/slacker](https://github.com/shomali11/slacker)
* `go-keybase-chat-bot` [github.com/keybase/go-keybase-chat-bot](https://github.com/keybase/go-keybase-chat-bot)
Requirements
---
* [Keybase App](https://keybase.io/download)
Install
---
```
go get github.com/sawadashota/keybaser
```
Examples
---
### Example 1
Defining a simple command
[examples/simple](./examples/simple)
```go
package main
import (
"context"
"log"
"github.com/keybase/go-keybase-chat-bot/kbchat"
"github.com/sawadashota/keybaser"
)
func main() {
client, err := kbchat.Start(kbchat.RunOptions{
Oneshot: &kbchat.OneshotOptions{
Username: "",
PaperKey: "",
},
})
if err != nil {
log.Fatal(err)
}
bot, err := keybaser.New(client)
if err != nil {
log.Fatal(err)
}
definition := &keybaser.CommandDefinition{
Handler: func(request keybaser.Request, response keybaser.ResponseWriter) {
response.Reply("pong")
},
}
bot.Command("ping", definition)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := bot.Listen(ctx); err != nil {
log.Fatal(err)
}
}
```
Example 2
---
Defining a command with parameter, description and example
[examples/parameter](./examples/parameter)
```go
package main
import (
"context"
"log"
"github.com/keybase/go-keybase-chat-bot/kbchat"
"github.com/sawadashota/keybaser"
)
func main() {
client, err := kbchat.Start(kbchat.RunOptions{
Oneshot: &kbchat.OneshotOptions{
Username: "",
PaperKey: "",
},
})
if err != nil {
log.Fatal(err)
}
bot, err := keybaser.New(client)
if err != nil {
log.Fatal(err)
}
definition := &keybaser.CommandDefinition{
Description: "Greet to you",
Example: "greet alice",
Handler: func(request keybaser.Request, response keybaser.ResponseWriter) {
name := request.Param("name")
response.Reply("Hello " + name)
},
}
bot.Command("greet ", definition)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := bot.Listen(ctx); err != nil {
log.Fatal(err)
}
}
```
Example 3
---
Sample of running on Docker.
Keybaser doesn't work Go's binary alone because [github.com/keybase/go-keybase-chat-bot](https://github.com/keybase/go-keybase-chat-bot) requires keybase app.
So this sample is using [keybaseio/client](https://hub.docker.com/r/keybaseio/client) as execution image.
The image's Dockerfile is [here](https://github.com/keybase/client/tree/master/packaging/linux/docker)
[examples/docker](./examples/docker)
```dockerfile
# Build Chat Bot app
FROM golang:1.13-buster as builder
WORKDIR /app
COPY . .
RUN go mod download && \
go mod verify && \
CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 \
go build \
-o app \
main.go
# Copy chat bot app binary to executor image
FROM keybaseio/client:nightly-slim
COPY --from=builder /app/app /usr/bin/app
```