diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a97b388 --- /dev/null +++ b/.env.example @@ -0,0 +1,17 @@ +# Copy to .env for local development β€” never commit .env +PORT=3000 + +# Meta WhatsApp Cloud API +WHATSAPP_TOKEN= +# Meta's numeric Phone Number ID from the Developer Console β€” NOT the phone number itself +WA_PHONE_NUMBER_ID= +VERIFY_TOKEN=my-secret-verify-token + +# Anthropic +ANTHROPIC_API_KEY= + +# Chatwoot +CHATWOOT_URL=https://chatwoot.example.com +CHATWOOT_API_KEY= +CHATWOOT_ACCOUNT_ID= +CHATWOOT_INBOX_ID= diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..92c96af --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: Build and Push + +on: + push: + branches: [main] + +env: + IMAGE: ghcr.io/rmcampos/shell-whats + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ${{ env.IMAGE }}:latest + ${{ env.IMAGE }}:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..53bbf9a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,139 @@ +name: Deploy + +on: + workflow_dispatch: + workflow_run: + workflows: [Build and Push] + types: [completed] + branches: [main] + +env: + IMAGE: ghcr.io/rmcampos/shell-whats + +jobs: + plan: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + outputs: + no_changes: ${{ steps.check-changes.outputs.no_changes }} + permissions: + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Setup kubectl + uses: azure/setup-kubectl@v4 + + - name: Write kubeconfig + run: | + mkdir -p ~/.kube + echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + + - name: Terraform Fmt -check -diff + working-directory: terraform + run: terraform fmt -check -diff + + - name: Terraform init + working-directory: terraform + run: terraform init -input=false + env: + AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + + - name: Terraform Validate + working-directory: terraform + run: terraform validate + + - name: Terraform Plan + id: check-changes + working-directory: terraform + env: + AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + run: | + timeout 1m terraform plan -input=false -out=tfplan \ + -var="db_user=${{ secrets.DB_USER }}" \ + -var="db_password=${{ secrets.DB_PASSWORD }}" \ + -var="db_name=${{ secrets.DB_NAME }}" \ + -var="security_key=${{ secrets.JWT_SECURITY_KEY }}" \ + -var="mailgun_apikey=${{ secrets.MAILGUN_API_KEY }}" \ + -var="r2_access_key=${{ secrets.R2_ACCESS_KEY_ID }}" \ + -var="r2_secret_key=${{ secrets.R2_SECRET_ACCESS_KEY }}" \ + -var="backend_image=${{ steps.deploy-vars.outputs.backend_image }}" \ + -var="frontend_image=${{ steps.deploy-vars.outputs.frontend_image }}" + terraform show -json tfplan > tfplan.json + if jq -e '.resource_changes | length == 0' tfplan.json >/dev/null; then + echo "no_changes=true" >> "$GITHUB_OUTPUT" + echo "No changes to apply." + exit 0 + else + echo "Changes detected. Proceeding with apply" + echo "no_changes=false" >> "$GITHUB_OUTPUT" + fi + + - name: Upload plan artifact + uses: actions/upload-artifact@v4 + with: + name: tfplan + path: terraform/tfplan + + terraform-apply: + runs-on: ubuntu-latest + needs: terraform-plan + if: > + (github.event_name == 'push' || github.event_name == 'workflow_run' || inputs.apply == 'true') + && needs.terraform-plan.outputs.no_changes == 'false' + environment: + name: production + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Download plan artifact + uses: actions/download-artifact@v4 + with: + name: tfplan + path: terraform + + - name: Setup Kubeconfig + run: | + mkdir -p ~/.kube + echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + + - name: Terraform Init + working-directory: terraform + env: + AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + run: terraform init -input=false + + - name: Terraform apply + working-directory: terraform + env: + TF_VAR_image: "${{ env.IMAGE }}:${{ github.event.workflow_run.head_sha }}" + TF_VAR_whatsapp_token: ${{ secrets.WHATSAPP_TOKEN }} + TF_VAR_anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + TF_VAR_chatwoot_api_key: ${{ secrets.CHATWOOT_API_KEY }} + TF_VAR_phone_number_id: ${{ secrets.PHONE_NUMBER_ID }} + TF_VAR_verify_token: ${{ secrets.VERIFY_TOKEN }} + TF_VAR_chatwoot_url: ${{ secrets.CHATWOOT_URL }} + TF_VAR_chatwoot_inbox_id: ${{ secrets.CHATWOOT_INBOX_ID }} + TF_VAR_chatwoot_account_id: ${{ secrets.CHATWOOT_ACCOUNT_ID }} + TF_VAR_kubeconfig_path: "~/.kube/config" + TF_VAR_kubeconfig_context: ${{ vars.KUBECONFIG_CONTEXT }} + TF_VAR_namespace: ${{ vars.K8S_NAMESPACE || 'default' }} + run: timeout 1m terraform apply tfplan diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eaea3d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules/ +.env +terraform/.terraform/ +terraform/terraform.tfvars +terraform/*.tfstate +terraform/*.tfstate.backup +terraform/.terraform.lock.hcl diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml new file mode 100644 index 0000000..2aa056d --- /dev/null +++ b/.idea/google-java-format.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0a0b7ce --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + {} + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1317a21 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/shell-whats.iml b/.idea/shell-whats.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/shell-whats.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f654eb7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:22-alpine AS deps +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN npm ci --omit=dev + +FROM node:22-alpine +WORKDIR /app +ENV NODE_ENV=production + +COPY --from=deps /app/node_modules ./node_modules +COPY src ./src +COPY package.json ./ + +EXPOSE 3000 +USER node +CMD ["node", "src/index.js"] diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ea01f53 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1036 @@ +{ + "name": "shell-whats", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "shell-whats", + "version": "1.0.0", + "dependencies": { + "@anthropic-ai/sdk": "^0.52.0", + "axios": "^1.9.0", + "dotenv": "^17.4.2", + "express": "^4.19.2" + } + }, + "node_modules/@anthropic-ai/sdk": { + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.52.0.tgz", + "integrity": "sha512-d4c+fg+xy9e46c8+YnrrgIQR45CZlAi7PwdzIfDXDM6ACxEZli1/fxhURsq30ZpMZy6LvSkr41jGq5aF5TD7rQ==", + "license": "MIT", + "bin": { + "anthropic-ai-sdk": "bin/cli" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/agent-base/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/agent-base/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.16.1.tgz", + "integrity": "sha512-caYkukvroVPO8KrzuJEb50Hm07KwfBZPEC3VeFHTsqWHvKTsy54hjJz9BS/cdaypROE2rH6xvm9mHX4fgWkr3A==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.16.0", + "form-data": "^4.0.5", + "https-proxy-agent": "^5.0.1", + "proxy-from-env": "^2.1.0" + } + }, + "node_modules/body-parser": { + "version": "1.20.5", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.5.tgz", + "integrity": "sha512-3grm+/2tUOvu2cjJkvsIxrv/wVpfXQW4PsQHYm7yk4vfpu7Ekl6nEsYBoJUL6qDwZUx8wUhQ8tR2qz+ad9c9OA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.15.1", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dotenv": { + "version": "17.4.2", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz", + "integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.22.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.2.tgz", + "integrity": "sha512-IuL+Elrou2ZvCFHs18/CIzy2Nzvo25nZ1/D2eIZlz7c+QUayAcYoiM2BthCjs+EBHVpjYjcuLDAiCWgeIX3X1Q==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.5", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.12", + "proxy-addr": "~2.0.7", + "qs": "~6.15.1", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/follow-redirects": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", + "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz", + "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/https-proxy-agent/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/https-proxy-agent/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz", + "integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/proxy-from-env": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", + "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/qs": { + "version": "6.15.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz", + "integrity": "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b3fadd9 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "shell-whats", + "version": "1.0.0", + "description": "WhatsApp Business API chatbot with Claude AI and Chatwoot handoff", + "main": "src/index.js", + "scripts": { + "start": "node src/index.js", + "dev": "node --watch src/index.js" + }, + "dependencies": { + "@anthropic-ai/sdk": "^0.52.0", + "axios": "^1.9.0", + "dotenv": "^17.4.2", + "express": "^4.19.2" + } +} diff --git a/src/handlers/messageHandler.js b/src/handlers/messageHandler.js new file mode 100644 index 0000000..8a179bc --- /dev/null +++ b/src/handlers/messageHandler.js @@ -0,0 +1,105 @@ +const { getSession } = require('../store/conversations'); +const { sendText, sendInteractiveButtons } = require('../services/whatsapp'); +const { chat } = require('../services/claude'); +const { createConversation } = require('../services/chatwoot'); + +const WELCOME_TEXT = + 'OlΓ‘! πŸ‘‹ Bem-vindo ao nosso suporte. Como podemos ajudΓ‘-lo hoje?'; + +const WELCOME_BUTTONS = [ + { id: 'btn_products', title: 'πŸ›οΈ Produtos/PreΓ§os' }, + { id: 'btn_support', title: 'πŸ”§ Suporte TΓ©cnico' }, + { id: 'btn_human', title: 'πŸ‘€ Falar com Agente' }, +]; + +const HUMAN_HANDOFF_REPLIES = new Set(['btn_human', 'humano', 'agente', 'atendente', 'falar com agente', 'falar com atendente']); + +async function handleMessage({ message, phoneNumber, displayName }) { + const session = getSession(phoneNumber); + + // Already handed off β€” silently ignore (Chatwoot takes over) + if (session.handedOff) return; + + const msgType = message.type; + + // Extract text from text or interactive button reply + let userText = ''; + let buttonId = null; + + if (msgType === 'text') { + userText = message.text?.body?.trim() || ''; + } else if (msgType === 'interactive') { + const reply = message.interactive?.button_reply; + buttonId = reply?.id || ''; + userText = reply?.title || ''; + } else { + // Unsupported message type + try { + await sendText(phoneNumber, 'Desculpe, no momento sΓ³ consigo processar mensagens de texto.'); + } catch (err) { + console.error('Meta API error details:', JSON.stringify(err.response?.data, null, 2)); + } + return; + } + + // First contact β€” send welcome menu + if (!session.greeted) { + session.greeted = true; + await sendInteractiveButtons(phoneNumber, WELCOME_TEXT, WELCOME_BUTTONS); + return; + } + + // Human handoff requested + const isHandoffRequest = + HUMAN_HANDOFF_REPLIES.has(buttonId) || + HUMAN_HANDOFF_REPLIES.has(userText.toLowerCase()); + + if (isHandoffRequest) { + session.handedOff = true; + console.log(`[HANDOFF] ${displayName} (${phoneNumber}) requested a human agent`); + await sendText( + phoneNumber, + 'Estamos transferindo vocΓͺ para um de nossos atendentes. Por favor, aguarde β€” em breve alguΓ©m estarΓ‘ com vocΓͺ. πŸ™\n\nQuando o atendimento for encerrado, envie qualquer mensagem para iniciar uma nova conversa.' + ); + try { + const conversationId = await createConversation(phoneNumber, displayName, session.history); + console.log(`[HANDOFF] Chatwoot conversation created (id=${conversationId}) for ${displayName} (${phoneNumber})`); + } catch (err) { + console.error('Chatwoot handoff failed:', err?.response?.data || err.message); + console.error('Meta API error details:', JSON.stringify(err.response?.data, null, 2)); + } + return; + } + + // Route to Claude + try { + const reply = await chat(session.history, userText); + + // Persist turn in history + session.history.push({ role: 'user', content: userText }); + session.history.push({ role: 'assistant', content: reply }); + + // Keep history bounded to last 20 turns (10 exchanges) + if (session.history.length > 20) { + session.history = session.history.slice(-20); + } + + await sendText(phoneNumber, reply); + + // After every AI reply, offer the human handoff option + await sendInteractiveButtons( + phoneNumber, + 'Posso ajudar com mais alguma coisa?', + [{ id: 'btn_human', title: 'πŸ‘€ Falar com Agente' }] + ); + } catch (err) { + console.error('Claude error:', err?.message); + console.error('Meta API error details:', JSON.stringify(err.response?.data, null, 2)); + await sendText( + phoneNumber, + "Estamos com uma instabilidade no momento. Por favor, tente novamente em instantes ou digite 'atendente' para falar com um de nossos agentes." + ); + } +} + +module.exports = { handleMessage }; diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..24a15c1 --- /dev/null +++ b/src/index.js @@ -0,0 +1,15 @@ +require('dotenv').config(); +const express = require('express'); +const webhookRouter = require('./routes/webhook'); +const chatwootWebhookRouter = require('./routes/chatwootWebhook'); + +const app = express(); +app.use(express.json()); + +app.use('/webhook', webhookRouter); +app.use('/chatwoot-webhook', chatwootWebhookRouter); + +app.get('/health', (_req, res) => res.json({ status: 'ok' })); + +const PORT = process.env.PORT || 3000; +app.listen(PORT, () => console.log(`Server running on port ${PORT}`)); diff --git a/src/routes/chatwootWebhook.js b/src/routes/chatwootWebhook.js new file mode 100644 index 0000000..5d7d858 --- /dev/null +++ b/src/routes/chatwootWebhook.js @@ -0,0 +1,31 @@ +const express = require('express'); +const { sendText } = require('../services/whatsapp'); + +const router = express.Router(); + +router.post('/', async (req, res) => { + res.sendStatus(200); + + try { + const { event, message_type, content, private: isPrivate, conversation } = req.body; + + // Only forward outgoing agent messages; ignore private notes and all other events + if (event !== 'message_created' || message_type !== 'outgoing' || isPrivate) return; + + const phoneNumber = conversation?.meta?.sender?.phone_number + || conversation?.additional_attributes?.phone_number; + + if (!phoneNumber || !content) return; + + // Strip leading + so it matches the format used throughout the app + const to = phoneNumber.replace(/^\+/, ''); + + console.log(`Chatwoot agent reply β†’ WhatsApp ${to}: ${content}`); + await sendText(to, content); + } catch (err) { + console.error('Chatwoot webhook error:', err.message); + console.error('Meta API error details:', JSON.stringify(err.response?.data, null, 2)); + } +}); + +module.exports = router; diff --git a/src/routes/webhook.js b/src/routes/webhook.js new file mode 100644 index 0000000..fd3375f --- /dev/null +++ b/src/routes/webhook.js @@ -0,0 +1,43 @@ +const express = require('express'); +const { handleMessage } = require('../handlers/messageHandler'); + +const router = express.Router(); + +// Meta webhook verification challenge +router.get('/', (req, res) => { + const mode = req.query['hub.mode']; + const token = req.query['hub.verify_token']; + const challenge = req.query['hub.challenge']; + + if (mode === 'subscribe' && token === process.env.VERIFY_TOKEN) { + console.log('Webhook verified'); + return res.status(200).send(challenge); + } + res.sendStatus(403); +}); + +// Inbound messages +router.post('/', async (req, res) => { + // Acknowledge immediately β€” Meta requires 200 within 20s + res.sendStatus(200); + + try { + const entry = req.body?.entry?.[0]; + const change = entry?.changes?.[0]; + const value = change?.value; + + if (!value?.messages?.length) return; + + const message = value.messages[0]; + const contact = value.contacts?.[0]; + const phoneNumber = message.from; + const displayName = contact?.profile?.name || phoneNumber; + + await handleMessage({ message, phoneNumber, displayName }); + } catch (err) { + console.error('Webhook processing error:', err); + console.error('Meta API error details:', JSON.stringify(err.response?.data, null, 2)); + } +}); + +module.exports = router; diff --git a/src/services/chatwoot.js b/src/services/chatwoot.js new file mode 100644 index 0000000..349b24c --- /dev/null +++ b/src/services/chatwoot.js @@ -0,0 +1,66 @@ +const axios = require('axios'); + +function headers() { + return { + api_access_token: process.env.CHATWOOT_API_KEY, + 'Content-Type': 'application/json', + }; +} + +function baseUrl() { + return `${process.env.CHATWOOT_URL}/api/v1/accounts/${process.env.CHATWOOT_ACCOUNT_ID}`; +} + +async function findOrCreateContact(phoneNumber, displayName) { + const search = await axios.get(`${baseUrl()}/contacts/search`, { + params: { q: phoneNumber, include_contacts: true }, + headers: headers(), + }); + + const existing = search.data?.payload?.find( + (c) => c.phone_number === phoneNumber || c.phone_number === `+${phoneNumber}` + ); + + if (existing) return existing.id; + + const created = await axios.post( + `${baseUrl()}/contacts`, + { name: displayName, phone_number: `+${phoneNumber}` }, + { headers: headers() } + ); + return created.data.payload.contact.id; +} + +async function createConversation(phoneNumber, displayName, history) { + const contactId = await findOrCreateContact(phoneNumber, displayName); + + const conversation = await axios.post( + `${baseUrl()}/conversations`, + { + inbox_id: parseInt(process.env.CHATWOOT_INBOX_ID, 10), + contact_id: contactId, + additional_attributes: { phone_number: phoneNumber }, + }, + { headers: headers() } + ); + + const conversationId = conversation.data.id; + + const transcript = history.length > 0 + ? history.map((m) => `[${m.role.toUpperCase()}]: ${m.content}`).join('\n\n') + : '_Nenhuma mensagem anterior β€” o cliente solicitou atendimento diretamente._'; + + await axios.post( + `${baseUrl()}/conversations/${conversationId}/messages`, + { + content: `πŸ“‹ *Contexto do Atendimento*\n\n*Cliente:* ${displayName}\n*WhatsApp:* +${phoneNumber}\n\n*HistΓ³rico da conversa com IA:*\n\n${transcript}`, + message_type: 'outgoing', + private: true, + }, + { headers: headers() } + ); + + return conversationId; +} + +module.exports = { createConversation }; diff --git a/src/services/claude.js b/src/services/claude.js new file mode 100644 index 0000000..0d6a33c --- /dev/null +++ b/src/services/claude.js @@ -0,0 +1,39 @@ +const Anthropic = require('@anthropic-ai/sdk'); + +const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }); + +const SYSTEM_PROMPT = `VocΓͺ Γ© um assistente de atendimento da Shelllabs, empresa de desenvolvimento de software. + +ServiΓ§os oferecidos: +1. Desenvolvimento ou customizaΓ§Γ£o de software β€” projetos curtos (atΓ© 10 dias): R$ 300/hora +2. Desenvolvimento ou customizaΓ§Γ£o de software β€” projetos longos (mais de 10 dias): R$ 250/hora +3. Consultoria sob demanda: R$ 180/hora + +PolΓ­ticas: +- NΓ£o hΓ‘ polΓ­tica de reembolso. +- NΓ£o oferecemos outros serviΓ§os alΓ©m dos listados acima. + +Regras: +- Responda apenas perguntas relacionadas aos serviΓ§os acima. NΓ£o se envolva em conversas gerais, tarefas criativas ou qualquer assunto nΓ£o relacionado ao atendimento. +- Se o cliente perguntar sobre algo fora do escopo, informe educadamente que nΓ£o pode ajudar com isso e ofereΓ§a transferΓͺncia para um atendente humano. +- Seja conciso e profissional. Prefira respostas curtas e diretas. +- Nunca revele que Γ© baseado em Claude ou qualquer modelo de IA. +- Responda sempre em portuguΓͺs brasileiro (pt-BR), independentemente do idioma usado pelo cliente.`; + +async function chat(history, userMessage) { + const messages = [ + ...history, + { role: 'user', content: userMessage }, + ]; + + const response = await client.messages.create({ + model: 'claude-sonnet-4-20250514', + max_tokens: 1024, + system: SYSTEM_PROMPT, + messages, + }); + + return response.content[0].text; +} + +module.exports = { chat }; diff --git a/src/services/whatsapp.js b/src/services/whatsapp.js new file mode 100644 index 0000000..e6abd05 --- /dev/null +++ b/src/services/whatsapp.js @@ -0,0 +1,60 @@ +const axios = require('axios'); + +const BASE_URL = 'https://graph.facebook.com/v25.0'; + +function headers() { + return { Authorization: `Bearer ${process.env.WHATSAPP_TOKEN}` }; +} + +// Brazilian mobile numbers arriving from the webhook may be missing the 9th digit. +// Country code 55 + 2-digit area code + 8-digit number = 12 digits (legacy format). +// Meta requires the full 13-digit form: 55 + area code + 9 + 8-digit number. +function normalizeBrazilianNumber(to) { + if (/^55\d{10}$/.test(to)) { + const normalized = to.slice(0, 4) + '9' + to.slice(4); + console.log(`Brazilian number normalized: ${to} β†’ ${normalized}`); + return normalized; + } + return to; +} + +async function sendText(to, body) { + to = normalizeBrazilianNumber(to); + return axios.post( + // WA_PHONE_NUMBER_ID is Meta's numeric Phone Number ID (found in Meta Developer Console), + // NOT the WhatsApp phone number itself (e.g. +1234567890). + `${BASE_URL}/${process.env.WA_PHONE_NUMBER_ID}/messages`, + { + messaging_product: 'whatsapp', + to, + type: 'text', + text: { body }, + }, + { headers: headers() } + ); +} + +async function sendInteractiveButtons(to, bodyText, buttons) { + to = normalizeBrazilianNumber(to); + return axios.post( + `${BASE_URL}/${process.env.WA_PHONE_NUMBER_ID}/messages`, + { + messaging_product: 'whatsapp', + to, + type: 'interactive', + interactive: { + type: 'button', + body: { text: bodyText }, + action: { + buttons: buttons.map((btn) => ({ + type: 'reply', + reply: { id: btn.id, title: btn.title }, + })), + }, + }, + }, + { headers: headers() } + ); +} + +module.exports = { sendText, sendInteractiveButtons }; diff --git a/src/store/conversations.js b/src/store/conversations.js new file mode 100644 index 0000000..a6f4bcb --- /dev/null +++ b/src/store/conversations.js @@ -0,0 +1,19 @@ +// In-memory conversation store β€” replace with Redis for production +const store = new Map(); + +function getSession(phoneNumber) { + if (!store.has(phoneNumber)) { + store.set(phoneNumber, { + history: [], // Claude message history [{role, content}] + handedOff: false, // true once forwarded to Chatwoot + greeted: false, // true after welcome menu sent + }); + } + return store.get(phoneNumber); +} + +function clearSession(phoneNumber) { + store.delete(phoneNumber); +} + +module.exports = { getSession, clearSession }; diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..bf2b707 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,188 @@ +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + version = "~> 2.30" + } + } + backend "s3" { + bucket = "shell-whats" + key = "kubernetes/terraform.tfstate" + region = "auto" + endpoints = { s3 = "https://d17eb09b6bce2f90e16e800bb2a6baf9.r2.cloudflarestorage.com" } + skip_credentials_validation = true + skip_region_validation = true + skip_requesting_account_id = true + skip_metadata_api_check = true + skip_s3_checksum = true + } + required_version = ">= 1.6" +} + +provider "kubernetes" { + config_path = var.kubeconfig_path + config_context = var.kubeconfig_context +} + +locals { + app_name = "shell-whats" + labels = { app = local.app_name } +} + +# ── Secret ──────────────────────────────────────────────────────────────────── + +resource "kubernetes_secret" "app" { + metadata { + name = "${local.app_name}-secret" + namespace = var.namespace + } + + data = { + WHATSAPP_TOKEN = var.whatsapp_token + ANTHROPIC_API_KEY = var.anthropic_api_key + CHATWOOT_API_KEY = var.chatwoot_api_key + } +} + +# ── ConfigMap ───────────────────────────────────────────────────────────────── + +resource "kubernetes_config_map" "app" { + metadata { + name = "${local.app_name}-config" + namespace = var.namespace + } + + data = { + NODE_ENV = "production" + PORT = "3000" + PHONE_NUMBER_ID = var.phone_number_id + VERIFY_TOKEN = var.verify_token + CHATWOOT_URL = var.chatwoot_url + CHATWOOT_INBOX_ID = var.chatwoot_inbox_id + CHATWOOT_ACCOUNT_ID = var.chatwoot_account_id + } +} + +# ── Deployment ──────────────────────────────────────────────────────────────── + +resource "kubernetes_deployment" "app" { + metadata { + name = local.app_name + namespace = var.namespace + labels = local.labels + } + + spec { + replicas = var.replicas + + selector { + match_labels = local.labels + } + + template { + metadata { + labels = local.labels + } + + spec { + container { + name = local.app_name + image = var.image + + port { + container_port = 3000 + protocol = "TCP" + } + + # Non-secret env vars from ConfigMap + env_from { + config_map_ref { + name = kubernetes_config_map.app.metadata[0].name + } + } + + # Secrets injected individually + env { + name = "WHATSAPP_TOKEN" + value_from { + secret_key_ref { + name = kubernetes_secret.app.metadata[0].name + key = "WHATSAPP_TOKEN" + } + } + } + + env { + name = "ANTHROPIC_API_KEY" + value_from { + secret_key_ref { + name = kubernetes_secret.app.metadata[0].name + key = "ANTHROPIC_API_KEY" + } + } + } + + env { + name = "CHATWOOT_API_KEY" + value_from { + secret_key_ref { + name = kubernetes_secret.app.metadata[0].name + key = "CHATWOOT_API_KEY" + } + } + } + + resources { + requests = { + cpu = "100m" + memory = "128Mi" + } + limits = { + cpu = "500m" + memory = "256Mi" + } + } + + liveness_probe { + http_get { + path = "/health" + port = 3000 + } + initial_delay_seconds = 10 + period_seconds = 30 + } + + readiness_probe { + http_get { + path = "/health" + port = 3000 + } + initial_delay_seconds = 5 + period_seconds = 10 + } + } + } + } + } +} + +# ── Service ─────────────────────────────────────────────────────────────────── + +resource "kubernetes_service" "app" { + metadata { + name = local.app_name + namespace = var.namespace + labels = local.labels + } + + spec { + selector = local.labels + type = var.service_type + + port { + port = 80 + target_port = 3000 + protocol = "TCP" + } + } +} diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..36295a6 --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,14 @@ +output "service_name" { + description = "Kubernetes service name" + value = kubernetes_service.app.metadata[0].name +} + +output "service_cluster_ip" { + description = "ClusterIP assigned to the service" + value = kubernetes_service.app.spec[0].cluster_ip +} + +output "deployment_name" { + description = "Kubernetes deployment name" + value = kubernetes_deployment.app.metadata[0].name +} diff --git a/terraform/terraform.tfvars.example b/terraform/terraform.tfvars.example new file mode 100644 index 0000000..156c1e7 --- /dev/null +++ b/terraform/terraform.tfvars.example @@ -0,0 +1,16 @@ +# Copy to terraform.tfvars and fill in real values β€” never commit that file +image = "registry.example.com/shell-whats:latest" +namespace = "bots" +replicas = 1 +service_type = "ClusterIP" +kubeconfig_context = "k3s-prod" + +phone_number_id = "1234567890" +verify_token = "my-secret-verify-token" +chatwoot_url = "https://chatwoot.example.com" +chatwoot_inbox_id = "1" + +# Sensitive β€” prefer TF_VAR_* env vars instead of this file +whatsapp_token = "" +anthropic_api_key = "" +chatwoot_api_key = "" diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..04386dd --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,81 @@ +variable "kubeconfig_path" { + description = "Path to kubeconfig file" + type = string + default = "~/.kube/config" +} + +variable "kubeconfig_context" { + description = "Kubernetes context to use" + type = string + default = "" +} + +variable "namespace" { + description = "Kubernetes namespace" + type = string + default = "default" +} + +variable "image" { + description = "Docker image for the app (e.g. registry.example.com/shell-whats:latest)" + type = string +} + +variable "replicas" { + description = "Number of pod replicas" + type = number + default = 1 +} + +variable "service_type" { + description = "Kubernetes service type (ClusterIP, NodePort, LoadBalancer)" + type = string + default = "ClusterIP" +} + +# ── App secrets (sensitive) ─────────────────────────────────────────────────── + +variable "whatsapp_token" { + description = "Meta WhatsApp Cloud API access token" + type = string + sensitive = true +} + +variable "anthropic_api_key" { + description = "Anthropic API key" + type = string + sensitive = true +} + +variable "chatwoot_api_key" { + description = "Chatwoot API access token" + type = string + sensitive = true +} + +# ── App config ──────────────────────────────────────────────────────────────── + +variable "phone_number_id" { + description = "Meta WhatsApp Phone Number ID" + type = string +} + +variable "verify_token" { + description = "Webhook verify token (self-defined, must match Meta dashboard)" + type = string +} + +variable "chatwoot_url" { + description = "Chatwoot base URL (e.g. https://chatwoot.example.com)" + type = string +} + +variable "chatwoot_inbox_id" { + description = "Chatwoot inbox ID for WhatsApp conversations" + type = string +} + +variable "chatwoot_account_id" { + description = "Chatwoot account ID" + type = string +}