Skip to content

Commit

Permalink
fix: discord webhook url config
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 18, 2024
1 parent da651a1 commit fae691f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ jobs:
oauth.kakao.client-secret-code: ${{ secrets.OAUTH_KAKAO_CLIENT_SECRET_CODE }}
oauth.kakao.admin-key: ${{ secrets.OAUTH_KAKAO_ADMIN_KEY }}
# Discord-Webhook-client 환경 변수 주입
client.discord.webhook.credential.1.webhookId: ${{ secrets.CLIENT_DISCORD_WEBHOOK_CREDENTIAL_1_WEBHOOK_ID }}
client.discord.webhook.credential.1.webhookToken: ${{ secrets.CLIENT_DISCORD_WEBHOOK_CREDENTIAL_1_WEBHOOK_TOKEN }}
client.discord.webhook.url: ${{ secrets.CLIENT_DISCORD_WEBHOOK_URL }}

# Secret Setup - application-prod.yml
- name: Inject env-values to application-prod.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
package com.hero.alignlab.client.discord.client

import com.hero.alignlab.client.discord.config.DiscordWebhookClientConfig
import com.hero.alignlab.client.discord.model.request.SendMessageRequest
import com.hero.alignlab.client.discord.model.response.GetWebhookWithTokenResponse
import com.hero.alignlab.client.kakao.SuspendableClient
import org.springframework.web.reactive.function.client.WebClient

class SuspendableDiscordWebhookClient(
client: WebClient,
private val config: DiscordWebhookClientConfig.Config,
) : DiscordWebhookClient, SuspendableClient(client) {
override suspend fun getWebhookWithToken(id: Int): GetWebhookWithTokenResponse {
return client
.get()
.discordUri(id)
.request()
}

override suspend fun sendMessage(id: Int, request: SendMessageRequest) {
return client
.post()
.discordUri(id)
.bodyValue(request)
.request()
}

private fun WebClient.RequestHeadersUriSpec<*>.discordUri(id: Int): WebClient.RequestHeadersSpec<*> {
val credential = getWebhookCredential(id)
return this.uri("/${credential.webhookId}/${credential.webhookToken}")
}

private fun WebClient.RequestBodyUriSpec.discordUri(id: Int): WebClient.RequestBodySpec {
val credential = getWebhookCredential(id)
return this.uri("/${credential.webhookId}/${credential.webhookToken}")
}

private fun getWebhookCredential(id: Int): DiscordWebhookClientConfig.Config.WebhookContext {
return config.credential[id] ?: throw RuntimeException("Webhook Credential does not exist, $id")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,11 @@ class DiscordWebhookClientConfig {

val webclient = WebClientFactory.generate(discordWebhookConfig.url)

return SuspendableDiscordWebhookClient(webclient, discordWebhookConfig)
return SuspendableDiscordWebhookClient(webclient)
}

data class Config(
@field:NotBlank
var url: String = "",
var credential: Map<Int, WebhookContext> = emptyMap()
) {
data class WebhookContext(
@field:NotBlank
var webhookId: Long,
@field:NotBlank
var webhookToken: String = "",
)
}
)
}
6 changes: 1 addition & 5 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ client:
unlink-path: /v1/user/unlink
discord:
webhook:
url: https://discord.com/api/webhooks
credential:
1:
webhookId:
webhookToken:
url:

encrypt:
key:
Expand Down

0 comments on commit fae691f

Please sign in to comment.