Skip to content

baloise-incubator/ms-teams-connector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI Quality Gate Status https://lift.sonatype.com/

ms-teams-connector

Utilize a MessageCard and publish it to a MS-Teams channel via webhook.

Special thanks goes to Roland Seidel for the idea and his reference implementation.

Usage

Add dependency to your project

<dependency>
  <groupId>com.baloise.open</groupId>
  <artifactId>ms-teams-connector</artifactId>
  <version>0.2.2</version>
</dependency>

Create publisher per channel

final String uri = "https://teams.proxy.url/webhook/TEAM_ID/IncomingWebhook/CHANNEL_ID/WEBHOOK_ID";
final MessagePublisher channelPublisher = MessagePublisher.getInstance(uri);

Now you can publish any message using MessagePublisher (e.g., create and publish a simple message)

final MessageCard msg = MessageCardFactory.createSimpleMessageCard("MyTitle", "MyMessage: Hello MFA-Team");
ScheduledFuture<?> publishedFuture = channelPublisher.publish(msg);

Example

Using MessageCardFactory builder

MessageCardFactory builder extends the "SimpleMessageCard" by adding colored horizontal ruler and facts.

  • Colors are either added by one of the predefined enums ( RED, GREEN, YELLOW, BLUE) or by adding any valid color hex code.

  • Facts are key-value pairs added as table below the text.

MessageCardFactory.builder("A crisp title", "A little more descriptive text.")
    .withColor(MessageCardFactory.Color.RED)
    .withFact("Status", "Failure")
    .withFact("Reason", "Out of memory")
    .build();

Configuration

Parameter Default Description
PROPERTY_RETRIES 3 Defines the number of retries to publish the message in case of unsuccessful answer from webhook. Accepts any positive integer > 0.
PROPERTY_RETRY_PAUSE 60 Defines the pause time between PROPERTY_RETRIES in seconds. Accepts any positive integer > 0.
PROPERTY_WEBHOOK_URI none The URI to your webhook. Required property provided either as String or URI.