Server for integration of Workplace with Webhooks
This receives payloads from mapped webhook and convert it in a message to the givened workplace group.
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>"For build you can use:
$ make buildit will generate two binaries:
wiwthe server used for startwSendToGroupused to send message to a given group by clim
You can use:
$ sudo make installit 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/gobinOr if you prefer you can get by go:
$ go get github.com/bornlogic/wiw/cmd/...After export the env you need to start the server in ./cmd/server/main.go
Examples:
run on default port (:3000)
$ wiwrun on port 8080
$ wiw -p :8080run by makefile
$ make serve args="-p :8080"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 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
You have an url like localhost:3000/github/{groupID} waiting for webhooks comming from github
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 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 operationsExamples:
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"Some useful explains about development
run all unitary tests
make testrun specific with args
make test args="server/handlers/github/github_test.go -run=TestGithubServe/invalid_status_from -v"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"