Skip to content

Commit

Permalink
fix: use channelID parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pirosiki197 committed Jul 1, 2024
1 parent 9e92441 commit 3aabea6
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ function doPost(e: GoogleAppsScript.Events.DoPost) {
const req: AlertRequest = JSON.parse(e.postData.contents)
const alertMessages = req.alerts.map(alertToMessage)
const text = alertMessages.join('\n\n')
const alertType = e.parameter.alertType
switch (alertType) {
case 'services':
sendServiceStatusMessage(text)
break
case 'logs':
sendErrorLogMessage(text)
break
}
const channelID = e.parameter.channelID
sendMessage(text, channelID)
}

function getStatusEmoji(status: string) {
Expand All @@ -45,31 +38,15 @@ ${link}
`.trim()
}

function sendServiceStatusMessage(message: string) {
const sign = computeSignature(message)
UrlFetchApp.fetch(`https://q.trap.jp/api/v3/webhooks/${WEBHOOK_ID}`, {
method: 'post',
contentType: 'text/plain; charset=utf-8',
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'X-TRAQ-Signature': sign
},
payload: message
})
}

// #team/SysAd/logs/error
const ERROR_LOG_CHANNEL_ID = 'cec4f852-817f-4fab-91d7-a668712b9ab6'

function sendErrorLogMessage(message: string) {
function sendMessage(message: string, channelID: string) {
const sign = computeSignature(message)
UrlFetchApp.fetch(`https://q.trap.jp/api/v3/webhooks/${WEBHOOK_ID}`, {
method: 'post',
contentType: 'text/plain; charset=utf-8',
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'X-TRAQ-Signature': sign,
'X-TRAQ-Channel-Id': ERROR_LOG_CHANNEL_ID
'X-TRAQ-Channel-Id': channelID
},
payload: message
})
Expand Down

0 comments on commit 3aabea6

Please sign in to comment.