-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT]회원 가입 시에 슬랙에 알림 발생 기능 개발
- Loading branch information
Showing
5 changed files
with
52 additions
and
5 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
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
33 changes: 33 additions & 0 deletions
33
...Server/src/main/java/com/example/growthookserver/external/slack/service/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,33 @@ | ||
package com.example.growthookserver.external.slack.service; | ||
|
||
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 java.io.IOException; | ||
|
||
@Service | ||
@Slf4j | ||
public class SlackService { | ||
@Value(value = "${slack.token}") | ||
String slackToken; | ||
|
||
public void sendSlackMessage(String userName, Long totalMember, String channel) { | ||
String message = userName +"님은 " + totalMember.toString() + "번째 쑥쑥이에어 곰이 됐어요."; | ||
try { | ||
MethodsClient methods = Slack.getInstance().methods(slackToken); | ||
|
||
ChatPostMessageRequest request = ChatPostMessageRequest.builder() | ||
.channel(channel) | ||
.text(message) | ||
.build(); | ||
methods.chatPostMessage(request); | ||
} catch (SlackApiException | IOException e) { | ||
throw new RuntimeException(e.getMessage()); | ||
} | ||
} | ||
} |