티스토리 뷰
그냥 String 으로 @이름 박으면 알아서 해주는줄 알았더니 형식이 다름.
POST 로 webhook URL로 아래 형식으로 보내야됨
url 참조
Text formatting in cards - Teams | Microsoft Learn
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Sample Adaptive Card with User Mention"
},
{
"type": "TextBlock",
"text": "Hi <at>Adele UPN</at>, <at>Adele Microsoft Entra ID</at>"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"msteams": {
"entities": [
{
"type": "mention",
"text": "<at>Adele UPN</at>",
"mentioned": {
"id": "AdeleV@contoso.onmicrosoft.com",
"name": "Adele Vance"
}
},
{
"type": "mention",
"text": "<at>Adele Microsoft Entra ID</at>",
"mentioned": {
"id": "87d349ed-44d7-43e1-9a83-5f2406dee5bd",
"name": "Adele Vance"
}
}
]
}
}
}]
}
Spring boot 환경에서 배치로 서버 Health Check알람 보내는 상황
DTO
package com.humuson.amc.common.model.teams;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import java.util.List;
@Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Builder
public class WeHookMentionMessage {
@JsonProperty("type")
private String type;
@JsonProperty("attachments")
private List<Attachment> attachments;
@Getter
@AllArgsConstructor
@Builder
@ToString
public static class Attachment {
@JsonProperty("contentType")
private String contentType;
@JsonProperty("content")
private Content content;
}
@Getter
@AllArgsConstructor
@Builder
@ToString
public static class Content {
@JsonProperty("type")
private String type;
@JsonProperty("body")
private List<Body> body;
@JsonProperty("$schema")
private String schema;
@JsonProperty("version")
private String version;
@JsonProperty("msteams")
private Msteams msteams;
}
@Getter
@AllArgsConstructor
@Builder
@ToString
public static class Body {
@JsonProperty("type")
private String type;
@JsonProperty("text")
private String text;
@JsonProperty("size")
private String size;
@JsonProperty("weight")
private String weight;
}
@Getter
@AllArgsConstructor
@Builder
@ToString
public static class Msteams {
@JsonProperty("entities")
private List<Entity> entities;
}
@Getter
@AllArgsConstructor
@Builder
@ToString
public static class Entity {
@JsonProperty("type")
private String type;
@JsonProperty("text")
private String text;
@JsonProperty("mentioned")
private Mentioned mentioned;
}
@Getter
@AllArgsConstructor
@Builder
@ToString
public static class Mentioned {
@JsonProperty("id")
private String id;
@JsonProperty("name")
private String name;
}
}
Batch Step임
private void sendWebhookError(String responseBody) {
List<WeHookMentionMessage.Attachment> attachments = Arrays.asList(
WeHookMentionMessage.Attachment.builder()
.contentType("application/vnd.microsoft.card.adaptive")
.content(WeHookMentionMessage.Content.builder()
.type("AdaptiveCard")
.body(Arrays.asList(
WeHookMentionMessage.Body.builder()
.type("TextBlock")
.size("Medium")
.weight("Bolder")
.text("Webhook Server Check")
.build(),
WeHookMentionMessage.Body.builder()
.type("TextBlock")
.text("Webhook 서버 점검하세요. 재기동됩니다. <at>이름1</at>, <at>이름2</at>, <at>이름3</at> " + responseBody)
.build()
))
.schema("http://adaptivecards.io/schemas/adaptive-card.json")
.version("1.0")
.msteams(WeHookMentionMessage.Msteams.builder()
.entities(Arrays.asList(
WeHookMentionMessage.Entity.builder()
.type("mention")
.text("<at>이름1</at>")
.mentioned(WeHookMentionMessage.Mentioned.builder()
.id("이름2@test.onmicrosoft.com")
.name("이름1")
.build())
.build(),
WeHookMentionMessage.Entity.builder()
.type("mention")
.text("<at>이름2</at>")
.mentioned(WeHookMentionMessage.Mentioned.builder()
.id("이름2@test.onmicrosoft.com")
.name("이름2")
.build())
.build(),
WeHookMentionMessage.Entity.builder()
.type("mention")
.text("<at>이름3</at>")
.mentioned(WeHookMentionMessage.Mentioned.builder()
.id("이름3@test.onmicrosoft.com")
.name("이름3")
.build())
.build()
))
.build())
.build())
.build()
);
String webhookUrl = ",,,";
WeHookMentionMessage message = WeHookMentionMessage.builder()
.type("message")
.attachments(attachments)
.build();
String webhookMessageJson = gson.toJson(message);
teamsWebhookApiUtil.send(webhookUrl, webhookMessageJson);
/**
* Webhook 서버 재시작 로직 실행
*/
try{
Session session = sshCommandConfig.sshSession();
...
} catch(Exception e){
log.error("서버 재시작 로직 중 에러 발생... {} " , e);
}
}
}
대충이렇게 만듦..하드코딩으로 박아버리기
'문제해결' 카테고리의 다른 글
Thread 가 많아질때 왜그럴까? (0) | 2024.12.31 |
---|---|
이 로직 .. 이게 어디서 동작하지? (0) | 2024.05.29 |
php 로그 확인법 (0) | 2024.03.09 |
terminus 왼쪽 사이드바 안나올때 (0) | 2024.03.04 |
linux 서버/ windows 강제 프로세스 종료 (0) | 2023.09.07 |