-
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.
feat: slack notifier when okky doesn't parsed
- Loading branch information
Showing
3 changed files
with
42 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
35 changes: 35 additions & 0 deletions
35
SouP/src/main/java/Matching/SouP/common/SlackNotifier.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,35 @@ | ||
package Matching.SouP.common; | ||
|
||
import Matching.SouP.service.PropertyUtil; | ||
import lombok.extern.slf4j.Slf4j; | ||
import okhttp3.*; | ||
|
||
|
||
@Slf4j | ||
public class SlackNotifier { | ||
private static final OkHttpClient client = new OkHttpClient(); | ||
|
||
public void sendMessageToSlack() { | ||
String webHookURL = PropertyUtil.getProperty("webhook.url"); | ||
String message = "OKKY 파싱 에러"; | ||
|
||
RequestBody body = RequestBody.create( | ||
MediaType.parse("application/json; charset=utf-8"), | ||
"{\"text\":\"" + message + "\"}" | ||
); | ||
|
||
Request request = new Request.Builder() | ||
.url(webHookURL) | ||
.post(body) | ||
.build(); | ||
|
||
try (Response response = client.newCall(request).execute()) { | ||
if (!response.isSuccessful()) { | ||
throw new RuntimeException("Unexpected code " + response); | ||
} | ||
log.warn("Message sent successfully: " + response.body().string()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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