Java library which provides developers notification via messengers
Introduction
Sometimes every developer needs to know about the event that happened as soon as possible. For example, about irregular work of the server or about changing the third-party rest-api, about anything, depending on the specifics of the project.
There are many ways to inform developers about such events - all sorts of services, loggers. But most of them send notifications to the mail or a issue tracking system of a different type, which is not always convenient and not always possible to track quickly.
This library sending notifications to messengers. Just create and connect a bot in the messenger that your team using and that is supported by this library. For now it is Slack and Telegram. Add the library to the project, add it configuration (access keys to the bot that you created), add lines, where it is needed, to send message and you receive messages when something happened.
This library compatible with Java 6+
Getting started
Download
Gradle:
compile 'com.github.fedorchuck:developers-notification:0.1.2'
Maven:
<dependency>
<groupId>com.github.fedorchuck</groupId>
<artifactId>developers-notification</artifactId>
<version>0.1.2</version>
</dependency>
Setup
The library is configured by environment variables or system properties. Supported variables:
DN_MESSENGER
where the message will be sent; possible values you can see in DevelopersNotificationMessenger required if you use methodsend
with signatureDevelopersNotification.send(String, String, Throwable)
;DN_SLACK_TOKEN
access key; required if you use Slack messages;DN_SLACK_CHANNEL
destination chat; required if you use Slack messages;DN_TELEGRAM_TOKEN
access key; required if you use Telegram messages;DN_TELEGRAM_CHANNEL
destination chat; required if you use Telegram messages;DN_USER_AGENT
user agent for HttpClient is not required; default value isMozilla/5.0
;DN_CONNECT_TIMEOUT
for HttpClient is not required; default value is5000
;DN_SHOW_WHOLE_LOG_DETAILS
receive boolean value; if value is true - at log will be printed Information containing passwords; default value isfalse
.
Required configuration which will be using for sending messages.
Connecting your bot
Slack
- Login in into Slack
- Add incoming-webhook
- Choose a channel and add press green button :-)
- Choose the channel again add press green button, again :-)
- Find the
Integration Settings
section - Find the
Webhook URL
sub-section and copy token. Example url:https://hooks.slack.com/services/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
, token:TZXG2L132/B56Z6RGR1/AdlsZzn1QGfo2qrEK4jpO4wJ
- Add configuration to your project. For this example it is:
DN_SLACK_TOKEN
=TZXG2L132/B56Z6RGR1/AdlsZzn1QGfo2qrEK4jpO4wJ
DN_SLACK_CHANNEL
=general
Telegram
- Create your bot
- Add the Telegram BOT to your chat.
- Get the list of updates for your BOT:
GET https://api.telegram.org/bot<YourBOTToken>/getUpdates
example:
GET https://api.telegram.org/bot32031087:pabzcu_j17-jbd78sadvbdy63d37gda37-d8/getUpdates
- Find object chat. It looks like this:
"chat": {
"id": -197235129,
"title": "test group developers notification",
"type": "group",
"all_members_are_administrators": true
},
- Add configuration to your project:
DN_TELEGRAM_TOKEN
=YourBOTToken
DN_TELEGRAM_CHANNEL
=chat.id
For this example it is:DN_TELEGRAM_TOKEN
=32031087:pabzcu_j17-jbd78sadvbdy63d37gda37-d8
DN_TELEGRAM_CHANNEL
=-197235129
Usage
You can set needed environment variables using:
DevelopersNotificationUtil.setEnvironmentVariable(key, value);
For checking set environment variables which needed this library use:
DevelopersNotification.printConfiguration();
For sending message to chosen destination you can use methods:
DevelopersNotification.send(DevelopersNotificationMessenger.ALL_AVAILABLE,
"your project name", "short description", new IllegalStateException("abcd"));
DevelopersNotification.send(
"your project name", "short description", new IllegalStateException("abcd"));
Changelog
See changelog file
Dependencies
License
This software is licensed under Apache License 2.0