From 1259ba76c9106d5e7684537caf58d801e1284e2f Mon Sep 17 00:00:00 2001 From: kosukesuenaga Date: Tue, 9 Dec 2025 14:57:17 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E7=92=B0=E5=A2=83?= =?UTF-8?q?=E3=83=87=E3=83=97=E3=83=AD=E3=82=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api-gateway/create_api_dev.sh | 2 +- api-gateway/deploy_dev.sh | 6 +- api-gateway/openapi_dev.yaml | 191 +++++++++++++++++- functions/generate_minutes/.gcloudignore | 24 +++ .../generate_minutes/deploy_function_dev.sh | 32 +++ functions/generate_minutes/src/apiRouter.ts | 42 ++-- 6 files changed, 267 insertions(+), 30 deletions(-) create mode 100644 functions/generate_minutes/.gcloudignore create mode 100644 functions/generate_minutes/deploy_function_dev.sh diff --git a/api-gateway/create_api_dev.sh b/api-gateway/create_api_dev.sh index 1e97276..0ec87ab 100755 --- a/api-gateway/create_api_dev.sh +++ b/api-gateway/create_api_dev.sh @@ -7,7 +7,7 @@ PROJECT_ID="datacom-poc" API_NAME="sales-tool-api" # プロジェクトを設定 -gcloud auth application-default set-quota-project dmiru-dev +gcloud auth application-default set-quota-project $PROJECT_ID gcloud config set project $PROJECT_ID # API Gatewayを作成 diff --git a/api-gateway/deploy_dev.sh b/api-gateway/deploy_dev.sh index b7ad6a2..37f45f7 100755 --- a/api-gateway/deploy_dev.sh +++ b/api-gateway/deploy_dev.sh @@ -2,11 +2,11 @@ # 環境変数 API_NAME="sales-tool-api" -API_CONFIG_NAME="sales-tool-gw-dev-conf-20250619" -GATEWAY_NAME="sales-tool-gw-dev" +API_CONFIG_NAME="sales-tool-gw-dev-conf-20251209" +GATEWAY_NAME="sales-tool-gw-dev-20251209" OPENAPI_SPEC="openapi_dev.yaml" PROJECT_ID="datacom-poc" -SERVICE_ACCOUNT="api-gateway-mpos@datacom-poc.iam.gserviceaccount.com" +SERVICE_ACCOUNT="mrt-apigateway-sa-devtest@datacom-poc.iam.gserviceaccount.com" LOCATION="asia-northeast1" gcloud auth application-default set-quota-project $PROJECT_ID diff --git a/api-gateway/openapi_dev.yaml b/api-gateway/openapi_dev.yaml index ad2a432..6fa1524 100755 --- a/api-gateway/openapi_dev.yaml +++ b/api-gateway/openapi_dev.yaml @@ -6,13 +6,191 @@ info: schemes: - 'https' paths: - /trigger-minutes-workflow-from-miitel: + /miitel: post: - description: 'ワークフロー呼び出し処理' - operationId: 'trigger-minutes-workflow-from-miitel' + description: 'Miitel Webhook Processer' + operationId: 'miitel' x-google-backend: - address: https://asia-northeast1-datacom-poc.cloudfunctions.net/mrt-trigger-minutes-workflow-from-miitel + address: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes/api/miitel path_translation: CONSTANT_ADDRESS + jwt_audience: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes + deadline: 600 + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: body + description: JSON payload + required: false + schema: + type: object + additionalProperties: true + responses: + 200: + description: 'OK' + schema: + type: object + additionalProperties: true + 401: + description: 'Auth Error' + schema: + type: object + properties: + error: + type: string + 500: + description: 'Error' + schema: + type: object + properties: + error: + type: string + security: + - APIKeyHeader: [] + + /dailyBatch: + post: + description: 'get companies and owners' + operationId: 'dailyBatch' + x-google-backend: + address: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes/api/dailyBatch + path_translation: CONSTANT_ADDRESS + jwt_audience: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes + deadline: 600 + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: body + description: JSON payload + required: false + schema: + type: object + additionalProperties: true + responses: + 200: + description: 'OK' + schema: + type: object + additionalProperties: true + 401: + description: 'Auth Error' + schema: + type: object + properties: + error: + type: string + 500: + description: 'Error' + schema: + type: object + properties: + error: + type: string + security: + - APIKeyHeader: [] + + /getLog: + post: + description: 'get log' + operationId: 'getLog' + x-google-backend: + address: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes/api/getLog + path_translation: CONSTANT_ADDRESS + jwt_audience: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes + deadline: 600 + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: body + description: JSON payload + required: false + schema: + type: object + additionalProperties: true + responses: + 200: + description: 'OK' + schema: + type: object + additionalProperties: true + 401: + description: 'Auth Error' + schema: + type: object + properties: + error: + type: string + 500: + description: 'Error' + schema: + type: object + properties: + error: + type: string + security: + - APIKeyHeader: [] + + /reExecute: + post: + description: '' + operationId: 'reExecute' + x-google-backend: + address: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes/api/reExecute + path_translation: CONSTANT_ADDRESS + jwt_audience: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes + deadline: 600 + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: body + description: JSON payload + required: false + schema: + type: object + additionalProperties: true + responses: + 200: + description: 'OK' + schema: + type: object + additionalProperties: true + 401: + description: 'Auth Error' + schema: + type: object + properties: + error: + type: string + 500: + description: 'Error' + schema: + type: object + properties: + error: + type: string + security: + - APIKeyHeader: [] + + /test: + post: + description: 'test' + operationId: 'test' + x-google-backend: + address: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes/api/test + path_translation: CONSTANT_ADDRESS + jwt_audience: https://asia-northeast1-datacom-poc.cloudfunctions.net/generate_minutes + deadline: 600 consumes: - application/json produces: @@ -49,10 +227,7 @@ paths: - APIKeyHeader: [] options: summary: 'CORS support' - operationId: 'trigger-minutes-workflow-from-miitel-options' - x-google-backend: - address: https://asia-northeast1-datacom-poc.cloudfunctions.net/mrttrigger-minutes-workflow-from-miitel - path_translation: CONSTANT_ADDRESS + operationId: 'test-options' responses: 204: description: 'CORS preflight' diff --git a/functions/generate_minutes/.gcloudignore b/functions/generate_minutes/.gcloudignore new file mode 100644 index 0000000..8fbd543 --- /dev/null +++ b/functions/generate_minutes/.gcloudignore @@ -0,0 +1,24 @@ +# This file specifies files that are *not* uploaded to Google Cloud +# using gcloud. It follows the same syntax as .gitignore, with the addition of +# "#!include" directives (which insert the entries of the given .gitignore-style +# file at that point). +# +# For more information, run: +# $ gcloud topic gcloudignore +# +.gcloudignore +# If you would like to upload your .git directory, .gitignore file or files +# from your .gitignore file, remove the corresponding line +# below: +.git +.gitignore + +node_modules + +.env_dev +.env_prod + +deploy_function_dev.sh + +package-lock.json + diff --git a/functions/generate_minutes/deploy_function_dev.sh b/functions/generate_minutes/deploy_function_dev.sh new file mode 100644 index 0000000..fc372b2 --- /dev/null +++ b/functions/generate_minutes/deploy_function_dev.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# プロジェクトIDを設定 +PROJECT_ID="datacom-poc" + +# デプロイする関数名 +FUNCTION_NAME="generate_minutes" + +# 関数のエントリポイント +ENTRY_POINT="helloHttp" + +# ランタイム +RUNTIME="nodejs22" + +# リージョン +REGION="asia-northeast1" + +# 環境変数ファイル +ENV_VARS_FILE=".env_dev" + +gcloud auth application-default set-quota-project $PROJECT_ID +gcloud config set project $PROJECT_ID + +gcloud functions deploy $FUNCTION_NAME \ + --gen2 \ + --region $REGION \ + --runtime $RUNTIME \ + --source=. \ + --entry-point $ENTRY_POINT \ + --env-vars-file $ENV_VARS_FILE \ + --trigger-http \ + --timeout 600s \ diff --git a/functions/generate_minutes/src/apiRouter.ts b/functions/generate_minutes/src/apiRouter.ts index 6077066..03efbaf 100644 --- a/functions/generate_minutes/src/apiRouter.ts +++ b/functions/generate_minutes/src/apiRouter.ts @@ -6,6 +6,7 @@ import { hubspotController } from "./logics/hubspot"; import { createCustomError, responseError } from "./logics/error"; import { CLOUD_STORAGE_LOG_FOLDER_NAME, CLOUD_STORAGE_MASTER_FOLDER_NAME, COMPANIES_FILE_NAME, OWNERS_FILE_NAME } from "../serverConfig"; import { Delay } from "cerceis-lib"; +import { googleDriveController } from "./logics/googleDrive"; const router = express.Router(); @@ -13,6 +14,10 @@ const router = express.Router(); router.post("/miitel", async (req, res) => { try { const body = req.body; + + if('challenge' in body) return res.status(200).contentType('text/plain').send(body.challenge); + + const parsedBody = MiiTelWebhookSchema.safeParse(body); if (!parsedBody.success) throw createCustomError("ZOD_FAILED"); @@ -23,9 +28,10 @@ router.post("/miitel", async (req, res) => { await processRequest(videoInfo); // if(!result) throw - res.status(200).send("ok"); + return res.status(200).send("ok"); } catch(err) { - responseError(err, res) + responseError(err, res); + return; } }); @@ -118,22 +124,22 @@ router.post("/logUpload", async (req, res) => { // res.send('ok'); // }); -// router.post("/test", async (req, res) => { -// try { +router.post("/test", async (req, res) => { + try { -// const googleAuth = await googleDriveController.getAuth(); -// const driveClilent = googleDriveController.getDriveClient(googleAuth); -// const sheetsClient = googleDriveController.getSheetsClient(googleAuth); -// const folderId = await googleDriveController.searchFileIdByFileName(driveClilent, MINUTES_CREATION_HISTORY_FOLDER_ID, '2025'); -// if(!folderId) throw new Error() -// // console.log(fileId); -// // const sheetId = await googleDriveController.getLogSheetId(driveClilent, sheetsClient, folderId, 'test1'); -// // console.log('sheet id : ', sheetId); -// res.send("ok"); -// } catch (error) { -// console.error("Error in /test endpoint:", error); -// res.status(500).send("Error in /test endpoint"); -// } -// }); + // const googleAuth = await googleDriveController.getAuth(); + // const driveClilent = googleDriveController.getDriveClient(googleAuth); + // const sheetsClient = googleDriveController.getSheetsClient(googleAuth); + // const folderId = await googleDriveController.searchFileIdByFileName(driveClilent, MINUTES_CREATION_HISTORY_FOLDER_ID, '2025'); + // if(!folderId) throw new Error() + // console.log(fileId); + // const sheetId = await googleDriveController.getLogSheetId(driveClilent, sheetsClient, folderId, 'test1'); + // console.log('sheet id : ', sheetId); + res.send("ok"); + } catch (error) { + console.error("Error in /test endpoint:", error); + res.status(500).send("Error in /test endpoint"); + } +}); export default router; \ No newline at end of file