webhook-proxy-go

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2017 License: MIT Imports: 17 Imported by: 0

README

WebhookProxy - A webhook proxy

Build Status Go Report Card Code Climate Docs License

WebhookProxy is a proxy service to map different webhook posts to message platforms such as Glip's inbound webhook service. It formats messages using CommonChat intermediate message format which can then be translated into different chat platform message formats. This is useful because many services with outbound webhooks need to be formatted before they can be consumed by a webhook consuming app such as a chat service. This proxy service does the conversion so you don't have to. Applications already integrated with Slack's inbound webhooks can create messages on Glip simply by using the proxy URL.

Conversion of the following webhook message formats to Glip inbound webhooks include:

Outbound Webhook Formats supported:

  1. AppSignal
  2. Apteligent/Crittercism
  3. Circle CI
  4. Codeship
  5. Confluence
  6. Datadog
  7. Desk.com
  8. Enchant
  9. GoSquared
  10. Heroku
  11. Librato
  12. Magnum CI
  13. Marketo
  14. OpsGenie
  15. Papertrail
  16. Pingdom
  17. Raygun
  18. Runscope
  19. Semaphore CI, Deploy
  20. StatusPage
  21. Travis CI
  22. Userlike
  23. VictorOps

Inbound Webhook Format supported:

  • Slack (inbound message format) - text only

Note: Slack inbound message formatting is for services sending outbound webhooks using Slack's inbound webhook message format, which can be directed to Glip via this proxy.

Example Webhook Message from Travis CI:

Installation

$ go get github.com/grokify/glip-webhook-proxy

Usage

Starting the Service

Start the service with the following.

package main

import (
	log "github.com/Sirupsen/logrus"
	"github.com/grokify/webhookproxy"
)

func main() {
	config := webhookproxy.Configuration{
		Port:           8080,
		EmojiURLFormat: "https://grokify.github.io/emoji/assets/images/%s.png",
		LogLevel:       log.DebugLevel}

	glipwebhookproxy.StartServer(config)
}

You can run the above by saving it to a file start.go and then running $ go run start.go.

Note: The emoji to URL is designed to take a icon_emoji value and convert it to a URL. EmojiURLFormat is a fmt format string with one %s verb to represent the emoji string without :. You can use any emoji image service. The example shows the emoji set from github.com/wpeterson/emoji forked and hosted at grokify.github.io/emoji/.

Creating the Glip Webhook
  1. create a Glip webhook
  2. use webhook URL's GUID to create the proxy URL as shown below
  3. use the proxy URL in your outbound webhook service
Service URL
Glip https://hooks.glip.com/webhook/11112222-3333-4444-5555-666677778888
Slack Inbound https://example.com/webhook/slack/in/glip/11112222-3333-4444-5555-666677778888
Travis CI Outbound https://example.com/webhook/travisci/out/glip/11112222-3333-4444-5555-666677778888

The webhook proxy URLs support both inbound and outbound formats. For example:

  • when using Travis CI's webhook format use travisci/out/glip to indicate converting a Travis CI outbound webhook format message to Glip.
  • when using a service that supports Slack inbound webhook format use slack/in/glip to indicate converting a Slack inbound webhook format message to Glip.

To create the Glip webhook and receive a webhook URL do the following:

Add the Webhook Integration

At the top of any conversation page, click the Settings gear icon and then click Add Integration.

Select the Glip Webhooks integration.

Get the Webhook URL

Once you get the URL, the proxy URL is created by appending the GUID (e.g. 1112222-3333-4444-5555-666677778888) to the proxy URL base, /webhook/slack/glip (e.g. https://glip-proxy.example.com/webhook/slack/glip/1112222-3333-4444-5555-666677778888). Use the proxy URL in the app that is posting the Slack webhook and the payload will be sent to Glip.

Example Requests

Most of the time you will likely either:

  • use the proxy URL in an outbound webhook service that supports the Slack format or
  • use a client library

The following examples are provided for reference and testing.

Using application/json
$ curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"username":"ghost-bot", "icon_emoji": ":ghost:", "text":"BOO!"}' \
  "http://localhost:8080/webhook/slack/glip/11112222-3333-4444-5555-666677778888"
Using application/x-www-form-urlencoded
$ curl -X POST \
  --data-urlencode 'payload={"username":"ghost-bot", "icon_emoji": ":ghost:", text":"BOO!"}' \
  "http://localhost:8080/webhook/slack/glip/11112222-3333-4444-5555-666677778888"
Using multipart/form-data
$ curl -X POST \
  -F 'payload={"username":"ghost-bot", "icon_emoji": ":ghost:", text":"BOO!"}' \
  "http://localhost:8080/webhook/slack/glip/11112222-3333-4444-5555-666677778888"
Using Community Ruby SDK

This has been tested using:

require 'slack/poster'

url = 'http://localhost:8080/webhook/slack/glip/11112222-3333-4444-5555-666677778888'

opts = {
	username: 'Ghost Bot [Bot]',
	icon_emoji: ':ghost:'
}

poster = Slack::Poster.new url, opts
poster.send_message 'BOO!'

Notes

WebhookProxy is built using:

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL