github.com/hatajoe/hooks

hooks is a simple event dispatch handler package for making a bot


Keywords
bot-framework, dispatcher, eventhandler, go, http-server, webhooks
License
MIT
Install
go get github.com/hatajoe/hooks

Documentation

hooks

Go Doc

hooks is a simple HTTP event dispatch handler.

GitHub webhook server

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/hatajoe/hooks"
	"github.com/hatajoe/hooks/github"
)

func main() {
	dispatcher := hooks.NewDispatcher(&github.EventParser{})

	verifier := github.NewVerifyMiddleware("GitHub webhook secret token")

	dispatcher.On("push", verifier.Verify(func(w http.ResponseWriter, r *http.Request) {
		fmt.Println("push event detected")
	}))

	if err := dispatcher.Listen("/webhooks", ":3000"); err != nil {
		log.Fatal(err)
	}
}

Slack event API server

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/hatajoe/hooks"
	"github.com/hatajoe/hooks/slack"
)

func main() {
	dispatcher := hooks.NewDispatcher(&slack.EventParser{
		ChallengeEventType: "challenge",
		VerifyToken:        true,
		VerificationToken:  "Slack event API secret token",
	})

	dispatcher.On("challenge", slack.ChallengeHandler)
	dispatcher.On("app_mention", func(w http.ResponseWriter, r *http.Request) {
		fmt.Println("app_mention event detected")
	})

	if err := dispatcher.Listen("/webhooks", ":3000"); err != nil {
		log.Fatal(err)
	}
}

Bot using hooks example

https://github.com/hatajoe/minibot