Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.n1netails</groupId>
<artifactId>n1netails-teams-webhook-client</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
<packaging>jar</packaging>

<name>n1netails-teams-webhook-client</name>
Expand Down Expand Up @@ -55,6 +55,20 @@
<artifactId>gson</artifactId>
<version>2.13.2</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
85 changes: 80 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ Install the teams webhook client by adding the following dependency:
<dependency>
<groupId>com.n1netails</groupId>
<artifactId>n1netails-teams-webhook-client</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
```

Gradle (Groovy)
```groovy
implementation 'com.n1netails:n1netails-teams-webhook-client:0.2.0'
implementation 'com.n1netails:n1netails-teams-webhook-client:0.3.0'
```

## Usage
Expand Down Expand Up @@ -94,12 +94,11 @@ The message card is a more flexible and customizable way to send messages.
```java
import com.n1netails.n1netails.teams.api.TeamsWebhookClient;
import com.n1netails.n1netails.teams.internal.TeamsWebhookClientImpl;
import com.n1netails.n1netails.teams.model.Fact;
import com.n1netails.n1netails.teams.model.MessageCard;
import com.n1netails.n1netails.teams.model.Section;
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 {
Expand All @@ -120,10 +119,15 @@ public class Example {
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();
Expand All @@ -137,6 +141,77 @@ public class Example {
<img src="teams-message-block.png" alt="N1netails teams webhook message block" width="500" style="display: block; margin: auto;"/>
</div>

### Image Message

```java
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
<div align="center">
<img src="teams-message-image.png" alt="N1netails teams webhook message image" width="500" style="display: block; margin: auto;"/>
</div>

### GIF Message

```java
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
<div align="center">
<img src="teams-message-gif.png" alt="N1netails teams webhook message gif" width="500" style="display: block; margin: auto;"/>
</div>


# Develop
## Build
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/n1netails/n1netails/teams/model/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.n1netails.n1netails.teams.model;

import lombok.Getter;
import lombok.Setter;

/**
* Action for MessageCard
*/
@Getter
@Setter
public class Action {
private String name;
private String target;

/**
* Action Constructor
*/
public Action() {}

/**
* Action Constructor with parameters
* @param name Name of the action
* @param target Target URL of the action
*/
public Action(String name, String target) {
this.name = name;
this.target = target;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MessageCard {
private String title;
private String summary;
private List<Section> sections;
private List<Action> actions;

/**
* Message Card Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Section {

private String title;
private List<Fact> facts;
private String imageUrl;

/**
* Section Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
* Teams Webhook Message
* @author shahid foy
Expand All @@ -12,6 +14,8 @@
public class WebhookMessage {

private String content;
private String imageUrl;
private List<Action> actions;

/**
* Webhook Message Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static class Content {
private String type;
private String version;
private List<BodyItem> body;
private List<ActionItem> actions;

/**
* Content Constructor
Expand Down Expand Up @@ -80,10 +81,43 @@ public static class BodyItem {
private String size;
private boolean wrap;
private boolean separator;
private String url;
private List<MediaSource> sources;

/**
* Body Item Constructor
*/
public BodyItem() {}
}

/**
* Media Source
*/
@Setter
@Getter
public static class MediaSource {
private String mimeType;
private String url;

/**
* Media Source Constructor
*/
public MediaSource() {}
}

/**
* Action Item
*/
@Setter
@Getter
public static class ActionItem {
private String type;
private String title;
private String url;

/**
* Action Item Constructor
*/
public ActionItem() {}
}
}
Loading
Loading