From 92734a4079f7cef71537e47e5992102c21d389a9 Mon Sep 17 00:00:00 2001 From: RikitoNoto <56541594+RikitoNoto@users.noreply.github.com> Date: Thu, 24 Aug 2023 21:43:29 +0900 Subject: [PATCH] =?UTF-8?q?#147=20Slack=E9=80=9A=E7=9F=A5=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../callable-functions/notificationSlack.ts | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/functions/src/callable-functions/notificationSlack.ts b/functions/src/callable-functions/notificationSlack.ts index c5d512e0..ea7df990 100644 --- a/functions/src/callable-functions/notificationSlack.ts +++ b/functions/src/callable-functions/notificationSlack.ts @@ -1,26 +1,12 @@ import axios from 'axios'; -import { https } from 'firebase-functions/v2'; -export const notificationSlack = https.onRequest(async (request, response) => { - if (request.method === `OPTIONS`) { - response.set(`Access-Control-Allow-Methods`, `POST`); - response.set(`Access-Control-Allow-Headers`, `Content-Type`); - response.status(204).send(``); - } - else if (request.method === `POST`) { - if (request.body[`text`]) { - const endpoint = process.env.SLACK_ENDPOINT - if (!endpoint) { - response.status(400).send(`could not find SLACK_ENDPOINT`); - return; - } - axios.post(endpoint, { text: request.body[`text`] }); - response.status(200).send(`OK`); - } - else { - response.status(400).send(`invalid parameter. You must include 'text' param in the body`); - } - } else { - response.status(405).send(`invalid method`); - } -}); +/** + * Slackへメッセージを通知する。 + * @param {message} message - 通知するテキスト + * @throws {Error} 通知に失敗した場合、エラーを発報 + */ +export const notificationSlack = async (message: string) => { + const url = process.env.SLACK_URL; // 環境変数からURLの取得 + if (!url) return; + await axios.post(url, { text: message }); +}