Skip to content

Repository files navigation

N1netails

N1ne Tails

License: MIT

Stars Issues Contributors Last Commit

Teams Webhook Client

N1netails is an open-source project that provides practical alerts and monitoring for applications. Use the N1netails Teams Webhook Client to easily send webhook messages to a teams channel.

How to set up a team and channels

In order to use this webhook client you will need to have a Microsoft 365 Business account.

Create teams webhook

  1. In Microsoft Teams, choose a channel and from the options menu (...) select Workflows.
  2. Search for Send webhook alerts to a channel and select it.
  3. Provide a name for your new webhook select Next.
  4. In the details section select the Microsoft Teams Team and the Microsoft Teams Channel you want the webhook to be linked to select Add Workflow.
  5. The dialog will present a unique URL that maps to the channel. Copy this webhook URL.
  6. Your webhook is now ready to receive messages.

Editing a Webhook in Power Automate

You can confirm your workflow is set up correctly by going to the channel where the workflow is installed.

  1. Click on More Options it will be three dots '...' next to the channel when you hover over it.
  2. Select Workflows.
  3. Click Manage in the bottom-left corner.
  4. Hover over your target webhook and select More commands → Edit.

If configured correctly, it should look like the image below:

N1ne Tails

Install

Install the teams webhook client by adding the following dependency:

<dependency>
    <groupId>com.n1netails</groupId>
    <artifactId>n1netails-teams-webhook-client</artifactId>
    <version>0.3.0</version>
</dependency>

Gradle (Groovy)

implementation 'com.n1netails:n1netails-teams-webhook-client:0.3.0'

Usage

To send a message to your Teams channel, use the TeamsWebhookClient.

Simple Message

import com.n1netails.n1netails.teams.api.TeamsWebhookClient;
import com.n1netails.n1netails.teams.internal.TeamsWebhookClientImpl;
import com.n1netails.n1netails.teams.model.WebhookMessage;
import com.n1netails.n1netails.teams.service.WebhookService;

public class Example {
    public static void main(String[] args) {
        try {
            WebhookService webhookService = new WebhookService();
            TeamsWebhookClient client = new TeamsWebhookClientImpl(webhookService);

            WebhookMessage message = new WebhookMessage();
            message.setContent("Hello, from n1netails-teams-webhook-client!");

            client.sendMessage("YOUR_WEBHOOK_URL", message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Example simple message output

N1netails teams webhook message simple

Message Card

The message card is a more flexible and customizable way to send messages.

import com.n1netails.n1netails.teams.api.TeamsWebhookClient;
import com.n1netails.n1netails.teams.internal.TeamsWebhookClientImpl;
import com.n1netails.n1netails.teams.model.*;
import com.n1netails.n1netails.teams.service.WebhookService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Example {
    public static void main(String[] args) {
        try {
            WebhookService webhookService = new WebhookService();
            TeamsWebhookClient client = new TeamsWebhookClientImpl(webhookService);

            MessageCard messageCard = new MessageCard();
            messageCard.setTitle("Message Card Title");
            messageCard.setSummary("Message Card Summary");

            List<Section> sections = new ArrayList<>();
            Section section = new Section();
            section.setTitle("Section Title");

            List<Fact> facts = new ArrayList<>();
            facts.add(new Fact("Fact 1", "Fact 1 Value"));
            facts.add(new Fact("Fact 2", "Fact 2 Value"));
            section.setFacts(facts);
            section.setImageUrl("https://raw.githubusercontent.com/n1netails/n1netails/refs/heads/main/n1netails_icon_transparent.png");
            sections.add(section);

            messageCard.setSections(sections);

            List<Action> actions = new ArrayList<>();
            actions.add(new Action("View Website", "https://github.com/n1netails/n1netails-teams-webhook-client"));
            messageCard.setActions(actions);

            client.sendMessage("YOUR_WEBHOOK_URL", messageCard);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Example message block output

N1netails teams webhook message block

Image Message

import com.n1netails.n1netails.teams.api.TeamsWebhookClient;
import com.n1netails.n1netails.teams.internal.TeamsWebhookClientImpl;
import com.n1netails.n1netails.teams.model.WebhookMessage;
import com.n1netails.n1netails.teams.service.WebhookService;

public class Example {
    public static void main(String[] args) {
        try {
            WebhookService webhookService = new WebhookService();
            TeamsWebhookClient client = new TeamsWebhookClientImpl(webhookService);

            WebhookMessage message = new WebhookMessage();
            message.setContent("Hello, from n1netails-teams-webhook-client!");
            message.setImageUrl("https://raw.githubusercontent.com/n1netails/n1netails/refs/heads/main/n1netails_icon_transparent.png");

            List<Action> actions = new ArrayList<>();
            actions.add(new Action("Visit Website", "https://github.com/n1netails/n1netails-teams-webhook-client"));
            message.setActions(actions);

            client.sendMessage("YOUR_WEBHOOK_URL", message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Example image message output

N1netails teams webhook message image

GIF Message

import com.n1netails.n1netails.teams.api.TeamsWebhookClient;
import com.n1netails.n1netails.teams.internal.TeamsWebhookClientImpl;
import com.n1netails.n1netails.teams.model.WebhookMessage;
import com.n1netails.n1netails.teams.service.WebhookService;

public class Example {
    public static void main(String[] args) {
        try {
            WebhookService webhookService = new WebhookService();
            TeamsWebhookClient client = new TeamsWebhookClientImpl(webhookService);

            WebhookMessage message = new WebhookMessage();
            message.setContent("Hello, from n1netails-teams-webhook-client!");
            // Gifs are also supported
            message.setImageUrl("https://media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExYmEwajlsZjBqb2d2Zmk1bmJoYTEyN2Q0czRmOWtmYjd4YWVzMHoxaCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/xsE65jaPsUKUo/giphy.gif");

            List<Action> actions = new ArrayList<>();
            actions.add(new Action("Visit Website", "https://github.com/n1netails/n1netails-teams-webhook-client"));
            message.setActions(actions);

            client.sendMessage("YOUR_WEBHOOK_URL", message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Example gif message output

N1netails teams webhook message gif

Develop

Build

Build the project using the following command

mvn clean install

Maven Central Repository

Use the following doc to get setup with publishing to the maven central repository https://central.sonatype.org/register/central-portal/#publishing

Maven install using release profile.

mvn clean install -P release

Maven deploy to the maven central repository

mvn deploy -P release

Support

For community users, open an issue on GitHub or Join our Discord

Join our Discord

Contributing

Please use the following guidelines for contributions CONTRIBUTING

About

A lightweight Java client for sending Teams webhooks.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages