ex)
https://pmoo365.webhook.office.com/webhook2/alaskdjalskdjasldk
-> https://outlook.office365.com/webhook2/alaskdjalskdjasldk
회사 전체적으로 Slack을 사용하는게 아니라 Teams를 사용하고 있기에, teams에 맞춰서 커스텀하게 소스를 수정해 보기로 했다.
위 내용처럼 먼저 자체 빌드 환경 세팅을 만들었다.
1) webhook.scala.html
<div>
<label class="radio inline">
<input type="radio" name="webhookType" value="SIMPLE" checked> Messenger (Only text)
</label>
<label class="radio inline">
<input type="radio" name="webhookType" value="DETAIL_SLACK"> Slack (Meta)
</label>
<label class="radio inline">
<input type="radio" name="webhookType" value="DETAIL_HANGOUT_CHAT"> Google Chat (Thread)
</label>
<label class="radio inline">
<input type="radio" name="webhookType" value="JSON"> Continuous Integration tool (Only push event)
</label>
<label class="radio inline">
<input type="radio" name="webhookType" value="TEAMS"> Microsoft Teams
</label>
<label class="radio inline"> | </label><label class="radio inline"></label>
<label class="checkbox inline" for="gitPush">
<input type="checkbox" id="gitPush" name="gitPush" class="form-check-input"> @Messages("project.webhook.includeGitPush")
</label>
</div>
2) WebhookType.java
public enum WebhookType {
SIMPLE(0), DETAIL_SLACK(1), DETAIL_HANGOUT_CHAT(2), JSON(3), TEAMS(4);
private int type;
WebhookType(int type) {
this.type = type;
}
}
3) Webhook.java
private String buildRequestMessage(String url, String message) {
StringBuilder requestMessage = new StringBuilder();
// TEAMS 전용 메세지일 경우 해당 정보로 전송
if (this.webhookType == WebhookType.TEAMS) {
requestMessage.append(String.format(" [%s](%s%s)", message, getBaseUrl(), url));
} else {
requestMessage.append(String.format(" <%s%s|", getBaseUrl(), url));
if (this.webhookType == WebhookType.DETAIL_SLACK) {
requestMessage.append(message.replace(">", ">"));
} else {
requestMessage.append(message);
}
requestMessage.append(">");
}
return requestMessage.toString();
}