Skip to content

bornlogic/bornlogic-workplace-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WIW - Workplace Integration Webhooks

Server for integration of Workplace with Webhooks

This receives payloads from mapped webhook and convert it in a message to the givened workplace group.

Setup

Export WORKPLACE_ACCESS_TOKEN with your api token givened by workplace

This access token will be used for send message in group, without this, you can't connect with workplace. if you need help to generate a token check the guide to generate a new token.

$ export WORKPLACE_ACCESS_TOKEN="<accessToken>"

Build

For build you can use:

$ make build

it will generate two binaries:

  • wiw the server used for start
  • wSendToGroup used to send message to a given group by clim

Install

You can use:

$ sudo make install

it will build and copy the binaries generated for /usr/local/bin folder

For custom path specify prefix or binpath vars

For generate the files inside a bin folder in this path you can set prefix:

$ make install prefix=.

For install in your custom bin folder like gobin in your $HOME you can set binpath:

$ make install binpath=$HOME/gobin

Or if you prefer you can get by go:

$ go get github.com/bornlogic/wiw/cmd/...

Run

After export the env you need to start the server in ./cmd/server/main.go

Examples:

run on default port (:3000)

$ wiw

run on port 8080

$ wiw -p :8080

run by makefile

$ make serve args="-p :8080"

Find GroupID

Inside a group you can check in url of workspace the groupID [see].

Example:
for group url: https://enterprise.workplace.com/chat/t/123456789026103
the groupID is: 123456789026103

Server Configuration

Server contains the webhooks mapped internally, from now, it contains:

  • Github, mapped events: issues, push on master, pull_request [see].

For any webhook, you have a path for use it {ip}:{port}/{service}/{groupID}, eg: localhost:3000/github/1203140219421

Github

You have an url like localhost:3000/github/{groupID} waiting for webhooks comming from github

Configuration

if you are running localhost, you can use ngrok for expose the service

Inside your repository in configuration you have the option Webhooks (verify if is available) Example: https://github.com/bornlogic/wiw/settings/hooks

You will click Add webhook and put the url with service and groupID configured for receive the messages. Example: https://eaa141a6.ngrok.io/github/{groupID}

make sure to enable events issues, pull_request and push.

Now you have github sending webhooks for your server, and can read the messages in your workplace group.

Open an issue to test this.

Cli tool

Group Send

cli used for send message to a given group

For more help try wSendToGroup -h:

$ wSendToGroup -h
Usage of wSendToGroup:
  -access-token WORKPLACE_ACCESS_TOKEN
        access token used to connect with workplace api, if empty it will use the env WORKPLACE_ACCESS_TOKEN
  -f string
        formatting of message, eg: PLAINTEXT, MARKDOWN(shorthand) (default "PLAINTEXT")
  -formatting string
        formatting of message, eg: PLAINTEXT, MARKDOWN (default "PLAINTEXT")
  -g string
        group id of group for send the message(shorthand)
  -group-id string
        group id of group for send the message
  -m string
        message to send in given group(shorthand)
  -message string
        message to send in given group
  -t WORKPLACE_ACCESS_TOKEN
        access token used to connect with workplace api, if empty it will use the env WORKPLACE_ACCESS_TOKEN(shorthand)
  -v    prints feedback of operations(shorthand)
  -verbose
        prints feedback of operations

Examples:

verbose mode

$ wSendToGroup --verbose \
	--access-token <accessToken> \
	--group-id <groupId> \
	--formatting MARKDOWN \
	--message "HELLO WORLD"

if WORKPLACE_ACCESS_TOKEN was setted you don't need pass the flag --access-token

$ export WORKPLACE_ACCESS_TOKEN=<accessToken>
$ wSendToGroup -g <groupId> -f MARKDOWN -m "HELLO WORLD"

Development

Some useful explains about development

Requirements

  • go (for run without docker, outside the makefile)
  • docker (for run without go, inside the makefile)

Test

run all unitary tests

make test

run specific with args

make test args="server/handlers/github/github_test.go -run=TestGithubServe/invalid_status_from -v"

Integration Tests

Integration tests are disabled by default

For integration test you need to set WORKPLACE_GROUP_ID_TEST and WORKPLACE_ACCESS_TOKEN env for test if message is sended

you need specify the build tag integration for run integration tests

Example:

run all with integration tests included

make test args="./... -tags=integration"

run all with integration tests of cmd

make test args="./cmd/... -tags=integration"

run specific integration test

make test args="./cmd/wSendToGroup/main_test.go -run TestSendToGroup"