Built on top of the Keybase API 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
Features are almost same as 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-inhelp
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
commander
github.com/shomali11/slackergo-keybase-chat-bot
github.com/keybase/go-keybase-chat-bot
go get github.com/sawadashota/keybaser
Defining a simple command
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: "<Bot's Username>",
PaperKey: "<Bot's 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)
}
}
Defining a command with parameter, description and example
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: "<Bot's Username>",
PaperKey: "<Bot's 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 <name>", definition)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := bot.Listen(ctx); err != nil {
log.Fatal(err)
}
}
Sample of running on Docker.
Keybaser doesn't work Go's binary alone because github.com/keybase/go-keybase-chat-bot requires keybase app. So this sample is using keybaseio/client as execution image. The image's Dockerfile is here
# 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