-
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.
Merge pull request #99 from TeamPINGLE/develop
DEPLOY
- Loading branch information
Showing
5 changed files
with
83 additions
and
1 deletion.
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
72 changes: 72 additions & 0 deletions
72
src/main/java/org/pingle/pingleserver/utils/SlackUtil.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,72 @@ | ||
package org.pingle.pingleserver.utils; | ||
|
||
import com.slack.api.Slack; | ||
import com.slack.api.webhook.Payload; | ||
import com.slack.api.webhook.WebhookResponse; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
public class SlackUtil { | ||
|
||
@Value("${slack.webhook.team-created}") | ||
private static String teamCreatedWebhookUrl; | ||
@Value("${slack.webhook.user-join}") | ||
private static String userJoinWebhookUrl; | ||
@Value("${slack.webhook.meeting-created}") | ||
private static String meetingCreatedWebhookUrl; | ||
@Value("${slack.webhook.server-error}") | ||
private static String serverErrorWebhookUrl; | ||
|
||
public static WebhookResponse alertUserSignUp (String name, String email) { | ||
try { | ||
String text = name + "(" + email + ")" +"님이 가입했습니다."; | ||
WebhookResponse response; | ||
Slack slack = Slack.getInstance(); | ||
Payload payload = Payload.builder().text(text).build(); | ||
response = slack.send(userJoinWebhookUrl, payload); | ||
return response; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
public static WebhookResponse alertCreateTeam(String teamName) { | ||
try { | ||
String text = "팀 : " + teamName + "이 생성되었습니다."; | ||
WebhookResponse response; | ||
Slack slack = Slack.getInstance(); | ||
Payload payload = Payload.builder().text(text).build(); | ||
response = slack.send(teamCreatedWebhookUrl, payload); | ||
return response; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
public static WebhookResponse alertCreateMeeting(String location, String meetingName) { | ||
try { | ||
String text = location + "에서" + meetingName + "번개가 생성되었습니다."; | ||
WebhookResponse response; | ||
Slack slack = Slack.getInstance(); | ||
Payload payload = Payload.builder().text(text).build(); | ||
response = slack.send(meetingCreatedWebhookUrl, payload); | ||
return response; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
public static WebhookResponse alertError(Exception exception) { | ||
try { | ||
String text = exception.getClass().getName() + " " | ||
+ exception.getMessage() + "\n" | ||
+ Arrays.toString(exception.getStackTrace()); | ||
WebhookResponse response; | ||
Slack slack = Slack.getInstance(); | ||
Payload payload = Payload.builder().text(text).build(); | ||
response = slack.send(serverErrorWebhookUrl, payload); | ||
return response; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |