LiubovFedorchuk / developers-notification

Java library which provides developers notification via messengers

Home Page:https://fedorchuck.github.io/developers-notification/javadoc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java library which provides developers notification via messengers

Build Status Apache License Version 2.0 Maven Central

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>

JAR-files:
https://oss.sonatype.org/content/repositories/releases/com/github/fedorchuck/developers-notification/

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 method send with signature DevelopersNotification.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 is Mozilla/5.0;
  • DN_CONNECT_TIMEOUT for HttpClient is not required; default value is 5000;
  • DN_SHOW_WHOLE_LOG_DETAILS receive boolean value; if value is true - at log will be printed Information containing passwords; default value is false.

Required configuration which will be using for sending messages.

Connecting your bot

Slack

  1. Login in into Slack
  2. Add incoming-webhook
  3. Choose a channel and add press green button :-)
  4. Choose the channel again add press green button, again :-)
  5. Find the Integration Settings section
  6. Find the Webhook URL sub-section and copy token. Example url: https://hooks.slack.com/services/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, token: TZXG2L132/B56Z6RGR1/AdlsZzn1QGfo2qrEK4jpO4wJ
  7. Add configuration to your project. For this example it is:
  • DN_SLACK_TOKEN = TZXG2L132/B56Z6RGR1/AdlsZzn1QGfo2qrEK4jpO4wJ
  • DN_SLACK_CHANNEL = general

Telegram

  1. Create your bot
  2. Add the Telegram BOT to your chat.
  3. 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
  1. Find object chat. It looks like this:
        "chat": {
          "id": -197235129,
          "title": "test group developers notification",
          "type": "group",
          "all_members_are_administrators": true
        },
  1. 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

About

Java library which provides developers notification via messengers

https://fedorchuck.github.io/developers-notification/javadoc/

License:Apache License 2.0


Languages

Language:Java 100.0%