-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from jjunsik/feat/core/POT-28
[Feat] Slack Bot 활용하여 슬랙 메시지 구현
- Loading branch information
Showing
6 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
pothole-core/src/main/java/pothole_solution/core/util/alarm/slack/SlackService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package pothole_solution.core.util.alarm.slack; | ||
|
||
import com.slack.api.Slack; | ||
import com.slack.api.methods.MethodsClient; | ||
import com.slack.api.methods.SlackApiException; | ||
import com.slack.api.methods.request.chat.ChatPostMessageRequest; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import pothole_solution.core.util.alarm.slack.constant.SlackConstant; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@Service | ||
public class SlackService { | ||
@Value(value = "${slack.token}") | ||
String slackToken; | ||
|
||
public void sendSlackMessage(String message) { | ||
try { | ||
MethodsClient methodsClient = Slack.getInstance().methods(slackToken); | ||
|
||
ChatPostMessageRequest messageRequest = ChatPostMessageRequest.builder() | ||
.channel(SlackConstant.POTHOLE_SERVER_DEPLOY) | ||
.text(message) | ||
.build(); | ||
|
||
methodsClient.chatPostMessage(messageRequest); | ||
|
||
log.info("Slack " + SlackConstant.POTHOLE_SERVER_DEPLOY + "에 메시지 보냄."); | ||
|
||
} catch (SlackApiException | IOException e) { | ||
log.error("slack error: {}", e.getMessage(), e); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ole-core/src/main/java/pothole_solution/core/util/alarm/slack/constant/SlackConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package pothole_solution.core.util.alarm.slack.constant; | ||
|
||
// 추후 채널 추가 시 채널에 따라 다른 작업을 하기 위해 생성 | ||
public class SlackConstant { | ||
|
||
// Slack에 생성된 채널명 | ||
public static final String POTHOLE_SERVER_DEPLOY = "#포트홀"; | ||
} |
2 changes: 1 addition & 1 deletion
2
...util/convertor/ProgressEnumConvertor.java → ...util/convertor/ProgressEnumConvertor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters