diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..6893dc38 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Require review/approval for any changes to GitHub Actions workflows +/.github/workflows/ @AchoArnold diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 00000000..dd234131 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,141 @@ +# Copilot Instructions for httpSMS + +httpSMS is a service that turns an Android phone into an SMS gateway via an HTTP API. This is a monorepo with three components: + +- **`api/`** — Go backend (Fiber, GORM, PostgreSQL) +- **`web/`** — Nuxt 2 frontend (Vue 2, Vuetify 2, TypeScript) +- **`android/`** — Native Android app (Kotlin) + +## Build, Test, and Lint Commands + +### API (Go) + +```bash +cd api + +# Development with hot-reload +air + +# Build +go build -o ./tmp/main.exe . + +# Run tests +go test ./... + +# Run a single test +go test ./pkg/services/ -run TestMessageService + +# Generate Swagger docs (required after changing API annotations) +swag init --requiredByDefault --parseDependency --parseInternal + +# Pre-commit hooks run: go-fumpt, go-imports, go-lint, go-mod-tidy +``` + +### Web (Nuxt/Vue) + +```bash +cd web + +# Install dependencies +pnpm install + +# Development server (port 3000) +pnpm dev + +# Lint (eslint + stylelint + prettier) +pnpm lint + +# Auto-fix lint issues +pnpm lintfix + +# Run tests (Jest) +pnpm test + +# Static site generation (production build) +pnpm run generate + +# Regenerate TypeScript API models from Swagger +pnpm api:models +``` + +### Android (Kotlin) + +```bash +cd android + +# Build +./gradlew build + +# Debug APK +./gradlew assembleDebug + +# Release APK +./gradlew assembleRelease +``` + +### Docker (full stack) + +```bash +# Start all services (PostgreSQL, Redis, API, Web) +docker compose up --build +# API at localhost:8000, Web at localhost:3000 +``` + +## Architecture + +### API — Layered Architecture with Event-Driven Processing + +The API uses a **DI container** (`pkg/di/container.go`) that lazily initializes all services as singletons. The layered architecture flows as: + +**Handlers → Services → Repositories → GORM/PostgreSQL** + +- **Handlers** (`pkg/handlers/`) — Fiber HTTP handlers. Each has a `RegisterRoutes()` method and embeds a base `handler` struct with standardized response methods (`responseBadRequest`, `responseNotFound`, etc.). +- **Services** (`pkg/services/`) — Business logic. Orchestrate repositories and dispatch events. +- **Repositories** (`pkg/repositories/`) — Data access via GORM. Interfaces defined alongside GORM implementations (prefixed `gorm*`). +- **Validators** (`pkg/validators/`) — One validator per handler, return `url.Values` for field errors. +- **Entities** (`pkg/entities/`) — Domain models, auto-migrated by GORM. + +**Event system**: Uses CloudEvents spec (`cloudevents/sdk-go`). Events defined in `pkg/events/` (31 event types). Listeners in `pkg/listeners/` process events either synchronously or via Google Cloud Tasks queue (emulator mode for local dev). + +**Entry point**: `main.go` loads `.env` in local mode, creates the DI container, and starts Fiber on `APP_PORT`. + +### Web — Nuxt 2 Static SPA + +- **State management**: Single Vuex store (`store/index.ts`) — actions make API calls via Axios, mutations update state, getters expose computed values. +- **Components**: Use `vue-property-decorator` class syntax with `@Component`, `@Prop`, `@Watch` decorators. +- **API client**: Axios configured in `plugins/axios.ts` with Firebase bearer token auth and `x-api-key` header support. +- **API models**: TypeScript types in `models/` are auto-generated from the Swagger spec via `swagger-typescript-api`. +- **Auth**: Firebase Authentication (Email/Password, Google, GitHub) with `auth` and `guest` middleware for route guards. +- **Real-time**: Pusher.js for live message updates. + +### Android — Task-Oriented, Event-Driven + +- **No MVVM/Clean Architecture** — uses a flat package structure with Activities, Services, BroadcastReceivers, and WorkManager tasks. +- **FCM integration**: `MyFirebaseMessagingService` receives push notifications → schedules `SendSmsWorker` via WorkManager → fetches message from API → sends SMS. +- **Dual SIM support**: Independent settings per SIM via `Settings` singleton (SharedPreferences). +- **HTTP client**: OkHttp with `x-api-key` authentication against the API. +- **Encryption**: AES-256/CFB with SHA-256 key derivation (`Encrypter.kt`). + +## Key Conventions + +### API (Go) + +- **Error handling**: Use `github.com/palantir/stacktrace` — wrap errors with `stacktrace.Propagate(err, "context")` or `stacktrace.PropagateWithCode()`. Never return bare errors. +- **Database queries**: Always use GORM query builder with context propagation (`repository.db.WithContext(ctx)`). No raw SQL. +- **Route registration**: Each handler defines `RegisterRoutes()` called from the DI container. Routes follow REST conventions under `/v1/`. +- **Middleware chain**: HTTP Logger → OpenTelemetry → CORS → Request Logger → Bearer Auth → API Key Auth. +- **Observability**: All layers are instrumented with OpenTelemetry (Fiber, GORM, Redis). Pass `logger` and `tracer` to constructors. +- **Code formatting**: `go-fumpt` (not `gofmt`), enforced via pre-commit hooks. + +### Web (Vue/TypeScript) + +- **Formatting**: No semicolons, single quotes, 2-space indentation (Prettier + ESLint). +- **Component style**: Class-based with `vue-property-decorator`, not Options API (though some pages use `Vue.extend()`). +- **Store pattern**: Actions handle async API calls and commit mutations. Access store from components via `this.$store`. + +### Android (Kotlin) + +- **API calls**: Use `HttpSmsApiService` singleton (static `create()` factory). OkHttp client with `x-api-key` header. +- **Background work**: Use WorkManager for tasks that must survive process death. Direct `Thread { }` for lightweight background ops. +- **State**: `Settings` object (SharedPreferences singleton) for all persistent state. +- **Phone number formatting**: Use `libphonenumber` for E.164 format validation. diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml new file mode 100644 index 00000000..849f5ec8 --- /dev/null +++ b/.github/workflows/api.yml @@ -0,0 +1,126 @@ +name: api + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read + id-token: write + +jobs: + test: + name: Integration Tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: stable + + - name: Generate Firebase credentials + run: | + bash tests/generate-firebase-credentials.sh tests/firebase-credentials.json + echo "FIREBASE_CREDENTIALS=$(jq -c . tests/firebase-credentials.json)" >> $GITHUB_ENV + + - name: Start Services + working-directory: ./tests + run: docker compose up -d --build + + - name: Wait for services to be healthy + working-directory: ./tests + run: | + echo "Waiting for MongoDB to be healthy..." + for i in $(seq 1 20); do + if docker compose exec mongodb mongosh --eval "db.runCommand('ping').ok" --quiet >/dev/null 2>&1; then + echo "MongoDB is healthy!" + break + fi + if [ $i -eq 20 ]; then + echo "MongoDB failed to become healthy" + docker compose logs mongodb + exit 1 + fi + echo "MongoDB attempt $i/20 - waiting 3s..." + sleep 3 + done + + echo "Waiting for API to be healthy..." + for i in $(seq 1 40); do + if docker compose exec api curl -sf http://localhost:8000/health >/dev/null 2>&1; then + echo "API is healthy!" + break + fi + if [ $i -eq 40 ]; then + echo "API failed to become healthy" + docker compose logs api + exit 1 + fi + echo "Attempt $i/40 - waiting 5s..." + sleep 5 + done + + - name: Seed Database + working-directory: ./tests + run: | + echo "Waiting for seed container to finish..." + docker compose wait seed || true + sleep 2 + + - name: Run Integration Tests + working-directory: ./tests + run: go test -v -timeout 300s ./... + + - name: Collect Logs on Failure + if: failure() + working-directory: ./tests + run: | + docker compose logs --tail 200 + + - name: Stop Services + if: always() + working-directory: ./tests + run: docker compose down -v + + deploy: + name: Deploy + runs-on: ubuntu-latest + needs: test + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v3 + with: + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v3 + + - name: Trigger Cloud Build Deploy + run: | + BUILD_ID=$(gcloud builds triggers run api-httpsms-com \ + --region=global \ + --project=httpsms-86c51 \ + --sha=${{ github.sha }} \ + --format="value(metadata.build.id)") + echo -e "Cloud Build: \033[34mhttps://console.cloud.google.com/cloud-build/builds/$BUILD_ID?project=httpsms-86c51\033[0m" + echo "" + echo "Polling Cloud Build Status..." + while true; do + STATUS=$(gcloud builds describe "$BUILD_ID" --region=global --project=httpsms-86c51 --format="value(status)") + LOCAL_TIME=$(date -u '+%Y-%m-%d %H:%M:%S UTC') + echo -e " \033[90m${LOCAL_TIME}\033[0m status=\033[36m${STATUS}\033[0m" + case "$STATUS" in + SUCCESS) echo -e "\033[32mBuild succeeded!\033[0m"; exit 0 ;; + FAILURE|TIMEOUT|CANCELLED|EXPIRED|INTERNAL_ERROR) echo -e "\033[31mBuild failed with status: $STATUS\033[0m"; exit 1 ;; + esac + sleep 30 + done diff --git a/.github/workflows/ci.yml b/.github/workflows/web.yml similarity index 63% rename from .github/workflows/ci.yml rename to .github/workflows/web.yml index 69d3aff0..ba4fe8ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/web.yml @@ -1,36 +1,40 @@ -name: ci +name: web on: push: branches: - main + pull_request: + branches: + - main + +permissions: + contents: read + pull-requests: write + deployments: write defaults: run: working-directory: ./web jobs: - ci: + validate: + name: Validate runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest] - node: [16] + node: [20] steps: - name: Checkout 🛎 uses: actions/checkout@master - - uses: pnpm/action-setup@v4 + - uses: pnpm/action-setup@v6 name: Install pnpm with: - version: 9 - - - name: Install Node.js 20 - uses: actions/setup-node@v4 - with: - node-version: 20 + version: 10 - name: Install dependencies 📦 run: pnpm install @@ -41,8 +45,26 @@ jobs: - name: Run tests 🧪 run: pnpm test - - name: Debug 🐛 - run: echo GITHUB_SHA=${GITHUB_SHA} + - name: Build 🏗️ + run: mv .env.production .env && echo GITHUB_SHA=${GITHUB_SHA} >> .env && pnpm run generate + + deploy: + name: Deploy + needs: validate + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + + steps: + - name: Checkout 🛎 + uses: actions/checkout@master + + - uses: pnpm/action-setup@v6 + name: Install pnpm + with: + version: 10 + + - name: Install dependencies 📦 + run: pnpm install - name: Build 🏗️ run: mv .env.production .env && echo GITHUB_SHA=${GITHUB_SHA} >> .env && pnpm run generate diff --git a/.gitignore b/.gitignore index b114cdd0..0aa9dfff 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,11 @@ android/app/debug/ *main.exe* android/app/release/ + +tests/firebase-credentials.json +tests/emulator/emulator.exe +SECURITY_AUDIT_REPORT.md + +*.exe + +docs/ diff --git a/.mcp.json b/.mcp.json new file mode 100644 index 00000000..1bb33a71 --- /dev/null +++ b/.mcp.json @@ -0,0 +1,22 @@ +{ + "mcpServers": { + "playwright": { + "type": "stdio", + "command": "npx", + "args": [ + "-y", + "@modelcontextprotocol/server-playwright", + "--base-url", + "http://localhost:3000" + ], + "env": { + "BROWSER": "chromium" + } + }, + "context7": { + "type": "stdio", + "command": "npx", + "args": ["@upstash/context7-mcp@latest"] + } + } +} diff --git a/README.md b/README.md index 49c41f9a..14690530 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # httpSMS -[![Build](https://github.com/NdoleStudio/httpsms/actions/workflows/ci.yml/badge.svg)](https://github.com/NdoleStudio/httpsms/actions/workflows/ci.yml) +[![Web](https://github.com/NdoleStudio/httpsms/actions/workflows/web.yml/badge.svg)](https://github.com/NdoleStudio/httpsms/actions/workflows/web.yml) +[![API](https://github.com/NdoleStudio/httpsms/actions/workflows/api.yml/badge.svg)](https://github.com/NdoleStudio/httpsms/actions/workflows/api.yml) [![GitHub contributors](https://img.shields.io/github/contributors/NdoleStudio/httpsms)](https://github.com/NdoleStudio/httpsms/graphs/contributors) [![GitHub license](https://img.shields.io/github/license/NdoleStudio/httpsms?color=brightgreen)](https://github.com/NdoleStudio/httpsms/blob/master/LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md) @@ -37,11 +38,13 @@ Quick Start Guide 👉 [https://docs.httpsms.com](https://docs.httpsms.com) - [Self Host Setup - Docker](#self-host-setup---docker) - [1. Setup Firebase](#1-setup-firebase) - [2. Setup SMTP Email service](#2-setup-smtp-email-service) - - [3. Download the code](#3-download-the-code) - - [4. Setup the environment variables](#4-setup-the-environment-variables) - - [5. Build and Run](#5-build-and-run) - - [6. Create the System User](#6-create-the-system-user) - - [7. Build the Android App.](#7-build-the-android-app) + - [3. Setup Cloudflare Turnstile](#3-setup-cloudflare-turnstile) + - [4. Download the code](#4-download-the-code) + - [5. Setup the environment variables](#5-setup-the-environment-variables) + - [6. Build and Run](#6-build-and-run) + - [7. Create the System User](#7-create-the-system-user) + - [8. Build the Android App.](#8-build-the-android-app) +- [Integration Testing](#integration-testing) - [License](#license) @@ -164,7 +167,15 @@ const firebaseConfig = { The httpSMS application uses [SMTP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol) to send emails to users e.g. when your Android phone has been offline for a long period of time. You can use a service like [mailtrap](https://mailtrap.io/) to create an SMTP server for development purposes. -### 3. Download the code +### 3. Setup Cloudflare Turnstile + +The message search route (`/v1/messages/search`) is protected by a [Cloudflare Turnstile](https://developers.cloudflare.com/turnstile/get-started/) captcha to prevent abuse. You need to set up a Turnstile widget for the search messages feature to work. + +1. Go to the [Cloudflare dashboard](https://dash.cloudflare.com/) and navigate to **Turnstile**. +2. Add a new site and configure it for your self-hosted domain (e.g., `localhost` for local development). +3. Note down the **Site Key** and **Secret Key** — you will need them for the frontend and backend environment variables respectively. + +### 4. Download the code Clone the httpSMS GitHub repository @@ -172,12 +183,12 @@ Clone the httpSMS GitHub repository git clone https://github.com/NdoleStudio/httpsms.git ``` -### 4. Setup the environment variables +### 5. Setup the environment variables - Copy the `.env.docker` file in the `web` directory into `.env` ```bash -cp web/.env.local.docker web/.env.local +cp web/.env.docker web/.env ``` - Update the environment variables in the `.env` file in the `web` directory with your firebase web SDK configuration in step 1 above @@ -190,15 +201,18 @@ FIREBASE_STORAGE_BUCKET= FIREBASE_MESSAGING_SENDER_ID= FIREBASE_APP_ID= FIREBASE_MEASUREMENT_ID= + +# Cloudflare Turnstile site key from step 3 +CLOUDFLARE_TURNSTILE_SITE_KEY= ``` - Copy the `.env.docker` file in the `api` directory into `.env` ```bash -cp api/.env.local.docker api/.env.local +cp api/.env.docker api/.env ``` -- Update the environment variables in the `.env` file in the `api` directory with your firebase service account credentials and SMTP server details. +- Update the environment variables in the `.env` file in the `api` directory with your firebase service account credentials, SMTP server details, and Cloudflare Turnstile secret key. ```dotenv # SMTP email server settings @@ -212,11 +226,14 @@ FIREBASE_CREDENTIALS= # This is the `projectId` from your firebase web config GCP_PROJECT_ID= + +# Cloudflare Turnstile secret key from step 3 +CLOUDFLARE_TURNSTILE_SECRET_KEY= ``` - Don't bother about the `EVENTS_QUEUE_USER_API_KEY` and `EVENTS_QUEUE_USER_ID` settings. We will set that up later. -### 5. Build and Run +### 6. Build and Run - Build and run the API, the web UI, database and cache using the `docker-compose.yml` file. It takes a while for build and download all the docker images. When it's finished, you'll be able to access the web UI at http://localhost:3000 and the API at http://localhost:8000 @@ -225,15 +242,41 @@ GCP_PROJECT_ID= docker compose up --build ``` -### 6. Create the System User +### 7. Create the System User + +- The application uses the concept of a system user to process events async. You should manually create this user in `users` table in your database. Make sure you use the same `id` and `api_key` as the `EVENTS_QUEUE_USER_ID`, and `EVENTS_QUEUE_USER_API_KEY` in your `.env` file. -- The application uses the concept of a system user to process events async. You should manually create this user in `users` table in your database. - Make sure you use the same `id` and `api_key` as the `EVENTS_QUEUE_USER_ID`, and `EVENTS_QUEUE_USER_API_KEY` in your `.env` file + ```SQL + INSERT INTO users (id, api_key, email ) VALUES ('your-system-user-id', 'your-system-api-key', 'system@domain.com'); + ``` -### 7. Build the Android App. +> [!IMPORTANT] +> Restart your API docker container after modifying `EVENTS_QUEUE_USER_ID`, and `EVENTS_QUEUE_USER_API_KEY` in your `.env` file so that the httpSMS API can pick up the changes. + +### 8. Build the Android App. - Before building the Android app in [Android Studio](https://developer.android.com/studio), you need to replace the `google-services.json` file in the `android/app` directory with the file which you got from step 1. You need to do this for the firebase FCM messages to work properly. +## Integration Testing + +The project includes end-to-end integration tests that validate the complete SMS send/receive lifecycle. Tests run the full stack (API, PostgreSQL, Redis) in Docker alongside a phone emulator that simulates an Android device. + +📖 **Full documentation:** [`tests/README.md`](tests/README.md) + +**Quick run:** + +```bash +cd tests +bash generate-firebase-credentials.sh +export FIREBASE_CREDENTIALS=$(jq -c . firebase-credentials.json) +docker compose up -d --build --wait +docker compose wait seed && sleep 2 +go test -v -timeout 120s ./... +docker compose down -v +``` + +Integration tests also run automatically in CI on every push/PR to `main`. + ## License This project is licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - see the [LICENSE](LICENSE) file for details diff --git a/android/.gitignore b/android/.gitignore index aa724b77..6c13541c 100644 --- a/android/.gitignore +++ b/android/.gitignore @@ -12,4 +12,5 @@ /captures .externalNativeBuild .cxx +.kotlin/sessions/ local.properties diff --git a/android/app/build.gradle b/android/app/build.gradle deleted file mode 100644 index f49acb2b..00000000 --- a/android/app/build.gradle +++ /dev/null @@ -1,73 +0,0 @@ -plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' - id 'com.google.gms.google-services' - id "io.sentry.android.gradle" version "4.3.1" -} - -def getGitHash = { -> - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'rev-parse', '--short', 'HEAD' - standardOutput = stdout - } - return stdout.toString().trim() -} - -android { - compileSdk 35 - - defaultConfig { - applicationId "com.httpsms" - minSdk 28 - targetSdk 35 - versionCode 1 - versionName "${getGitHash()}" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - debug { - manifestPlaceholders["sentryEnvironment"] = "development" - } - release { - manifestPlaceholders["sentryEnvironment"] = "production" - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = '1.8' - } - namespace 'com.httpsms' - - buildFeatures { - buildConfig = true - } -} - -dependencies { - implementation platform('com.google.firebase:firebase-bom:33.13.0') - implementation 'com.journeyapps:zxing-android-embedded:4.3.0' - implementation 'com.google.firebase:firebase-analytics-ktx' - implementation 'com.google.firebase:firebase-messaging-ktx' - implementation 'com.squareup.okhttp3:okhttp:4.12.0' - implementation 'com.jakewharton.timber:timber:5.0.1' - implementation 'androidx.preference:preference-ktx:1.2.1' - implementation 'androidx.work:work-runtime-ktx:2.10.1' - implementation 'androidx.core:core-ktx:1.16.0' - implementation "androidx.cardview:cardview:1.0.0" - implementation 'com.beust:klaxon:5.6' - implementation 'androidx.appcompat:appcompat:1.7.0' - implementation 'org.apache.commons:commons-text:1.12.0' - implementation 'com.google.android.material:material:1.12.0' - implementation 'androidx.constraintlayout:constraintlayout:2.2.1' - implementation 'com.googlecode.libphonenumber:libphonenumber:9.0.4' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.2.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' -} diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts new file mode 100644 index 00000000..15857e70 --- /dev/null +++ b/android/app/build.gradle.kts @@ -0,0 +1,65 @@ +plugins { + id("com.android.application") + id("com.google.gms.google-services") + id("io.sentry.android.gradle") version "6.2.0" +} + +val gitHash = providers.exec { + commandLine("git", "rev-parse", "--short", "HEAD") +}.standardOutput.asText.map { it.trim() } + +android { + compileSdk = 36 + + defaultConfig { + applicationId = "com.httpsms" + minSdk = 28 + targetSdk = 36 + versionCode = 1 + versionName = gitHash.getOrElse("unknown") + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + getByName("debug") { + manifestPlaceholders["sentryEnvironment"] = "development" + } + getByName("release") { + manifestPlaceholders["sentryEnvironment"] = "production" + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + namespace = "com.httpsms" + + buildFeatures { + buildConfig = true + } +} + +dependencies { + implementation(platform("com.google.firebase:firebase-bom:34.11.0")) + implementation("com.journeyapps:zxing-android-embedded:4.3.0") + implementation("com.google.firebase:firebase-analytics") + implementation("com.google.firebase:firebase-messaging") + implementation("com.squareup.okhttp3:okhttp:5.3.2") + implementation("com.jakewharton.timber:timber:5.0.1") + implementation("androidx.preference:preference-ktx:1.2.1") + implementation("androidx.work:work-runtime-ktx:2.11.1") + implementation("androidx.core:core-ktx:1.18.0") + implementation("androidx.cardview:cardview:1.0.0") + implementation("com.beust:klaxon:5.6") + implementation("androidx.appcompat:appcompat:1.7.1") + implementation("org.apache.commons:commons-text:1.15.0") + implementation("com.google.android.material:material:1.13.0") + implementation("androidx.constraintlayout:constraintlayout:2.2.1") + implementation("com.googlecode.libphonenumber:libphonenumber:9.0.26") + implementation("com.klinkerapps:android-smsmms:5.2.6") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.3.0") + androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0") +} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6d704ade..86ca0a51 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + @@ -30,7 +31,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.HttpSMS" - tools:targetApi="31"> + tools:targetApi="36"> + android:name="com.journeyapps.barcodescanner.CaptureActivity" + android:screenOrientation="fullSensor" + tools:replace="screenOrientation" + tools:ignore="DiscouragedApi" /> + + + + @@ -90,6 +95,17 @@ + + + + + diff --git a/android/app/src/main/java/com/httpsms/Constants.kt b/android/app/src/main/java/com/httpsms/Constants.kt index fd8a0b90..ba3e1584 100644 --- a/android/app/src/main/java/com/httpsms/Constants.kt +++ b/android/app/src/main/java/com/httpsms/Constants.kt @@ -10,6 +10,7 @@ class Constants { const val KEY_MESSAGE_TIMESTAMP = "KEY_MESSAGE_TIMESTAMP" const val KEY_MESSAGE_REASON = "KEY_MESSAGE_REASON" const val KEY_MESSAGE_ENCRYPTED = "KEY_MESSAGE_ENCRYPTED" + const val KEY_MESSAGE_ATTACHMENTS = "KEY_MESSAGE_ATTACHMENTS" const val KEY_HEARTBEAT_ID = "KEY_HEARTBEAT_ID" @@ -18,5 +19,7 @@ class Constants { const val SIM2 = "SIM2" const val TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'000000'ZZZZZ" + + const val MAX_MMS_ATTACHMENT_SIZE: Long = (3L * 1024 * 1024) / 2 } } diff --git a/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt b/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt index 8f1e448c..e4113289 100644 --- a/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt +++ b/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt @@ -9,6 +9,15 @@ import com.google.firebase.messaging.RemoteMessage import com.httpsms.SentReceiver.FailedMessageWorker import timber.log.Timber +import com.google.android.mms.pdu_alt.CharacterSets +import com.google.android.mms.pdu_alt.EncodedStringValue +import com.google.android.mms.pdu_alt.PduBody +import com.google.android.mms.pdu_alt.PduComposer +import com.google.android.mms.pdu_alt.PduPart +import com.google.android.mms.pdu_alt.SendReq +import okhttp3.MediaType +import java.io.File + class MyFirebaseMessagingService : FirebaseMessagingService() { // [START receive_message] override fun onMessageReceived(remoteMessage: RemoteMessage) { @@ -158,6 +167,11 @@ class MyFirebaseMessagingService : FirebaseMessagingService() { } Receiver.register(applicationContext) + + if (message.attachments != null && message.attachments.isNotEmpty()) { + return handleMmsMessage(message) + } + val parts = getMessageParts(applicationContext, message) if (parts.size == 1) { return handleSingleMessage(message, parts.first()) @@ -165,6 +179,143 @@ class MyFirebaseMessagingService : FirebaseMessagingService() { return handleMultipartMessage(message, parts) } + fun extractFileName(url: String, prefix: String, mimeType: String? = null): String { + val fileName = url.substringAfterLast("/") + .substringBefore("?") + .takeIf { it.isNotBlank() && it.contains(".") } + ?: run { + val extension = mimeType?.let { mime -> + val ext = mime.substringAfterLast("/") + if (ext.isNotBlank()) ".$ext" else ".bin" + } ?: "" + "attachment$extension" + } + + return "${prefix}_$fileName" + } + + private fun handleMmsMessage(message: Message): Result { + Timber.d("Processing MMS for message ID [${message.id}]") + val apiService = HttpSmsApiService.create(applicationContext) + + val downloadedFiles = mutableListOf>() + + try { + for ((index, attachment) in message.attachments!!.withIndex()) { + val file = apiService.downloadAttachment(applicationContext, attachment, message.id, index) + if (file.first == null || file.second == null) { + handleFailed(applicationContext, message.id, "Failed to download attachment or file size exceeded 1.5MB.") + return Result.failure() + } + downloadedFiles.add(Pair(file.first!!, file.second!!)) + } + + val sendReq = SendReq() + + val encodedContact = EncodedStringValue(message.contact) + sendReq.to = arrayOf(encodedContact) + + val pduBody = PduBody() + + if (message.content.isNotEmpty()) { + val textPart = PduPart() + textPart.setCharset(CharacterSets.UTF_8) + textPart.contentType = "text/plain".toByteArray() + textPart.name = "text".toByteArray() + textPart.contentId = "text".toByteArray() + textPart.contentLocation = "text".toByteArray() + + var messageBody = message.content + val encryptionKey = Settings.getEncryptionKey(applicationContext) + if (message.encrypted && !encryptionKey.isNullOrEmpty()) { + messageBody = Encrypter.decrypt(encryptionKey, messageBody) + } + textPart.data = messageBody.toByteArray(Charsets.UTF_8) + + pduBody.addPart(textPart) + } + + for ((index, file) in downloadedFiles.withIndex()) { + val fileBytes = file.first.readBytes() + + val mediaPart = PduPart() + mediaPart.contentType = file.second.toString().toByteArray() + + + val fileName = extractFileName(message.attachments[index], index.toString(), file.second.toString()) + mediaPart.name = fileName.toByteArray() + mediaPart.contentId = fileName.toByteArray() + mediaPart.contentLocation = fileName.toByteArray() + mediaPart.data = fileBytes + + Timber.d("Adding MMS attachment with name [$fileName] and size [${fileBytes.size}] and type [${file.second}]") + + pduBody.addPart(mediaPart) + } + + sendReq.body = pduBody + + val pduComposer = PduComposer(applicationContext, sendReq) + val pduBytes = pduComposer.make() + + if (pduBytes == null) { + Timber.e("PduComposer failed to generate PDU byte array") + handleFailed(applicationContext, message.id, "Failed to compose MMS PDU.") + return Result.failure() + } + + val mmsDir = java.io.File(applicationContext.cacheDir, "mms_attachments") + if (!mmsDir.exists()) { + mmsDir.mkdirs() + } + + val pduFile = java.io.File(mmsDir, "pdu_${message.id}.dat") + java.io.FileOutputStream(pduFile).use { it.write(pduBytes) } + + val pduUri = androidx.core.content.FileProvider.getUriForFile( + applicationContext, + "${BuildConfig.APPLICATION_ID}.fileprovider", + pduFile + ) + + val sentIntent = createPendingIntent(message.id, SmsManagerService.sentAction()) + SmsManagerService().sendMultimediaMessage(applicationContext, pduUri, message.sim, sentIntent) + + Timber.d("Successfully dispatched MMS for message ID [${message.id}]") + return Result.success() + + } catch (e: Exception) { + Timber.e(e, "Failed to send MMS for message ID [${message.id}]") + handleFailed(applicationContext, message.id, e.message ?: "Internal error while building or sending MMS.") + return Result.failure() + } finally { + // Clean up any downloaded temporary files + downloadedFiles.forEach { file -> + if (file.first.exists()) { + file.first.delete() + } + } + + // Also clean up the MMS PDU file to avoid cache buildup in cases where + // sendMultimediaMessage fails before the sent broadcast is delivered. + try { + // The PDU file is stored under the "mms_attachments" cache subdirectory; + // delete it from the same location to ensure cleanup is effective. + val pduDir = File(applicationContext.cacheDir, "mms_attachments") + val pduFile = File(pduDir, "pdu_${message.id}.dat") + if (pduFile.exists()) { + val deleted = pduFile.delete() + if (!deleted) { + Timber.w("Failed to delete MMS PDU file for message ID [${message.id}] at [${pduFile.absolutePath}]") + } + } + } catch (cleanupException: Exception) { + // Best-effort cleanup; log but do not change the original result. + Timber.w(cleanupException, "Error while cleaning up MMS PDU file for message ID [${message.id}]") + } + } + } + private fun handleMultipartMessage(message:Message, parts: ArrayList): Result { Timber.d("sending multipart SMS for message with ID [${message.id}]") return try { diff --git a/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt b/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt index 3d813e13..51fa21cd 100644 --- a/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt +++ b/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt @@ -1,12 +1,18 @@ package com.httpsms import android.content.Context +import com.httpsms.Constants.Companion.MAX_MMS_ATTACHMENT_SIZE +import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody -import org.apache.commons.text.StringEscapeUtils import timber.log.Timber +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream import java.net.URI import java.net.URL import java.util.logging.Level @@ -68,17 +74,8 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) { return sendEvent(messageId, "FAILED", timestamp, reason) } - fun receive(sim: String, from: String, to: String, content: String, encrypted: Boolean, timestamp: String): Boolean { - val body = """ - { - "content": "${StringEscapeUtils.escapeJson(content)}", - "sim": "$sim", - "from": "$from", - "timestamp": "$timestamp", - "encrypted": $encrypted, - "to": "$to" - } - """.trimIndent() + fun receive(requestPayload: ReceivedMessageRequest): Boolean { + val body = com.beust.klaxon.Klaxon().toJsonString(requestPayload) val request: Request = Request.Builder() .url(resolveURL("/v1/messages/receive")) @@ -87,16 +84,21 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) { .header(clientVersionHeader, BuildConfig.VERSION_NAME) .build() - val response = client.newCall(request).execute() + val response = try { + client.newCall(request).execute() + } catch (e: Exception) { + Timber.e(e, "Exception while sending received message request") + return false + } + if (!response.isSuccessful) { - Timber.e("error response [${response.body?.string()}] with code [${response.code}] while receiving message [${body}]") + Timber.e("error response [${response.body?.string()}] with code [${response.code}] while receiving message") response.close() return response.code in 400..499 } - val message = ResponseMessage.fromJson(response.body!!.string()) response.close() - Timber.i("received message stored successfully for message with ID [${message?.data?.id}]" ) + Timber.i("received message stored successfully") return true } @@ -156,6 +158,65 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) { return true } + fun InputStream.copyToWithLimit( + out: OutputStream, + limit: Long, + bufferSize: Int = DEFAULT_BUFFER_SIZE + ): Long { + var bytesCopied: Long = 0 + val buffer = ByteArray(bufferSize) + var bytes = read(buffer) + + while (bytes >= 0) { + bytesCopied += bytes + + if (bytesCopied > limit) { + throw IOException("Download aborted: File exceeded maximum allowed size of $limit bytes.") + } + + out.write(buffer, 0, bytes) + bytes = read(buffer) + } + return bytesCopied + } + + fun downloadAttachment(context: Context, urlString: String, messageId: String, attachmentIndex: Int): Pair { + val request = Request.Builder().url(urlString).build() + + try { + client.newCall(request).execute().use { response -> + if (!response.isSuccessful) { + Timber.e("Failed to download attachment: ${response.code}") + return Pair(null, null) + } + + val body = response.body + val contentLength = body.contentLength() + if (contentLength > MAX_MMS_ATTACHMENT_SIZE) { + Timber.e("Attachment is too large ($contentLength bytes).") + return Pair(null, null) + } + + val mmsDir = File(context.cacheDir, "mms_attachments") + if (!mmsDir.exists()) { + mmsDir.mkdirs() + } + + val tempFile = File(mmsDir, "mms_${messageId}_$attachmentIndex") + val inputStream = body.byteStream() + FileOutputStream(tempFile).use { outputStream -> + inputStream.use { input -> + input.copyToWithLimit(outputStream, MAX_MMS_ATTACHMENT_SIZE) + } + } + + return Pair(tempFile, body.contentType()) + } + } catch (e: Exception) { + Timber.e(e, "Exception while download attachment") + return Pair(null, null) + } + } private fun sendEvent(messageId: String, event: String, timestamp: String, reason: String? = null): Boolean { var reasonString = "null" @@ -186,7 +247,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) { } if (!response.isSuccessful) { - Timber.e("error response [${response.body?.string()}] with code [${response.code}] while sending [${event}] event [${body}] for message with ID [${messageId}]") + Timber.e("error response [${response.body.string()}] with code [${response.code}] while sending [${event}] event [${body}] for message with ID [${messageId}]") response.close() return false } diff --git a/android/app/src/main/java/com/httpsms/MainActivity.kt b/android/app/src/main/java/com/httpsms/MainActivity.kt index 5f76ada8..363e7c19 100644 --- a/android/app/src/main/java/com/httpsms/MainActivity.kt +++ b/android/app/src/main/java/com/httpsms/MainActivity.kt @@ -6,6 +6,7 @@ import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent +import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.os.Bundle @@ -28,7 +29,6 @@ import com.google.android.material.card.MaterialCardView import com.google.android.material.progressindicator.LinearProgressIndicator import com.httpsms.services.StickyNotificationService import com.httpsms.worker.HeartbeatWorker -import okhttp3.internal.format import timber.log.Timber import java.time.Instant import java.time.ZoneId @@ -60,6 +60,7 @@ class MainActivity : AppCompatActivity() { scheduleHeartbeatWorker(this) setVersion() setHeartbeatListener(this) + setSmsPermissionListener() setBatteryOptimizationListener() } @@ -74,12 +75,13 @@ class MainActivity : AppCompatActivity() { redirectToLogin() refreshToken(this) setCardContent(this) + setSmsPermissionListener() setBatteryOptimizationListener() } private fun setVersion() { val appVersionView = findViewById(R.id.mainAppVersion) - appVersionView.text = format(getString(R.string.app_version), BuildConfig.VERSION_NAME) + appVersionView.text = getString(R.string.app_version, BuildConfig.VERSION_NAME) } private fun setCardContent(context: Context) { @@ -114,6 +116,7 @@ class MainActivity : AppCompatActivity() { Settings.setIncomingCallEventsEnabled(context, Constants.SIM2, false) } } + setSmsPermissionListener() } var permissions = arrayOf( @@ -283,8 +286,9 @@ class MainActivity : AppCompatActivity() { @SuppressLint("BatteryLife") private fun setBatteryOptimizationListener() { val pm = getSystemService(POWER_SERVICE) as PowerManager + val button = findViewById(R.id.batteryOptimizationButtonButton) if (!pm.isIgnoringBatteryOptimizations(packageName)) { - val button = findViewById(R.id.batteryOptimizationButtonButton) + button.visibility = View.VISIBLE button.setOnClickListener { val intent = Intent() intent.action = ProviderSettings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS @@ -292,8 +296,43 @@ class MainActivity : AppCompatActivity() { startActivity(intent) } } else { - val layout = findViewById(R.id.batteryOptimizationLinearLayout) + button.visibility = View.GONE + } + updatePermissionLayoutVisibility() + } + + private fun setSmsPermissionListener() { + val smsPermissions = arrayOf( + Manifest.permission.SEND_SMS, + Manifest.permission.RECEIVE_SMS, + Manifest.permission.READ_SMS + ) + val allGranted = smsPermissions.all { + checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED + } + + val button = findViewById(R.id.smsPermissionButton) + if (!allGranted) { + button.visibility = View.VISIBLE + button.setOnClickListener { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://httpsms.com/blog/grant-send-and-read-sms-permissions-on-android")) + startActivity(intent) + } + } else { + button.visibility = View.GONE + } + updatePermissionLayoutVisibility() + } + + private fun updatePermissionLayoutVisibility() { + val smsButton = findViewById(R.id.smsPermissionButton) + val batteryButton = findViewById(R.id.batteryOptimizationButtonButton) + val layout = findViewById(R.id.batteryOptimizationLinearLayout) + + if (smsButton.visibility == View.GONE && batteryButton.visibility == View.GONE) { layout.visibility = View.GONE + } else { + layout.visibility = View.VISIBLE } } diff --git a/android/app/src/main/java/com/httpsms/Models.kt b/android/app/src/main/java/com/httpsms/Models.kt index ccfe590b..b4bf5464 100644 --- a/android/app/src/main/java/com/httpsms/Models.kt +++ b/android/app/src/main/java/com/httpsms/Models.kt @@ -68,5 +68,24 @@ data class Message ( val type: String, @Json(name = "updated_at") - val updatedAt: String + val updatedAt: String, + + val attachments: List? = null +) + +data class ReceivedAttachment( + val name: String, + @Json(name = "content_type") + val contentType: String, + val content: String +) + +data class ReceivedMessageRequest( + val sim: String, + val from: String, + val to: String, + val content: String, + val encrypted: Boolean, + val timestamp: String, + val attachments: List? = null ) diff --git a/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt b/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt index 9d0f3d83..3edc30e2 100644 --- a/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt +++ b/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt @@ -4,7 +4,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.provider.Telephony -import androidx.work.BackoffPolicy +import android.util.Base64 import androidx.work.Constraints import androidx.work.Data import androidx.work.NetworkType @@ -13,20 +13,30 @@ import androidx.work.WorkManager import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf +import com.google.android.mms.pdu_alt.CharacterSets +import com.google.android.mms.pdu_alt.MultimediaMessagePdu +import com.google.android.mms.pdu_alt.PduParser +import com.google.android.mms.pdu_alt.RetrieveConf import timber.log.Timber +import java.io.File +import java.io.FileOutputStream import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.format.DateTimeFormatter -import java.util.concurrent.TimeUnit class ReceivedReceiver: BroadcastReceiver() { - override fun onReceive(context: Context,intent: Intent) { - if (intent.action != Telephony.Sms.Intents.SMS_RECEIVED_ACTION) { + override fun onReceive(context: Context, intent: Intent) { + if (intent.action == Telephony.Sms.Intents.SMS_RECEIVED_ACTION) { + handleSmsReceived(context, intent) + } else if (intent.action == Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION) { + handleMmsReceived(context, intent) + } else { Timber.e("received invalid intent with action [${intent.action}]") - return } + } + private fun handleSmsReceived(context: Context, intent: Intent) { var smsSender = "" var smsBody = "" @@ -35,12 +45,7 @@ class ReceivedReceiver: BroadcastReceiver() smsBody += smsMessage.messageBody } - var sim = Constants.SIM1 - var owner = Settings.getSIM1PhoneNumber(context) - if (intent.getIntExtra("android.telephony.extra.SLOT_INDEX", 0) > 0 && Settings.isDualSIM(context)) { - owner = Settings.getSIM2PhoneNumber(context) - sim = Constants.SIM2 - } + val (sim, owner) = getSimAndOwner(context, intent) if (!Settings.isIncomingMessageEnabled(context, sim)) { Timber.w("[${sim}] is not active for incoming messages") @@ -56,7 +61,71 @@ class ReceivedReceiver: BroadcastReceiver() ) } - private fun handleMessageReceived(context: Context, sim: String, from: String, to : String, content: String) { + private fun handleMmsReceived(context: Context, intent: Intent) { + val pushData = intent.getByteArrayExtra("data") ?: return + val pdu = PduParser(pushData, true).parse() ?: return + + if (pdu !is MultimediaMessagePdu) { + Timber.d("Received PDU is not a MultimediaMessagePdu, ignoring.") + return + } + + val from = pdu.from?.string ?: "" + var content = "" + val attachmentFiles = mutableListOf() + + // Check if it's a RetrieveConf (which contains the actual message body) + if (pdu is RetrieveConf) { + val body = pdu.body + if (body != null) { + for (i in 0 until body.partsNum) { + val part = body.getPart(i) + val partData = part.data ?: continue + val contentType = String(part.contentType ?: "application/octet-stream".toByteArray()) + + if (contentType.startsWith("text/plain")) { + content += String(partData, charset(CharacterSets.getMimeName(part.charset))) + } else { + // Save attachment to a temporary file + val fileName = String(part.name ?: part.contentLocation ?: part.contentId ?: "attachment_$i".toByteArray()) + val tempFile = File(context.cacheDir, "received_mms_${System.currentTimeMillis()}_$i") + FileOutputStream(tempFile).use { it.write(partData) } + attachmentFiles.add("${tempFile.absolutePath}|${contentType}|${fileName}") + } + } + } + } else { + Timber.d("Received PDU is of type [${pdu.javaClass.simpleName}], body extraction not implemented.") + } + + val (sim, owner) = getSimAndOwner(context, intent) + + if (!Settings.isIncomingMessageEnabled(context, sim)) { + Timber.w("[${sim}] is not active for incoming messages") + return + } + + handleMessageReceived( + context, + sim, + from, + owner, + content, + attachmentFiles.toTypedArray() + ) + } + + private fun getSimAndOwner(context: Context, intent: Intent): Pair { + var sim = Constants.SIM1 + var owner = Settings.getSIM1PhoneNumber(context) + if (intent.getIntExtra("android.telephony.extra.SLOT_INDEX", 0) > 0 && Settings.isDualSIM(context)) { + owner = Settings.getSIM2PhoneNumber(context) + sim = Constants.SIM2 + } + return Pair(sim, owner) + } + + private fun handleMessageReceived(context: Context, sim: String, from: String, to : String, content: String, attachments: Array? = null) { val timestamp = ZonedDateTime.now(ZoneOffset.UTC) if (!Settings.isLoggedIn(context)) { @@ -84,7 +153,8 @@ class ReceivedReceiver: BroadcastReceiver() Constants.KEY_MESSAGE_SIM to sim, Constants.KEY_MESSAGE_CONTENT to body, Constants.KEY_MESSAGE_ENCRYPTED to Settings.encryptReceivedMessages(context), - Constants.KEY_MESSAGE_TIMESTAMP to DateTimeFormatter.ofPattern(Constants.TIMESTAMP_PATTERN).format(timestamp).replace("+", "Z") + Constants.KEY_MESSAGE_TIMESTAMP to DateTimeFormatter.ofPattern(Constants.TIMESTAMP_PATTERN).format(timestamp).replace("+", "Z"), + Constants.KEY_MESSAGE_ATTACHMENTS to attachments ) val work = OneTimeWorkRequest @@ -104,14 +174,52 @@ class ReceivedReceiver: BroadcastReceiver() override fun doWork(): Result { Timber.i("[${this.inputData.getString(Constants.KEY_MESSAGE_SIM)}] forwarding received message from [${this.inputData.getString(Constants.KEY_MESSAGE_FROM)}] to [${this.inputData.getString(Constants.KEY_MESSAGE_TO)}]") - if (HttpSmsApiService.create(applicationContext).receive( - this.inputData.getString(Constants.KEY_MESSAGE_SIM)!!, - this.inputData.getString(Constants.KEY_MESSAGE_FROM)!!, - this.inputData.getString(Constants.KEY_MESSAGE_TO)!!, - this.inputData.getString(Constants.KEY_MESSAGE_CONTENT)!!, - this.inputData.getBoolean(Constants.KEY_MESSAGE_ENCRYPTED, false), - this.inputData.getString(Constants.KEY_MESSAGE_TIMESTAMP)!!, - )) { + val sim = this.inputData.getString(Constants.KEY_MESSAGE_SIM)!! + val from = this.inputData.getString(Constants.KEY_MESSAGE_FROM)!! + val to = this.inputData.getString(Constants.KEY_MESSAGE_TO)!! + val content = this.inputData.getString(Constants.KEY_MESSAGE_CONTENT)!! + val encrypted = this.inputData.getBoolean(Constants.KEY_MESSAGE_ENCRYPTED, false) + val timestamp = this.inputData.getString(Constants.KEY_MESSAGE_TIMESTAMP)!! + + val attachmentsData = inputData.getStringArray(Constants.KEY_MESSAGE_ATTACHMENTS) + val attachments = attachmentsData?.mapNotNull { + val parts = it.split("|") + val file = File(parts[0]) + if (file.exists()) { + val bytes = file.readBytes() + val base64Content = Base64.encodeToString(bytes, Base64.NO_WRAP) + ReceivedAttachment( + name = parts[2], + contentType = parts[1], + content = base64Content + ) + } else { + null + } + } + + val request = ReceivedMessageRequest( + sim = sim, + from = from, + to = to, + content = content, + encrypted = encrypted, + timestamp = timestamp, + attachments = attachments + ) + + val success = HttpSmsApiService.create(applicationContext).receive(request) + + // Cleanup temp files + attachmentsData?.forEach { + val path = it.split("|")[0] + val file = File(path) + if (file.exists()) { + file.delete() + } + } + + if (success) { return Result.success() } diff --git a/android/app/src/main/java/com/httpsms/SentReceiver.kt b/android/app/src/main/java/com/httpsms/SentReceiver.kt index 7995c35c..2b5bfd12 100644 --- a/android/app/src/main/java/com/httpsms/SentReceiver.kt +++ b/android/app/src/main/java/com/httpsms/SentReceiver.kt @@ -14,16 +14,40 @@ import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import timber.log.Timber +import java.io.File internal class SentReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { + val messageId = intent.getStringExtra(Constants.KEY_MESSAGE_ID) + cleanupPduFile(context, messageId) when (resultCode) { Activity.RESULT_OK -> handleMessageSent(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID)) SmsManager.RESULT_ERROR_GENERIC_FAILURE -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "GENERIC_FAILURE") SmsManager.RESULT_ERROR_NO_SERVICE -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "NO_SERVICE") SmsManager.RESULT_ERROR_NULL_PDU -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "NULL_PDU") SmsManager.RESULT_ERROR_RADIO_OFF -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "RADIO_OFF") - else -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "UNKNOWN") + SmsManager.RESULT_ERROR_LIMIT_EXCEEDED -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "LIMIT_EXCEEDED") + else -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "UNKNOWN:${resultCode}") + } + } + + private fun cleanupPduFile(context: Context, messageId: String?) { + if (messageId == null) return + + try { + val baseMessageId = messageId.substringBefore(".") + val mmsDir = File(context.cacheDir, "mms_attachments") + val pduFile = File(mmsDir, "pdu_$baseMessageId.dat") + + if (pduFile.exists()) { + if (pduFile.delete()) { + Timber.d("Cleaned up PDU file for message ID [$baseMessageId]") + } else { + Timber.w("Failed to delete PDU file for message ID [$baseMessageId]") + } + } + } catch (e: Exception) { + Timber.e(e, "Error cleaning up PDU file for message ID [$messageId]") } } diff --git a/android/app/src/main/java/com/httpsms/SmsManagerService.kt b/android/app/src/main/java/com/httpsms/SmsManagerService.kt index 17987b5c..c96a90a0 100644 --- a/android/app/src/main/java/com/httpsms/SmsManagerService.kt +++ b/android/app/src/main/java/com/httpsms/SmsManagerService.kt @@ -62,7 +62,7 @@ class SmsManagerService { } Timber.d("active subscription info size: [${localSubscriptionManager.activeSubscriptionInfoList!!.size}]") - val subscriptionId = if (sim == Constants.SIM1 && localSubscriptionManager.activeSubscriptionInfoList!!.size > 0) { + val subscriptionId = if (sim == Constants.SIM1 && localSubscriptionManager.activeSubscriptionInfoList!!.isNotEmpty()) { localSubscriptionManager.activeSubscriptionInfoList!![0].subscriptionId } else if (sim == Constants.SIM2 && localSubscriptionManager.activeSubscriptionInfoList!!.size > 1) { localSubscriptionManager.activeSubscriptionInfoList!![1].subscriptionId @@ -76,4 +76,10 @@ class SmsManagerService { context.getSystemService(SmsManager::class.java).createForSubscriptionId(subscriptionId) } } + + // Wrapper for the smsManager's sendMultimediaMessage + fun sendMultimediaMessage(context: Context, pduUri: android.net.Uri, sim: String, sentIntent: PendingIntent) { + val smsManager = getSmsManager(context, sim) + smsManager.sendMultimediaMessage(context, pduUri, null, null, sentIntent) + } } diff --git a/android/app/src/main/java/com/httpsms/worker/HeartbeatWorker.kt b/android/app/src/main/java/com/httpsms/worker/HeartbeatWorker.kt index ab83a3ec..174f2742 100644 --- a/android/app/src/main/java/com/httpsms/worker/HeartbeatWorker.kt +++ b/android/app/src/main/java/com/httpsms/worker/HeartbeatWorker.kt @@ -29,11 +29,16 @@ class HeartbeatWorker(appContext: Context, workerParams: WorkerParameters) : Wor return Result.success() } - HttpSmsApiService.create(applicationContext).storeHeartbeat(phoneNumbers.toTypedArray(), Settings.isCharging(applicationContext)) - Timber.d("finished sending heartbeats to server") + try{ + HttpSmsApiService.create(applicationContext).storeHeartbeat(phoneNumbers.toTypedArray(), Settings.isCharging(applicationContext)) + Timber.d("finished sending heartbeats to server") - Settings.setHeartbeatTimestampAsync(applicationContext, System.currentTimeMillis()) - Timber.d("Set the heartbeat timestamp") + Settings.setHeartbeatTimestampAsync(applicationContext, System.currentTimeMillis()) + Timber.d("Set the heartbeat timestamp") + } catch (exception: Exception) { + Timber.e(exception, "Failed to send [${phoneNumbers.joinToString()}] heartbeats to server") + return Result.failure() + } return Result.success() } diff --git a/android/app/src/main/res/drawable/open_in_new_24.xml b/android/app/src/main/res/drawable/open_in_new_24.xml new file mode 100644 index 00000000..b257c344 --- /dev/null +++ b/android/app/src/main/res/drawable/open_in_new_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/android/app/src/main/res/layout/activity_login.xml b/android/app/src/main/res/layout/activity_login.xml index cfd86db6..03552be5 100644 --- a/android/app/src/main/res/layout/activity_login.xml +++ b/android/app/src/main/res/layout/activity_login.xml @@ -1,174 +1,188 @@ - - - - - - - + + - - + + + + - - + android:layout_marginTop="32dp" + android:layout_marginBottom="24dp" + android:autoLink="web" + android:lineHeight="28sp" + android:text="@string/get_your_api_key" + android:textAlignment="center" + android:textSize="20sp" + app:layout_constraintBottom_toTopOf="@+id/loginApiKeyTextInputLayout" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/imageView" + app:layout_constraintVertical_bias="0" + app:layout_constraintVertical_chainStyle="packed" /> - - - + android:hint="@string/text_area_api_key" + app:errorEnabled="true" + app:endIconMode="custom" + app:endIconDrawable="@android:drawable/ic_menu_camera" + app:endIconContentDescription="cameraButton" + app:layout_constraintBottom_toTopOf="@+id/loginPhoneNumberLayoutSIM1" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView"> - + - - - + + + android:layout_marginTop="8dp" + android:hint="@string/login_phone_number_sim1" + app:errorEnabled="true" + app:placeholderText="@string/login_phone_number_hint" + app:layout_constraintBottom_toTopOf="@+id/loginPhoneNumberLayoutSIM2" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/loginApiKeyTextInputLayout"> - + + + - + app:placeholderText="@string/login_phone_number_hint" + app:layout_constraintBottom_toTopOf="@+id/loginServerUrlLayoutContainer" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/loginPhoneNumberLayoutSIM1"> - - - - - - + + + + + + + + - - - + android:layout_marginTop="16dp" + android:orientation="vertical" + android:gravity="center" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/loginServerUrlLayoutContainer"> + + + + + + + + diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index d04b9150..75849475 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -3,9 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:paddingLeft="16dp" - android:paddingRight="16dp" android:layout_height="match_parent" + android:fitsSystemWindows="true" tools:context=".MainActivity"> - - @@ -46,8 +37,6 @@ android:orientation="vertical" android:padding="16dp"> - - - @@ -96,8 +86,6 @@ android:orientation="vertical" android:padding="16dp"> - - - + + + app:indicatorColor="@color/pink_500" /> + + + android:layout_height="match_parent" + android:fitsSystemWindows="true"> @@ -30,8 +27,10 @@ + android:layout_height="0dp" + android:fillViewport="true" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@+id/settings_app_bar_layout"> + android:paddingRight="16dp"> #121212 - true + false diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 24e9609d..02dfa1b6 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -7,7 +7,7 @@ Login With API Key API Key HTTP Sms Logo - Open\nhttpsms.com/settings\nto get your API key + Get Your API Key at\nhttpsms.com/settings Log Out e.g +18005550199 (international format) e.g https://api.httpsms.com @@ -17,6 +17,7 @@ https://api.httpsms.com httpsms.com - %s Disable Battery Optimization + Enable SMS Permission App Settings SIM1 SIM2 diff --git a/android/app/src/main/res/values/themes.xml b/android/app/src/main/res/values/themes.xml index 538ca49c..5914accc 100644 --- a/android/app/src/main/res/values/themes.xml +++ b/android/app/src/main/res/values/themes.xml @@ -13,7 +13,7 @@ #121212 - true + false diff --git a/android/app/src/main/res/xml/file_paths.xml b/android/app/src/main/res/xml/file_paths.xml new file mode 100644 index 00000000..0df3af41 --- /dev/null +++ b/android/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle deleted file mode 100644 index e29386c3..00000000 --- a/android/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - ext { - kotlin_version = '2.1.0' - } - repositories { - // Check that you have the following line (if not, add it): - google() - mavenCentral() // Google's Maven repository - - } - dependencies { - // Add this line - classpath 'com.google.gms:google-services:4.4.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -plugins { - id 'com.android.application' version '8.9.2' apply false - id 'com.android.library' version '8.9.2' apply false - id 'org.jetbrains.kotlin.android' version '1.6.21' apply false -} - -tasks.register('clean', Delete) { - delete rootProject.buildDir -} diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 00000000..ee8d1b8d --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1,19 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.google.gms:google-services:4.4.2") + } +} + +plugins { + id("com.android.application") version "9.2.1" apply false + id("com.android.library") version "9.2.1" apply false +} + +tasks.register("clean") { + delete(rootProject.layout.buildDirectory) +} diff --git a/android/gradle.properties b/android/gradle.properties index cf0008dd..1f124546 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -22,3 +22,11 @@ kotlin.code.style=official # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true android.nonFinalResIds=false +android.defaults.buildfeatures.resvalues=true +android.sdk.defaultTargetSdkToCompileSdkIfUnset=false +android.enableAppCompileTimeRClass=false +android.usesSdkInManifest.disallowed=false +android.uniquePackageNames=false +android.dependency.useConstraints=true +android.r8.strictFullModeForKeepRules=false +android.r8.optimizedResourceShrinking=false diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index f40abbca..ff340ba9 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Thu Jun 23 15:32:32 EEST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/android/settings.gradle b/android/settings.gradle.kts similarity index 95% rename from android/settings.gradle rename to android/settings.gradle.kts index baf72e29..75be430a 100644 --- a/android/settings.gradle +++ b/android/settings.gradle.kts @@ -13,4 +13,4 @@ dependencyResolutionManagement { } } rootProject.name = "httpSMS" -include ':app' +include(":app") diff --git a/api/.air.toml b/api/.air.toml deleted file mode 100644 index 15d45a05..00000000 --- a/api/.air.toml +++ /dev/null @@ -1,36 +0,0 @@ -root = "." -testdata_dir = "testdata" -tmp_dir = "tmp" - -[build] - bin = "tmp\\main.exe" - cmd = "go build -o ./tmp/main.exe ." - delay = 1000 - exclude_dir = ["assets", "tmp", "vendor", "testdata"] - exclude_file = [] - exclude_regex = ["_test.go"] - exclude_unchanged = false - follow_symlink = false - full_bin = "" - include_dir = [] - include_ext = ["go", "tpl", "tmpl", "html"] - kill_delay = "0s" - log = "build-errors.log" - send_interrupt = false - stop_on_error = true - -[color] - app = "" - build = "yellow" - main = "magenta" - runner = "green" - watcher = "cyan" - -[log] - time = false - -[misc] - clean_on_exit = false - -[screen] - clear_on_rebuild = false diff --git a/api/.env.docker b/api/.env.docker index 9dc43fdb..cf8f8cda 100644 --- a/api/.env.docker +++ b/api/.env.docker @@ -5,6 +5,10 @@ GCP_PROJECT_ID=httpsms-docker USE_HTTP_LOGGER=true +# Set to "true" to enable feature entitlement checks (limits for free users). +# Defaults to "false" for self-hosted deployments (no limits). +ENTITLEMENT_ENABLED=false + EVENTS_QUEUE_TYPE=emulator EVENTS_QUEUE_NAME=events-local EVENTS_QUEUE_ENDPOINT=http://localhost:8000/v1/events @@ -48,6 +52,9 @@ DATABASE_URL_DEDICATED=postgresql://dbusername:dbpassword@postgres:5432/httpsms # Redis connection string REDIS_URL=redis://@redis:6379 +# Google Cloud Storage bucket for MMS attachments. Leave empty to use in-memory storage. +GCS_BUCKET_NAME= + # [optional] If you would like to use uptrace.dev for distributed tracing, you can set the DSN here. # This is optional and you can leave it empty if you don't want to use uptrace UPTRACE_DSN= @@ -58,3 +65,7 @@ PUSHER_APP_ID= PUSHER_KEY= PUSHER_SECRET= PUSHER_CLUSTER= + +# Cloudflare Turnstile secret key for validating captcha tokens on the /v1/messages/search route +# Get your secret key at https://developers.cloudflare.com/turnstile/get-started/ +CLOUDFLARE_TURNSTILE_SECRET_KEY= diff --git a/api/Dockerfile b/api/Dockerfile index 34d82403..6e6423b1 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,4 +1,4 @@ -FROM golang as builder +FROM golang AS builder ARG GIT_COMMIT ENV GIT_COMMIT=$GIT_COMMIT @@ -21,7 +21,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=$GI FROM alpine:latest -RUN addgroup -S http-sms && adduser -S http-sms -G http-sms +RUN apk add --no-cache curl && addgroup -S http-sms && adduser -S http-sms -G http-sms USER http-sms WORKDIR /home/http-sms diff --git a/api/cmd/fcm/main.go b/api/cmd/fcm/main.go index 4906142b..470397cf 100644 --- a/api/cmd/fcm/main.go +++ b/api/cmd/fcm/main.go @@ -18,7 +18,7 @@ func main() { } container := di.NewContainer(os.Getenv("GCP_PROJECT_ID"), "") - client := container.FirebaseMessagingClient() + client := container.FCMClient() result, err := client.Send(context.Background(), &messaging.Message{ Data: map[string]string{ diff --git a/api/docs/docs.go b/api/docs/docs.go index 908d34c3..dadff723 100644 --- a/api/docs/docs.go +++ b/api/docs/docs.go @@ -1,5 +1,4 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Package docs Code generated by swaggo/swag. DO NOT EDIT package docs import "github.com/swaggo/swag" @@ -11,7 +10,7 @@ const docTemplate = `{ "description": "{{escape .Description}}", "title": "{{.Title}}", "contact": { - "name": "HTTP SMS", + "name": "support@httpsms.com", "email": "support@httpsms.com" }, "license": { @@ -145,13 +144,13 @@ const docTemplate = `{ } }, "/bulk-messages": { - "post": { + "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Sends bulk SMS messages to multiple users from a CSV file.", + "description": "Fetches the last 10 bulk message order summaries for the authenticated user showing counts per status.", "consumes": [ "application/json" ], @@ -161,7 +160,54 @@ const docTemplate = `{ "tags": [ "BulkSMS" ], + "summary": "List bulk message orders", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.BulkMessagesResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Sends bulk SMS messages to multiple users based on our [CSV template](https://httpsms.com/templates/httpsms-bulk.csv) or our [Excel template](https://httpsms.com/templates/httpsms-bulk.xlsx).", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "BulkSMS" + ], "summary": "Store bulk SMS file", + "parameters": [ + { + "type": "file", + "description": "The Excel or CSV file containing the messages to be sent.", + "name": "document", + "in": "formData", + "required": true + } + ], "responses": { "202": { "description": "Accepted", @@ -701,53 +747,6 @@ const docTemplate = `{ } } }, - "/lemonsqueezy/event": { - "post": { - "description": "Publish a lemonsqueezy event to the registered listeners", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Lemonsqueezy" - ], - "summary": "Consume a lemonsqueezy event", - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, "/message-threads": { "get": { "security": [ @@ -1410,7 +1409,7 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "Add a new SMS message to be sent by the android phone", + "description": "Add a new SMS message to be sent by your Android phone", "consumes": [ "application/json" ], @@ -1420,10 +1419,10 @@ const docTemplate = `{ "tags": [ "Messages" ], - "summary": "Send a new SMS message", + "summary": "Send an SMS message", "parameters": [ { - "description": "PostSend message request payload", + "description": "Send message request payload", "name": "payload", "in": "body", "required": true, @@ -1467,6 +1466,72 @@ const docTemplate = `{ } }, "/messages/{messageID}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get a message from the database by the message ID.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Get a message from the database.", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the message", + "name": "messageID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, "delete": { "security": [ { @@ -1732,6 +1797,12 @@ const docTemplate = `{ "$ref": "#/definitions/responses.Unauthorized" } }, + "402": { + "description": "Payment Required", + "schema": { + "$ref": "#/definitions/responses.PaymentRequired" + } + }, "422": { "description": "Unprocessable Entity", "schema": { @@ -2152,35 +2223,26 @@ const docTemplate = `{ } } }, - "/users/me": { + "/send-schedules": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Get details of the currently authenticated user", - "consumes": [ - "application/json" - ], + "description": "List all send schedules owned by the authenticated user.", "produces": [ "application/json" ], "tags": [ - "Users" + "SendSchedules" ], - "summary": "Get current user", + "summary": "List send schedules", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/responses.UserResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" + "$ref": "#/definitions/responses.MessageSendSchedulesResponse" } }, "401": { @@ -2189,12 +2251,6 @@ const docTemplate = `{ "$ref": "#/definitions/responses.Unauthorized" } }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -2203,13 +2259,13 @@ const docTemplate = `{ } } }, - "put": { + "post": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Updates the details of the currently authenticated user", + "description": "Create a new send schedule for the authenticated user.", "consumes": [ "application/json" ], @@ -2217,25 +2273,25 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Users" + "SendSchedules" ], - "summary": "Update a user", + "summary": "Create send schedule", "parameters": [ { - "description": "Payload of user details to update", + "description": "Payload of new send schedule.", "name": "payload", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/requests.UserUpdate" + "$ref": "#/definitions/requests.MessageSendScheduleStore" } } ], "responses": { - "200": { - "description": "OK", + "201": { + "description": "Created", "schema": { - "$ref": "#/definitions/responses.PhoneResponse" + "$ref": "#/definitions/responses.MessageSendScheduleResponse" } }, "400": { @@ -2250,6 +2306,12 @@ const docTemplate = `{ "$ref": "#/definitions/responses.Unauthorized" } }, + "402": { + "description": "Payment Required", + "schema": { + "$ref": "#/definitions/responses.PaymentRequired" + } + }, "422": { "description": "Unprocessable Entity", "schema": { @@ -2263,14 +2325,16 @@ const docTemplate = `{ } } } - }, - "delete": { + } + }, + "/send-schedules/{scheduleID}": { + "put": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Deletes the currently authenticated user together with all their data.", + "description": "Update a send schedule owned by the authenticated user.", "consumes": [ "application/json" ], @@ -2278,51 +2342,32 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Users" + "SendSchedules" ], - "summary": "Delete a user", - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } + "summary": "Update send schedule", + "parameters": [ + { + "type": "string", + "description": "Schedule ID", + "name": "scheduleID", + "in": "path", + "required": true }, - "500": { - "description": "Internal Server Error", + { + "description": "Payload of updated send schedule.", + "name": "payload", + "in": "body", + "required": true, "schema": { - "$ref": "#/definitions/responses.InternalServerError" + "$ref": "#/definitions/requests.MessageSendScheduleStore" } } - } - } - }, - "/users/subscription": { - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Cancel the subscription of the authenticated user.", - "produces": [ - "application/json" - ], - "tags": [ - "Users" ], - "summary": "Cancel the user's subscription", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/responses.NoContent" + "$ref": "#/definitions/responses.MessageSendScheduleResponse" } }, "400": { @@ -2337,6 +2382,12 @@ const docTemplate = `{ "$ref": "#/definitions/responses.Unauthorized" } }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, "422": { "description": "Unprocessable Entity", "schema": { @@ -2350,28 +2401,403 @@ const docTemplate = `{ } } } - } - }, - "/users/subscription-update-url": { - "get": { + }, + "delete": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Fetches the subscription URL of the authenticated user.", + "description": "Delete a send schedule owned by the authenticated user.", "produces": [ "application/json" ], "tags": [ - "Users" + "SendSchedules" ], - "summary": "Currently authenticated user subscription update URL", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.OkString" + "summary": "Delete send schedule", + "parameters": [ + { + "type": "string", + "description": "Schedule ID", + "name": "scheduleID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/me": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get details of the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Get current user", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.UserResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Updates the details of the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Update a user", + "parameters": [ + { + "description": "Payload of user details to update", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.UserUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhoneResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Deletes the currently authenticated user together with all their data.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Delete a user", + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Cancel the subscription of the authenticated user.", + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Cancel the user's subscription", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription-update-url": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Fetches the subscription URL of the authenticated user.", + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Currently authenticated user subscription update URL", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.OkString" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription/invoices/{subscriptionInvoiceID}": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Generates a new invoice PDF file for the given subscription payment with given parameters.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/pdf" + ], + "tags": [ + "Users" + ], + "summary": "Generate a subscription payment invoice", + "parameters": [ + { + "description": "Generate subscription payment invoice parameters", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.UserPaymentInvoice" + } + }, + { + "type": "string", + "description": "ID of the subscription invoice to generate the PDF for", + "name": "subscriptionInvoiceID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "file" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription/payments": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Subscription payments are generated throughout the lifecycle of a subscription, typically there is one at the time of purchase and then one for each renewal.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Get the last 10 subscription payments.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.UserSubscriptionPaymentsResponse" } }, "400": { @@ -2534,6 +2960,68 @@ const docTemplate = `{ } } }, + "/v1/attachments/{userID}/{messageID}/{attachmentIndex}/{filename}": { + "get": { + "description": "Download an MMS attachment by its path components", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Attachments" + ], + "summary": "Download a message attachment", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "userID", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Message ID", + "name": "messageID", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Attachment index", + "name": "attachmentIndex", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Filename with extension", + "name": "filename", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "file" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, "/webhooks": { "get": { "security": [ @@ -2855,6 +3343,53 @@ const docTemplate = `{ } } }, + "entities.BulkMessage": { + "type": "object", + "required": [ + "created_at", + "delivered_count", + "failed_count", + "pending_count", + "request_id", + "scheduled_count", + "sent_count", + "total" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "delivered_count": { + "type": "integer", + "example": 25 + }, + "failed_count": { + "type": "integer", + "example": 5 + }, + "pending_count": { + "type": "integer", + "example": 30 + }, + "request_id": { + "type": "string", + "example": "bulk-32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "scheduled_count": { + "type": "integer", + "example": 50 + }, + "sent_count": { + "type": "integer", + "example": 40 + }, + "total": { + "type": "integer", + "example": 150 + } + } + }, "entities.Discord": { "type": "object", "required": [ @@ -2937,28 +3472,17 @@ const docTemplate = `{ "entities.Message": { "type": "object", "required": [ - "can_be_polled", + "attachments", "contact", "content", "created_at", - "delivered_at", "encrypted", - "expired_at", - "failed_at", - "failure_reason", "id", - "last_attempted_at", "max_send_attempts", "order_timestamp", "owner", - "received_at", - "request_id", "request_received_at", - "scheduled_at", - "scheduled_send_time", "send_attempt_count", - "send_time", - "sent_at", "sim", "status", "type", @@ -2966,9 +3490,15 @@ const docTemplate = `{ "user_id" ], "properties": { - "can_be_polled": { - "type": "boolean", - "example": false + "attachments": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "https://example.com/image.jpg", + "https://example.com/video.mp4" + ] }, "contact": { "type": "string", @@ -3051,22 +3581,64 @@ const docTemplate = `{ "type": "integer", "example": 133414 }, - "sent_at": { + "sent_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "sim": { + "description": "SIM is the SIM card to use to send the message\n* SMS1: use the SIM card in slot 1\n* SMS2: use the SIM card in slot 2\n* DEFAULT: used the default communication SIM card", + "allOf": [ + { + "$ref": "#/definitions/entities.SIM" + } + ], + "example": "DEFAULT" + }, + "status": { + "type": "string", + "example": "pending" + }, + "type": { + "type": "string", + "example": "mobile-terminated" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + }, + "user_id": { "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "entities.MessageSendSchedule": { + "type": "object", + "required": [ + "created_at", + "id", + "name", + "timezone", + "updated_at", + "user_id", + "windows" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" }, - "sim": { - "description": "SIM is the SIM card to use to send the message\n* SMS1: use the SIM card in slot 1\n* SMS2: use the SIM card in slot 2\n* DEFAULT: used the default communication SIM card", + "id": { "type": "string", - "example": "DEFAULT" + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" }, - "status": { + "name": { "type": "string", - "example": "pending" + "example": "Business Hours" }, - "type": { + "timezone": { "type": "string", - "example": "mobile-terminated" + "example": "Europe/Tallinn" }, "updated_at": { "type": "string", @@ -3075,6 +3647,34 @@ const docTemplate = `{ "user_id": { "type": "string", "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + }, + "windows": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.MessageSendScheduleWindow" + } + } + } + }, + "entities.MessageSendScheduleWindow": { + "type": "object", + "required": [ + "day_of_week", + "end_minute", + "start_minute" + ], + "properties": { + "day_of_week": { + "type": "integer", + "example": 1 + }, + "end_minute": { + "type": "integer", + "example": 1020 + }, + "start_minute": { + "type": "integer", + "example": 540 } } }, @@ -3149,12 +3749,10 @@ const docTemplate = `{ "type": "object", "required": [ "created_at", - "fcm_token", "id", "max_send_attempts", "message_expiration_seconds", "messages_per_minute", - "missed_call_auto_reply", "phone_number", "sim", "updated_at", @@ -3182,6 +3780,10 @@ const docTemplate = `{ "description": "MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired.", "type": "integer" }, + "message_send_schedule_id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, "messages_per_minute": { "type": "integer", "example": 1 @@ -3195,8 +3797,7 @@ const docTemplate = `{ "example": "+18005550199" }, "sim": { - "description": "SIM card that received the message", - "type": "string" + "$ref": "#/definitions/entities.SIM" }, "updated_at": { "type": "string", @@ -3272,10 +3873,49 @@ const docTemplate = `{ } } }, + "entities.SIM": { + "type": "string", + "enum": [ + "SIM1", + "SIM2" + ], + "x-enum-varnames": [ + "SIM1", + "SIM2" + ] + }, + "entities.SubscriptionName": { + "type": "string", + "enum": [ + "free", + "pro-monthly", + "pro-yearly", + "ultra-monthly", + "ultra-yearly", + "pro-lifetime", + "20k-monthly", + "100k-monthly", + "50k-monthly", + "200k-monthly", + "20k-yearly" + ], + "x-enum-varnames": [ + "SubscriptionNameFree", + "SubscriptionNameProMonthly", + "SubscriptionNameProYearly", + "SubscriptionNameUltraMonthly", + "SubscriptionNameUltraYearly", + "SubscriptionNameProLifetime", + "SubscriptionName20KMonthly", + "SubscriptionName100KMonthly", + "SubscriptionName50KMonthly", + "SubscriptionName200KMonthly", + "SubscriptionName20KYearly" + ] + }, "entities.User": { "type": "object", "required": [ - "active_phone_id", "api_key", "created_at", "email", @@ -3284,11 +3924,8 @@ const docTemplate = `{ "notification_message_status_enabled", "notification_newsletter_enabled", "notification_webhook_enabled", - "subscription_ends_at", "subscription_id", "subscription_name", - "subscription_renews_at", - "subscription_status", "timezone", "updated_at" ], @@ -3338,7 +3975,11 @@ const docTemplate = `{ "example": "8f9c71b8-b84e-4417-8408-a62274f65a08" }, "subscription_name": { - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/entities.SubscriptionName" + } + ], "example": "free" }, "subscription_renews_at": { @@ -3473,15 +4114,46 @@ const docTemplate = `{ } } }, + "requests.MessageAttachment": { + "type": "object", + "required": [ + "content", + "content_type", + "name" + ], + "properties": { + "content": { + "description": "Content is the base64-encoded attachment data", + "type": "string", + "example": "base64data..." + }, + "content_type": { + "description": "ContentType is the MIME type of the attachment", + "type": "string", + "example": "image/jpeg" + }, + "name": { + "description": "Name is the original filename of the attachment", + "type": "string", + "example": "photo.jpg" + } + } + }, "requests.MessageBulkSend": { "type": "object", "required": [ "content", - "encrypted", "from", "to" ], "properties": { + "attachments": { + "description": "Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS", + "type": "array", + "items": { + "type": "string" + } + }, "content": { "type": "string", "example": "This is a sample text message" @@ -3574,6 +4246,13 @@ const docTemplate = `{ "to" ], "properties": { + "attachments": { + "description": "Attachments is the list of MMS attachments received with the message", + "type": "array", + "items": { + "$ref": "#/definitions/requests.MessageAttachment" + } + }, "content": { "type": "string", "example": "This is a sample text message received on a phone" @@ -3589,7 +4268,11 @@ const docTemplate = `{ }, "sim": { "description": "SIM card that received the message", - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/entities.SIM" + } + ], "example": "SIM1" }, "timestamp": { @@ -3611,6 +4294,17 @@ const docTemplate = `{ "to" ], "properties": { + "attachments": { + "description": "Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS", + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "https://example.com/image.jpg", + "https://example.com/video.mp4" + ] + }, "content": { "type": "string", "example": "This is a sample text message" @@ -3630,9 +4324,9 @@ const docTemplate = `{ "example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4" }, "send_at": { - "description": "SendAt is an optional parameter used to schedule a message to be sent at a later time", + "description": "SendAt is an optional parameter used to schedule a message to be sent in the future. The time is considered to be in your profile's local timezone and you can queue messages for up to 20 days (480 hours) in the future.", "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" + "example": "2025-12-19T16:39:57-08:00" }, "to": { "type": "string", @@ -3640,6 +4334,47 @@ const docTemplate = `{ } } }, + "requests.MessageSendScheduleStore": { + "type": "object", + "required": [ + "name", + "timezone", + "windows" + ], + "properties": { + "name": { + "type": "string" + }, + "timezone": { + "type": "string" + }, + "windows": { + "type": "array", + "items": { + "$ref": "#/definitions/requests.MessageSendScheduleWindow" + } + } + } + }, + "requests.MessageSendScheduleWindow": { + "type": "object", + "required": [ + "day_of_week", + "end_minute", + "start_minute" + ], + "properties": { + "day_of_week": { + "type": "integer" + }, + "end_minute": { + "type": "integer" + }, + "start_minute": { + "type": "integer" + } + } + }, "requests.MessageThreadUpdate": { "type": "object", "required": [ @@ -3713,6 +4448,10 @@ const docTemplate = `{ "type": "integer", "example": 12345 }, + "message_send_schedule_id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, "messages_per_minute": { "type": "integer", "example": 1 @@ -3759,6 +4498,48 @@ const docTemplate = `{ } } }, + "requests.UserPaymentInvoice": { + "type": "object", + "required": [ + "address", + "city", + "country", + "name", + "notes", + "state", + "zip_code" + ], + "properties": { + "address": { + "type": "string", + "example": "221B Baker Street, London" + }, + "city": { + "type": "string", + "example": "Los Angeles" + }, + "country": { + "type": "string", + "example": "US" + }, + "name": { + "type": "string", + "example": "Acme Corp" + }, + "notes": { + "type": "string", + "example": "Thank you for your business!" + }, + "state": { + "type": "string", + "example": "CA" + }, + "zip_code": { + "type": "string", + "example": "9800" + } + } + }, "requests.UserUpdate": { "type": "object", "required": [ @@ -3909,6 +4690,30 @@ const docTemplate = `{ } } }, + "responses.BulkMessagesResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.BulkMessage" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, "responses.DiscordResponse": { "type": "object", "required": [ @@ -4037,6 +4842,51 @@ const docTemplate = `{ } } }, + "responses.MessageSendScheduleResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.MessageSendSchedule" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.MessageSendSchedulesResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.MessageSendSchedule" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, "responses.MessageThreadsResponse": { "type": "object", "required": [ @@ -4140,6 +4990,23 @@ const docTemplate = `{ } } }, + "responses.PaymentRequired": { + "type": "object", + "required": [ + "message", + "status" + ], + "properties": { + "message": { + "type": "string", + "example": "You have reached the maximum number of allowed resources. Please upgrade your plan." + }, + "status": { + "type": "string", + "example": "error" + } + } + }, "responses.PhoneAPIKeyResponse": { "type": "object", "required": [ @@ -4300,6 +5167,156 @@ const docTemplate = `{ } } }, + "responses.UserSubscriptionPaymentsResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "type": "object", + "required": [ + "attributes", + "id", + "type" + ], + "properties": { + "attributes": { + "type": "object", + "required": [ + "billing_reason", + "card_brand", + "card_last_four", + "created_at", + "currency", + "currency_rate", + "discount_total", + "discount_total_formatted", + "discount_total_usd", + "refunded", + "refunded_amount", + "refunded_amount_formatted", + "refunded_amount_usd", + "refunded_at", + "status", + "status_formatted", + "subtotal", + "subtotal_formatted", + "subtotal_usd", + "tax", + "tax_formatted", + "tax_inclusive", + "tax_usd", + "total", + "total_formatted", + "total_usd", + "updated_at" + ], + "properties": { + "billing_reason": { + "type": "string" + }, + "card_brand": { + "type": "string" + }, + "card_last_four": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "currency": { + "type": "string" + }, + "currency_rate": { + "type": "string" + }, + "discount_total": { + "type": "integer" + }, + "discount_total_formatted": { + "type": "string" + }, + "discount_total_usd": { + "type": "integer" + }, + "refunded": { + "type": "boolean" + }, + "refunded_amount": { + "type": "integer" + }, + "refunded_amount_formatted": { + "type": "string" + }, + "refunded_amount_usd": { + "type": "integer" + }, + "refunded_at": {}, + "status": { + "type": "string" + }, + "status_formatted": { + "type": "string" + }, + "subtotal": { + "type": "integer" + }, + "subtotal_formatted": { + "type": "string" + }, + "subtotal_usd": { + "type": "integer" + }, + "tax": { + "type": "integer" + }, + "tax_formatted": { + "type": "string" + }, + "tax_inclusive": { + "type": "boolean" + }, + "tax_usd": { + "type": "integer" + }, + "total": { + "type": "integer" + }, + "total_formatted": { + "type": "string" + }, + "total_usd": { + "type": "integer" + }, + "updated_at": { + "type": "string" + } + } + }, + "id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, "responses.WebhookResponse": { "type": "object", "required": [ @@ -4362,9 +5379,11 @@ var SwaggerInfo = &swag.Spec{ BasePath: "/v1", Schemes: []string{"https"}, Title: "httpSMS API Reference", - Description: "API to send SMS messages using android [SmsManager](https://developer.android.com/reference/android/telephony/SmsManager) via HTTP", + Description: "Use your Android phone to send and receive SMS messages via a simple programmable API with end-to-end encryption.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/api/docs/swagger.json b/api/docs/swagger.json index fb49b100..69e9d363 100644 --- a/api/docs/swagger.json +++ b/api/docs/swagger.json @@ -1,3933 +1,5370 @@ { - "schemes": ["https"], - "swagger": "2.0", - "info": { - "description": "API to send SMS messages using android [SmsManager](https://developer.android.com/reference/android/telephony/SmsManager) via HTTP", - "title": "httpSMS API Reference", - "contact": { - "name": "HTTP SMS", - "email": "support@httpsms.com" - }, - "license": { - "name": "AGPL-3.0", - "url": "https://raw.githubusercontent.com/NdoleStudio/http-sms-manager/main/LICENSE" - }, - "version": "1.0" - }, - "host": "api.httpsms.com", - "basePath": "/v1", - "paths": { - "/billing/usage": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get the summary of sent and received messages for a user in the current month", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Billing"], - "summary": "Get Billing Usage.", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.BillingUsageResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/billing/usage-history": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get billing usage records of sent and received messages for a user in the past. It will be sorted by timestamp in descending order.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Billing"], - "summary": "Get billing usage history.", - "parameters": [ - { - "minimum": 0, - "type": "integer", - "description": "number of heartbeats to skip", - "name": "skip", - "in": "query" - }, - { - "maximum": 100, - "minimum": 1, - "type": "integer", - "description": "number of heartbeats to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.BillingUsagesResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/bulk-messages": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Sends bulk SMS messages to multiple users from a CSV file.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["BulkSMS"], - "summary": "Store bulk SMS file", - "responses": { - "202": { - "description": "Accepted", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/discord-integrations": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get the discord integrations of a user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["DiscordIntegration"], - "summary": "Get discord integrations of a user", - "parameters": [ - { - "minimum": 0, - "type": "integer", - "description": "number of discord integrations to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter discord integrations containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 20, - "minimum": 1, - "type": "integer", - "description": "number of discord integrations to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.DiscordsResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Store a discord integration for the authenticated user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["DiscordIntegration"], - "summary": "Store discord integration", - "parameters": [ - { - "description": "Payload of the discord integration request", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.DiscordStore" - } - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/responses.DiscordResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/discord-integrations/{discordID}": { - "put": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Update a discord integration for the currently authenticated user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["DiscordIntegration"], - "summary": "Update a discord integration", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the discord integration", - "name": "discordID", - "in": "path", - "required": true - }, - { - "description": "Payload of discord integration to update", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.DiscordUpdate" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.DiscordResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Delete a discord integration for a user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Webhooks"], - "summary": "Delete discord integration", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the discord integration", - "name": "discordID", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/discord/event": { - "post": { - "description": "Publish a discord event to the registered listeners", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Discord"], - "summary": "Consume a discord event", - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/heartbeats": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get the last time a phone number requested for outstanding messages. It will be sorted by timestamp in descending order.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Heartbeats"], - "summary": "Get heartbeats of an owner phone number", - "parameters": [ - { - "type": "string", - "default": "+18005550199", - "description": "the owner's phone number", - "name": "owner", - "in": "query", - "required": true - }, - { - "minimum": 0, - "type": "integer", - "description": "number of heartbeats to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 20, - "minimum": 1, - "type": "integer", - "description": "number of heartbeats to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.HeartbeatsResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Store the heartbeat to make notify that a phone number is still active", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Heartbeats"], - "summary": "Register heartbeat of an owner phone number", - "parameters": [ - { - "description": "Payload of the heartbeat request", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.HeartbeatStore" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.HeartbeatResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/integration/3cx/messages": { - "post": { - "description": "Sends an SMS message from the 3CX platform", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["3CXIntegration"], - "summary": "Sends a 3CX SMS message", - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/lemonsqueezy/event": { - "post": { - "description": "Publish a lemonsqueezy event to the registered listeners", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Lemonsqueezy"], - "summary": "Consume a lemonsqueezy event", - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/message-threads": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get list of contacts which a phone number has communicated with (threads). It will be sorted by timestamp in descending order.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["MessageThreads"], - "summary": "Get message threads for a phone number", - "parameters": [ - { - "type": "string", - "default": "+18005550199", - "description": "owner phone number", - "name": "owner", - "in": "query", - "required": true - }, - { - "minimum": 0, - "type": "integer", - "description": "number of messages to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter message threads containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 20, - "minimum": 1, - "type": "integer", - "description": "number of messages to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessageThreadsResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/message-threads/{messageThreadID}": { - "put": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Updates the details of a message thread", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["MessageThreads"], - "summary": "Update a message thread", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the message thread", - "name": "messageThreadID", - "in": "path", - "required": true - }, - { - "description": "Payload of message thread details to update", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.MessageThreadUpdate" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.PhoneResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Delete a message thread from the database and also deletes all the messages in the thread.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["MessageThreads"], - "summary": "Delete a message thread from the database.", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the message thread", - "name": "messageThreadID", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/responses.NotFound" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get list of messages which are sent between 2 phone numbers. It will be sorted by timestamp in descending order.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Get messages which are sent between 2 phone numbers", - "parameters": [ - { - "type": "string", - "default": "+18005550199", - "description": "the owner's phone number", - "name": "owner", - "in": "query", - "required": true - }, - { - "type": "string", - "default": "+18005550100", - "description": "the contact's phone number", - "name": "contact", - "in": "query", - "required": true - }, - { - "minimum": 0, - "type": "integer", - "description": "number of messages to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter messages containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 20, - "minimum": 1, - "type": "integer", - "description": "number of messages to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessagesResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/bulk-send": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Add bulk SMS messages to be sent by the android phone", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Send bulk SMS messages", - "parameters": [ - { - "description": "Bulk send message request payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.MessageBulkSend" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/responses.MessagesResponse" - } - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/calls/missed": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "This endpoint is called by the httpSMS android app to register a missed call event on the mobile phone.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Register a missed call event on the mobile phone", - "parameters": [ - { - "description": "Payload of the missed call event.", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.MessageCallMissed" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessageResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/responses.NotFound" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/outstanding": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get an outstanding message to be sent by an android phone", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Get an outstanding message", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703cb", - "description": "The ID of the message", - "name": "message_id", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessageResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/receive": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Add a new message received from a mobile phone", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Receive a new SMS message from a mobile phone", - "parameters": [ - { - "description": "Received message request payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.MessageReceive" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessageResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/search": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "This returns the list of all messages based on the filter criteria including missed calls", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Search all messages of a user", - "parameters": [ - { - "type": "string", - "description": "Cloudflare turnstile token https://www.cloudflare.com/en-gb/application-services/products/turnstile/", - "name": "token", - "in": "header", - "required": true - }, - { - "type": "string", - "default": "+18005550199,+18005550100", - "description": "the owner's phone numbers", - "name": "owners", - "in": "query", - "required": true - }, - { - "minimum": 0, - "type": "integer", - "description": "number of messages to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter messages containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 200, - "minimum": 1, - "type": "integer", - "description": "number of messages to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessagesResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/send": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Add a new SMS message to be sent by the android phone", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Send a new SMS message", - "parameters": [ - { - "description": "PostSend message request payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.MessageSend" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessageResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/{messageID}": { - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Delete a message from the database and removes the message content from the list of threads.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Delete a message from the database.", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the message", - "name": "messageID", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/responses.NotFound" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/messages/{messageID}/events": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Use this endpoint to send events for a message when it is failed, sent or delivered by the mobile phone.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Messages"], - "summary": "Upsert an event for a message on the mobile phone", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the message", - "name": "messageID", - "in": "path", - "required": true - }, - { - "description": "Payload of the event emitted.", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.MessageEvent" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.MessageResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/responses.NotFound" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/phone-api-keys": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get list phone API keys which a user has registered on the httpSMS application", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["PhoneAPIKeys"], - "summary": "Get the phone API keys of a user", - "parameters": [ - { - "minimum": 0, - "type": "integer", - "description": "number of phone api keys to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter phone api keys with name containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 100, - "minimum": 1, - "type": "integer", - "description": "number of phone api keys to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.PhoneAPIKeysResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Creates a new phone API key which can be used to log in to the httpSMS app on your Android phone", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["PhoneAPIKeys"], - "summary": "Store phone API key", - "parameters": [ - { - "description": "Payload of new phone API key.", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.PhoneAPIKeyStoreRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.PhoneAPIKeyResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/phone-api-keys/{phoneAPIKeyID}": { - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Delete a phone API Key from the database and cannot be used for authentication anymore.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["PhoneAPIKeys"], - "summary": "Delete a phone API key from the database.", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the phone API key", - "name": "phoneAPIKeyID", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/responses.NotFound" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/phone-api-keys/{phoneAPIKeyID}/phones/{phoneID}": { - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "You will need to login again to the httpSMS app on your Android phone with a new phone API key.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["PhoneAPIKeys"], - "summary": "Remove the association of a phone from the phone API key.", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the phone API key", - "name": "phoneAPIKeyID", - "in": "path", - "required": true - }, - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the phone", - "name": "phoneID", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/responses.NotFound" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/phones": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get list of phones which a user has registered on the http sms application", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Phones"], - "summary": "Get phones of a user", - "parameters": [ - { - "minimum": 0, - "type": "integer", - "description": "number of heartbeats to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter phones containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 20, - "minimum": 1, - "type": "integer", - "description": "number of phones to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.PhonesResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "put": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Updates properties of a user's phone. If the phone with this number does not exist, a new one will be created. Think of this method like an 'upsert'", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Phones"], - "summary": "Upsert Phone", - "parameters": [ - { - "description": "Payload of new phone number.", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.PhoneUpsert" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.PhoneResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/phones/fcm-token": { - "put": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Updates the FCM token of a phone. If the phone with this number does not exist, a new one will be created. Think of this method like an 'upsert'", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Phones"], - "summary": "Upserts the FCM token of a phone", - "parameters": [ - { - "description": "Payload of new FCM token.", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.PhoneFCMToken" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.PhoneResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/phones/{phoneID}": { - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Delete a phone that has been sored in the database", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Phones"], - "summary": "Delete Phone", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the phone", - "name": "phoneID", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/users/me": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get details of the currently authenticated user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Users"], - "summary": "Get current user", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.UserResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "put": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Updates the details of the currently authenticated user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Users"], - "summary": "Update a user", - "parameters": [ - { - "description": "Payload of user details to update", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.UserUpdate" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.PhoneResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Deletes the currently authenticated user together with all their data.", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Users"], - "summary": "Delete a user", - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/users/subscription": { - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Cancel the subscription of the authenticated user.", - "produces": ["application/json"], - "tags": ["Users"], - "summary": "Cancel the user's subscription", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/users/subscription-update-url": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Fetches the subscription URL of the authenticated user.", - "produces": ["application/json"], - "tags": ["Users"], - "summary": "Currently authenticated user subscription update URL", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.OkString" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/users/{userID}/api-keys": { - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Rotate the user's API key in case the current API Key is compromised", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Users"], - "summary": "Rotate the user's API Key", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the user to update", - "name": "userID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.UserResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/users/{userID}/notifications": { - "put": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Update the email notification settings for a user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Users"], - "summary": "Update notification settings", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the user to update", - "name": "userID", - "in": "path", - "required": true - }, - { - "description": "User notification details to update", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.UserNotificationUpdate" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.UserResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/webhooks": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Get the webhooks of a user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Webhooks"], - "summary": "Get webhooks of a user", - "parameters": [ - { - "minimum": 0, - "type": "integer", - "description": "number of webhooks to skip", - "name": "skip", - "in": "query" - }, - { - "type": "string", - "description": "filter webhooks containing query", - "name": "query", - "in": "query" - }, - { - "maximum": 20, - "minimum": 1, - "type": "integer", - "description": "number of webhooks to return", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.WebhooksResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Store a webhook for the authenticated user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Webhooks"], - "summary": "Store a webhook", - "parameters": [ - { - "description": "Payload of the webhook request", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.WebhookStore" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.WebhookResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - }, - "/webhooks/{webhookID}": { - "put": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Update a webhook for the currently authenticated user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Webhooks"], - "summary": "Update a webhook", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the webhook", - "name": "webhookID", - "in": "path", - "required": true - }, - { - "description": "Payload of webhook details to update", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.WebhookUpdate" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/responses.WebhookResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - }, - "delete": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Delete a webhook for a user", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["Webhooks"], - "summary": "Delete webhook", - "parameters": [ - { - "type": "string", - "default": "32343a19-da5e-4b1b-a767-3298a73703ca", - "description": "ID of the webhook", - "name": "webhookID", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "No Content", - "schema": { - "$ref": "#/definitions/responses.NoContent" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.BadRequest" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/responses.Unauthorized" - } - }, - "422": { - "description": "Unprocessable Entity", - "schema": { - "$ref": "#/definitions/responses.UnprocessableEntity" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.InternalServerError" - } - } - } - } - } - }, - "definitions": { - "entities.BillingUsage": { - "type": "object", - "required": [ - "created_at", - "end_timestamp", - "id", - "received_messages", - "sent_messages", - "start_timestamp", - "total_cost", - "updated_at", - "user_id" - ], - "properties": { - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "end_timestamp": { - "type": "string", - "example": "2022-01-31T23:59:59+00:00" - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "received_messages": { - "type": "integer", - "example": 465 - }, - "sent_messages": { - "type": "integer", - "example": 321 - }, - "start_timestamp": { - "type": "string", - "example": "2022-01-01T00:00:00+00:00" - }, - "total_cost": { - "type": "integer", - "example": 0 - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:10.303278+03:00" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - } - } - }, - "entities.Discord": { - "type": "object", - "required": [ - "created_at", - "id", - "incoming_channel_id", - "name", - "server_id", - "updated_at", - "user_id" - ], - "properties": { - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "incoming_channel_id": { - "type": "string", - "example": "1095780203256627291" - }, - "name": { - "type": "string", - "example": "Game Server" - }, - "server_id": { - "type": "string", - "example": "1095778291488653372" - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:10.303278+03:00" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - } - } - }, - "entities.Heartbeat": { - "type": "object", - "required": [ - "charging", - "id", - "owner", - "timestamp", - "user_id", - "version" - ], - "properties": { - "charging": { - "type": "boolean", - "example": true - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "owner": { - "type": "string", - "example": "+18005550199" - }, - "timestamp": { - "type": "string", - "example": "2022-06-05T14:26:01.520828+03:00" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - }, - "version": { - "type": "string", - "example": "344c10f" - } - } - }, - "entities.Message": { - "type": "object", - "required": [ - "can_be_polled", - "contact", - "content", - "created_at", - "delivered_at", - "encrypted", - "expired_at", - "failed_at", - "failure_reason", - "id", - "last_attempted_at", - "max_send_attempts", - "order_timestamp", - "owner", - "received_at", - "request_id", - "request_received_at", - "scheduled_at", - "scheduled_send_time", - "send_attempt_count", - "send_time", - "sent_at", - "sim", - "status", - "type", - "updated_at", - "user_id" - ], - "properties": { - "can_be_polled": { - "type": "boolean", - "example": false - }, + "schemes": [ + "https" + ], + "swagger": "2.0", + "info": { + "description": "Use your Android phone to send and receive SMS messages via a simple programmable API with end-to-end encryption.", + "title": "httpSMS API Reference", "contact": { - "type": "string", - "example": "+18005550100" - }, - "content": { - "type": "string", - "example": "This is a sample text message" - }, - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "delivered_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "encrypted": { - "type": "boolean", - "example": false - }, - "expired_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "failed_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "failure_reason": { - "type": "string", - "example": "UNKNOWN" - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "last_attempted_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "max_send_attempts": { - "type": "integer", - "example": 1 - }, - "order_timestamp": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "owner": { - "type": "string", - "example": "+18005550199" - }, - "received_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "request_id": { - "type": "string", - "example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4" - }, - "request_received_at": { - "type": "string", - "example": "2022-06-05T14:26:01.520828+03:00" - }, - "scheduled_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "scheduled_send_time": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "send_attempt_count": { - "type": "integer", - "example": 0 - }, - "send_time": { - "description": "SendDuration is the number of nanoseconds from when the request was received until when the mobile phone send the message", - "type": "integer", - "example": 133414 - }, - "sent_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "sim": { - "description": "SIM is the SIM card to use to send the message\n* SMS1: use the SIM card in slot 1\n* SMS2: use the SIM card in slot 2\n* DEFAULT: used the default communication SIM card", - "type": "string", - "example": "DEFAULT" - }, - "status": { - "type": "string", - "example": "pending" - }, - "type": { - "type": "string", - "example": "mobile-terminated" - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:10.303278+03:00" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - } - } - }, - "entities.MessageThread": { - "type": "object", - "required": [ - "color", - "contact", - "created_at", - "id", - "is_archived", - "last_message_content", - "last_message_id", - "order_timestamp", - "owner", - "status", - "updated_at", - "user_id" - ], - "properties": { - "color": { - "type": "string", - "example": "indigo" - }, - "contact": { - "type": "string", - "example": "+18005550100" - }, - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703ca" + "name": "support@httpsms.com", + "email": "support@httpsms.com" }, - "is_archived": { - "type": "boolean", - "example": false + "license": { + "name": "AGPL-3.0", + "url": "https://raw.githubusercontent.com/NdoleStudio/http-sms-manager/main/LICENSE" }, - "last_message_content": { - "type": "string", - "example": "This is a sample message content" - }, - "last_message_id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703ca" - }, - "order_timestamp": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "owner": { - "type": "string", - "example": "+18005550199" - }, - "status": { - "type": "string", - "example": "PENDING" - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - } - } - }, - "entities.Phone": { - "type": "object", - "required": [ - "created_at", - "fcm_token", - "id", - "max_send_attempts", - "message_expiration_seconds", - "messages_per_minute", - "missed_call_auto_reply", - "phone_number", - "sim", - "updated_at", - "user_id" - ], - "properties": { - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "fcm_token": { - "type": "string", - "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "max_send_attempts": { - "description": "MaxSendAttempts determines how many times to retry sending an SMS message", - "type": "integer", - "example": 2 - }, - "message_expiration_seconds": { - "description": "MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired.", - "type": "integer" - }, - "messages_per_minute": { - "type": "integer", - "example": 1 - }, - "missed_call_auto_reply": { - "type": "string", - "example": "This phone cannot receive calls. Please send an SMS instead." - }, - "phone_number": { - "type": "string", - "example": "+18005550199" - }, - "sim": { - "description": "SIM card that received the message", - "type": "string" - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:10.303278+03:00" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - } - } - }, - "entities.PhoneAPIKey": { - "type": "object", - "required": [ - "api_key", - "created_at", - "id", - "name", - "phone_ids", - "phone_numbers", - "updated_at", - "user_email", - "user_id" - ], - "properties": { - "api_key": { - "type": "string", - "example": "pk_DGW8NwQp7mxKaSZ72Xq9v6xxxxx" - }, - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "name": { - "type": "string", - "example": "Business Phone Key" - }, - "phone_ids": { - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "32343a19-da5e-4b1b-a767-3298a73703cb", - "32343a19-da5e-4b1b-a767-3298a73703cc" - ] - }, - "phone_numbers": { - "type": "array", - "items": { - "type": "string" - }, - "example": ["+18005550199", "+18005550100"] - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "user_email": { - "type": "string", - "example": "user@gmail.com" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - } - } - }, - "entities.User": { - "type": "object", - "required": [ - "active_phone_id", - "api_key", - "created_at", - "email", - "id", - "notification_heartbeat_enabled", - "notification_message_status_enabled", - "notification_newsletter_enabled", - "notification_webhook_enabled", - "subscription_ends_at", - "subscription_id", - "subscription_name", - "subscription_renews_at", - "subscription_status", - "timezone", - "updated_at" - ], - "properties": { - "active_phone_id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "api_key": { - "type": "string", - "example": "x-api-key" - }, - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "email": { - "type": "string", - "example": "name@email.com" - }, - "id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - }, - "notification_heartbeat_enabled": { - "type": "boolean", - "example": true - }, - "notification_message_status_enabled": { - "type": "boolean", - "example": true - }, - "notification_newsletter_enabled": { - "type": "boolean", - "example": true - }, - "notification_webhook_enabled": { - "type": "boolean", - "example": true - }, - "subscription_ends_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "subscription_id": { - "type": "string", - "example": "8f9c71b8-b84e-4417-8408-a62274f65a08" - }, - "subscription_name": { - "type": "string", - "example": "free" - }, - "subscription_renews_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "subscription_status": { - "type": "string", - "example": "on_trial" - }, - "timezone": { - "type": "string", - "example": "Europe/Helsinki" - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:10.303278+03:00" - } - } - }, - "entities.Webhook": { - "type": "object", - "required": [ - "created_at", - "events", - "id", - "phone_numbers", - "signing_key", - "updated_at", - "url", - "user_id" - ], - "properties": { - "created_at": { - "type": "string", - "example": "2022-06-05T14:26:02.302718+03:00" - }, - "events": { - "type": "array", - "items": { - "type": "string" - }, - "example": ["message.phone.received"] - }, - "id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "phone_numbers": { - "type": "array", - "items": { - "type": "string" - }, - "example": ["+18005550199", "+18005550100"] - }, - "signing_key": { - "type": "string", - "example": "DGW8NwQp7mxKaSZ72Xq9v67SLqSbWQvckzzmK8D6rvd7NywSEkdMJtuxKyEkYnCY" - }, - "updated_at": { - "type": "string", - "example": "2022-06-05T14:26:10.303278+03:00" - }, - "url": { - "type": "string", - "example": "https://example.com" - }, - "user_id": { - "type": "string", - "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" - } - } - }, - "requests.DiscordStore": { - "type": "object", - "required": ["incoming_channel_id", "name", "server_id"], - "properties": { - "incoming_channel_id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "server_id": { - "type": "string" - } - } - }, - "requests.DiscordUpdate": { - "type": "object", - "required": ["incoming_channel_id", "name", "server_id"], - "properties": { - "incoming_channel_id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "server_id": { - "type": "string" - } - } - }, - "requests.HeartbeatStore": { - "type": "object", - "required": ["charging", "phone_numbers"], - "properties": { - "charging": { - "type": "boolean" - }, - "phone_numbers": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "requests.MessageBulkSend": { - "type": "object", - "required": ["content", "encrypted", "from", "to"], - "properties": { - "content": { - "type": "string", - "example": "This is a sample text message" - }, - "encrypted": { - "description": "Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app", - "type": "boolean", - "example": false - }, - "from": { - "type": "string", - "example": "+18005550199" - }, - "request_id": { - "description": "RequestID is an optional parameter used to track a request from the client's perspective", - "type": "string", - "example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4" - }, - "to": { - "type": "array", - "items": { - "type": "string" - }, - "example": ["+18005550100", "+18005550100"] - } - } - }, - "requests.MessageCallMissed": { - "type": "object", - "required": ["from", "sim", "timestamp", "to"], - "properties": { - "from": { - "type": "string", - "example": "+18005550199" - }, - "sim": { - "type": "string", - "example": "SIM1" - }, - "timestamp": { - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "to": { - "type": "string", - "example": "+18005550100" - } - } - }, - "requests.MessageEvent": { - "type": "object", - "required": ["event_name", "reason", "timestamp"], - "properties": { - "event_name": { - "description": "EventName is the type of event\n* SENT: is emitted when a message is sent by the mobile phone\n* FAILED: is event is emitted when the message could not be sent by the mobile phone\n* DELIVERED: is event is emitted when a delivery report has been received by the mobile phone", - "type": "string", - "example": "SENT" - }, - "reason": { - "description": "Reason is the exact error message in case the event is an error", - "type": "string" - }, - "timestamp": { - "description": "Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible", - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - } - } - }, - "requests.MessageReceive": { - "type": "object", - "required": ["content", "encrypted", "from", "sim", "timestamp", "to"], - "properties": { - "content": { - "type": "string", - "example": "This is a sample text message received on a phone" - }, - "encrypted": { - "description": "Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app", - "type": "boolean", - "example": false - }, - "from": { - "type": "string", - "example": "+18005550199" - }, - "sim": { - "description": "SIM card that received the message", - "type": "string", - "example": "SIM1" - }, - "timestamp": { - "description": "Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible", - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "to": { - "type": "string", - "example": "+18005550100" - } - } - }, - "requests.MessageSend": { - "type": "object", - "required": ["content", "from", "to"], - "properties": { - "content": { - "type": "string", - "example": "This is a sample text message" - }, - "encrypted": { - "description": "Encrypted is an optional parameter used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app", - "type": "boolean", - "example": false - }, - "from": { - "type": "string", - "example": "+18005550199" - }, - "request_id": { - "description": "RequestID is an optional parameter used to track a request from the client's perspective", - "type": "string", - "example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4" - }, - "send_at": { - "description": "SendAt is an optional parameter used to schedule a message to be sent at a later time", - "type": "string", - "example": "2022-06-05T14:26:09.527976+03:00" - }, - "to": { - "type": "string", - "example": "+18005550100" - } - } - }, - "requests.MessageThreadUpdate": { - "type": "object", - "required": ["is_archived"], - "properties": { - "is_archived": { - "type": "boolean", - "example": true - } - } - }, - "requests.PhoneAPIKeyStoreRequest": { - "type": "object", - "required": ["name"], - "properties": { - "name": { - "type": "string", - "example": "My Phone API Key" - } - } - }, - "requests.PhoneFCMToken": { - "type": "object", - "required": ["fcm_token", "phone_number", "sim"], - "properties": { - "fcm_token": { - "type": "string", - "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." - }, - "phone_number": { - "type": "string", - "example": "[+18005550199]" - }, - "sim": { - "description": "SIM is the SIM slot of the phone in case the phone has more than 1 SIM slot", - "type": "string", - "example": "SIM1" - } - } - }, - "requests.PhoneUpsert": { - "type": "object", - "required": [ - "fcm_token", - "max_send_attempts", - "message_expiration_seconds", - "messages_per_minute", - "missed_call_auto_reply", - "phone_number", - "sim" - ], - "properties": { - "fcm_token": { - "type": "string", - "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." - }, - "max_send_attempts": { - "description": "MaxSendAttempts is the number of attempts when sending an SMS message to handle the case where the phone is offline.", - "type": "integer", - "example": 2 - }, - "message_expiration_seconds": { - "description": "MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired.", - "type": "integer", - "example": 12345 - }, - "messages_per_minute": { - "type": "integer", - "example": 1 - }, - "missed_call_auto_reply": { - "type": "string", - "example": "e.g. This phone cannot receive calls. Please send an SMS instead." - }, - "phone_number": { - "type": "string", - "example": "+18005550199" - }, - "sim": { - "description": "SIM is the SIM slot of the phone in case the phone has more than 1 SIM slot", - "type": "string", - "example": "SIM1" - } - } + "version": "1.0" }, - "requests.UserNotificationUpdate": { - "type": "object", - "required": [ - "heartbeat_enabled", - "message_status_enabled", - "newsletter_enabled", - "webhook_enabled" - ], - "properties": { - "heartbeat_enabled": { - "type": "boolean", - "example": true - }, - "message_status_enabled": { - "type": "boolean", - "example": true - }, - "newsletter_enabled": { - "type": "boolean", - "example": true - }, - "webhook_enabled": { - "type": "boolean", - "example": true - } - } - }, - "requests.UserUpdate": { - "type": "object", - "required": ["active_phone_id", "timezone"], - "properties": { - "active_phone_id": { - "type": "string", - "example": "32343a19-da5e-4b1b-a767-3298a73703cb" - }, - "timezone": { - "type": "string", - "example": "Europe/Helsinki" - } - } - }, - "requests.WebhookStore": { - "type": "object", - "required": ["events", "phone_numbers", "signing_key", "url"], - "properties": { - "events": { - "type": "array", - "items": { - "type": "string" - } - }, - "phone_numbers": { - "type": "array", - "items": { - "type": "string" - }, - "example": ["+18005550100", "+18005550100"] - }, - "signing_key": { - "type": "string" - }, - "url": { - "type": "string" - } - } - }, - "requests.WebhookUpdate": { - "type": "object", - "required": ["events", "phone_numbers", "signing_key", "url"], - "properties": { - "events": { - "type": "array", - "items": { - "type": "string" - } - }, - "phone_numbers": { - "type": "array", - "items": { - "type": "string" - }, - "example": ["+18005550100", "+18005550100"] - }, - "signing_key": { - "type": "string" - }, - "url": { - "type": "string" - } - } - }, - "responses.BadRequest": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "string", - "example": "The request body is not a valid JSON string" - }, - "message": { - "type": "string", - "example": "The request isn't properly formed" - }, - "status": { - "type": "string", - "example": "error" - } - } - }, - "responses.BillingUsageResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.BillingUsage" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.BillingUsagesResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.BillingUsage" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.DiscordResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.Discord" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.DiscordsResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.Discord" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.HeartbeatResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.Heartbeat" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.HeartbeatsResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.Heartbeat" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.InternalServerError": { - "type": "object", - "required": ["message", "status"], - "properties": { - "message": { - "type": "string", - "example": "We ran into an internal error while handling the request." - }, - "status": { - "type": "string", - "example": "error" - } - } - }, - "responses.MessageResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.Message" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.MessageThreadsResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.MessageThread" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.MessagesResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.Message" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.NoContent": { - "type": "object", - "required": ["message", "status"], - "properties": { - "message": { - "type": "string", - "example": "action performed successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.NotFound": { - "type": "object", - "required": ["message", "status"], - "properties": { - "message": { - "type": "string", - "example": "cannot find message with ID [32343a19-da5e-4b1b-a767-3298a73703ca]" - }, - "status": { - "type": "string", - "example": "error" - } - } - }, - "responses.OkString": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "string" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.PhoneAPIKeyResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.PhoneAPIKey" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.PhoneAPIKeysResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.PhoneAPIKey" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.PhoneResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.Phone" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.PhonesResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.Phone" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" - } - } - }, - "responses.Unauthorized": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "string", - "example": "Make sure your API key is set in the [X-API-Key] header in the request" - }, - "message": { - "type": "string", - "example": "You are not authorized to carry out this request." - }, - "status": { - "type": "string", - "example": "error" - } - } - }, - "responses.UnprocessableEntity": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "message": { - "type": "string", - "example": "validation errors while handling request" - }, - "status": { - "type": "string", - "example": "error" - } - } - }, - "responses.UserResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.User" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" + "host": "api.httpsms.com", + "basePath": "/v1", + "paths": { + "/billing/usage": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get the summary of sent and received messages for a user in the current month", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Billing" + ], + "summary": "Get Billing Usage.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.BillingUsageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/billing/usage-history": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get billing usage records of sent and received messages for a user in the past. It will be sorted by timestamp in descending order.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Billing" + ], + "summary": "Get billing usage history.", + "parameters": [ + { + "minimum": 0, + "type": "integer", + "description": "number of heartbeats to skip", + "name": "skip", + "in": "query" + }, + { + "maximum": 100, + "minimum": 1, + "type": "integer", + "description": "number of heartbeats to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.BillingUsagesResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/bulk-messages": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Fetches the last 10 bulk message order summaries for the authenticated user showing counts per status.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "BulkSMS" + ], + "summary": "List bulk message orders", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.BulkMessagesResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Sends bulk SMS messages to multiple users based on our [CSV template](https://httpsms.com/templates/httpsms-bulk.csv) or our [Excel template](https://httpsms.com/templates/httpsms-bulk.xlsx).", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "BulkSMS" + ], + "summary": "Store bulk SMS file", + "parameters": [ + { + "type": "file", + "description": "The Excel or CSV file containing the messages to be sent.", + "name": "document", + "in": "formData", + "required": true + } + ], + "responses": { + "202": { + "description": "Accepted", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/discord-integrations": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get the discord integrations of a user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DiscordIntegration" + ], + "summary": "Get discord integrations of a user", + "parameters": [ + { + "minimum": 0, + "type": "integer", + "description": "number of discord integrations to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter discord integrations containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 20, + "minimum": 1, + "type": "integer", + "description": "number of discord integrations to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.DiscordsResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Store a discord integration for the authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DiscordIntegration" + ], + "summary": "Store discord integration", + "parameters": [ + { + "description": "Payload of the discord integration request", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.DiscordStore" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/responses.DiscordResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/discord-integrations/{discordID}": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Update a discord integration for the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DiscordIntegration" + ], + "summary": "Update a discord integration", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the discord integration", + "name": "discordID", + "in": "path", + "required": true + }, + { + "description": "Payload of discord integration to update", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.DiscordUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.DiscordResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete a discord integration for a user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Webhooks" + ], + "summary": "Delete discord integration", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the discord integration", + "name": "discordID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/discord/event": { + "post": { + "description": "Publish a discord event to the registered listeners", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Discord" + ], + "summary": "Consume a discord event", + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/heartbeats": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get the last time a phone number requested for outstanding messages. It will be sorted by timestamp in descending order.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Heartbeats" + ], + "summary": "Get heartbeats of an owner phone number", + "parameters": [ + { + "type": "string", + "default": "+18005550199", + "description": "the owner's phone number", + "name": "owner", + "in": "query", + "required": true + }, + { + "minimum": 0, + "type": "integer", + "description": "number of heartbeats to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 20, + "minimum": 1, + "type": "integer", + "description": "number of heartbeats to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.HeartbeatsResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Store the heartbeat to make notify that a phone number is still active", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Heartbeats" + ], + "summary": "Register heartbeat of an owner phone number", + "parameters": [ + { + "description": "Payload of the heartbeat request", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.HeartbeatStore" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.HeartbeatResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/integration/3cx/messages": { + "post": { + "description": "Sends an SMS message from the 3CX platform", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "3CXIntegration" + ], + "summary": "Sends a 3CX SMS message", + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/message-threads": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get list of contacts which a phone number has communicated with (threads). It will be sorted by timestamp in descending order.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MessageThreads" + ], + "summary": "Get message threads for a phone number", + "parameters": [ + { + "type": "string", + "default": "+18005550199", + "description": "owner phone number", + "name": "owner", + "in": "query", + "required": true + }, + { + "minimum": 0, + "type": "integer", + "description": "number of messages to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter message threads containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 20, + "minimum": 1, + "type": "integer", + "description": "number of messages to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageThreadsResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/message-threads/{messageThreadID}": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Updates the details of a message thread", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MessageThreads" + ], + "summary": "Update a message thread", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the message thread", + "name": "messageThreadID", + "in": "path", + "required": true + }, + { + "description": "Payload of message thread details to update", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageThreadUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhoneResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete a message thread from the database and also deletes all the messages in the thread.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MessageThreads" + ], + "summary": "Delete a message thread from the database.", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the message thread", + "name": "messageThreadID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get list of messages which are sent between 2 phone numbers. It will be sorted by timestamp in descending order.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Get messages which are sent between 2 phone numbers", + "parameters": [ + { + "type": "string", + "default": "+18005550199", + "description": "the owner's phone number", + "name": "owner", + "in": "query", + "required": true + }, + { + "type": "string", + "default": "+18005550100", + "description": "the contact's phone number", + "name": "contact", + "in": "query", + "required": true + }, + { + "minimum": 0, + "type": "integer", + "description": "number of messages to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter messages containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 20, + "minimum": 1, + "type": "integer", + "description": "number of messages to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessagesResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/bulk-send": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Add bulk SMS messages to be sent by the android phone", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Send bulk SMS messages", + "parameters": [ + { + "description": "Bulk send message request payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageBulkSend" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/responses.MessagesResponse" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/calls/missed": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "This endpoint is called by the httpSMS android app to register a missed call event on the mobile phone.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Register a missed call event on the mobile phone", + "parameters": [ + { + "description": "Payload of the missed call event.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageCallMissed" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/outstanding": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get an outstanding message to be sent by an android phone", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Get an outstanding message", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703cb", + "description": "The ID of the message", + "name": "message_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/receive": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Add a new message received from a mobile phone", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Receive a new SMS message from a mobile phone", + "parameters": [ + { + "description": "Received message request payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageReceive" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/search": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "This returns the list of all messages based on the filter criteria including missed calls", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Search all messages of a user", + "parameters": [ + { + "type": "string", + "description": "Cloudflare turnstile token https://www.cloudflare.com/en-gb/application-services/products/turnstile/", + "name": "token", + "in": "header", + "required": true + }, + { + "type": "string", + "default": "+18005550199,+18005550100", + "description": "the owner's phone numbers", + "name": "owners", + "in": "query", + "required": true + }, + { + "minimum": 0, + "type": "integer", + "description": "number of messages to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter messages containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 200, + "minimum": 1, + "type": "integer", + "description": "number of messages to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessagesResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/send": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Add a new SMS message to be sent by your Android phone", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Send an SMS message", + "parameters": [ + { + "description": "Send message request payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageSend" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/{messageID}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get a message from the database by the message ID.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Get a message from the database.", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the message", + "name": "messageID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete a message from the database and removes the message content from the list of threads.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Delete a message from the database.", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the message", + "name": "messageID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/messages/{messageID}/events": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Use this endpoint to send events for a message when it is failed, sent or delivered by the mobile phone.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Messages" + ], + "summary": "Upsert an event for a message on the mobile phone", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the message", + "name": "messageID", + "in": "path", + "required": true + }, + { + "description": "Payload of the event emitted.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageEvent" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/phone-api-keys": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get list phone API keys which a user has registered on the httpSMS application", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PhoneAPIKeys" + ], + "summary": "Get the phone API keys of a user", + "parameters": [ + { + "minimum": 0, + "type": "integer", + "description": "number of phone api keys to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter phone api keys with name containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 100, + "minimum": 1, + "type": "integer", + "description": "number of phone api keys to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhoneAPIKeysResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Creates a new phone API key which can be used to log in to the httpSMS app on your Android phone", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PhoneAPIKeys" + ], + "summary": "Store phone API key", + "parameters": [ + { + "description": "Payload of new phone API key.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.PhoneAPIKeyStoreRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhoneAPIKeyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "402": { + "description": "Payment Required", + "schema": { + "$ref": "#/definitions/responses.PaymentRequired" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/phone-api-keys/{phoneAPIKeyID}": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete a phone API Key from the database and cannot be used for authentication anymore.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PhoneAPIKeys" + ], + "summary": "Delete a phone API key from the database.", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the phone API key", + "name": "phoneAPIKeyID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/phone-api-keys/{phoneAPIKeyID}/phones/{phoneID}": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "You will need to login again to the httpSMS app on your Android phone with a new phone API key.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PhoneAPIKeys" + ], + "summary": "Remove the association of a phone from the phone API key.", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the phone API key", + "name": "phoneAPIKeyID", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the phone", + "name": "phoneID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/phones": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get list of phones which a user has registered on the http sms application", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Phones" + ], + "summary": "Get phones of a user", + "parameters": [ + { + "minimum": 0, + "type": "integer", + "description": "number of heartbeats to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter phones containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 20, + "minimum": 1, + "type": "integer", + "description": "number of phones to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhonesResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Updates properties of a user's phone. If the phone with this number does not exist, a new one will be created. Think of this method like an 'upsert'", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Phones" + ], + "summary": "Upsert Phone", + "parameters": [ + { + "description": "Payload of new phone number.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.PhoneUpsert" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhoneResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/phones/fcm-token": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Updates the FCM token of a phone. If the phone with this number does not exist, a new one will be created. Think of this method like an 'upsert'", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Phones" + ], + "summary": "Upserts the FCM token of a phone", + "parameters": [ + { + "description": "Payload of new FCM token.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.PhoneFCMToken" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhoneResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/phones/{phoneID}": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete a phone that has been sored in the database", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Phones" + ], + "summary": "Delete Phone", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the phone", + "name": "phoneID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/send-schedules": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "List all send schedules owned by the authenticated user.", + "produces": [ + "application/json" + ], + "tags": [ + "SendSchedules" + ], + "summary": "List send schedules", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageSendSchedulesResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Create a new send schedule for the authenticated user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SendSchedules" + ], + "summary": "Create send schedule", + "parameters": [ + { + "description": "Payload of new send schedule.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageSendScheduleStore" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/responses.MessageSendScheduleResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "402": { + "description": "Payment Required", + "schema": { + "$ref": "#/definitions/responses.PaymentRequired" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/send-schedules/{scheduleID}": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Update a send schedule owned by the authenticated user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SendSchedules" + ], + "summary": "Update send schedule", + "parameters": [ + { + "type": "string", + "description": "Schedule ID", + "name": "scheduleID", + "in": "path", + "required": true + }, + { + "description": "Payload of updated send schedule.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.MessageSendScheduleStore" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.MessageSendScheduleResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete a send schedule owned by the authenticated user.", + "produces": [ + "application/json" + ], + "tags": [ + "SendSchedules" + ], + "summary": "Delete send schedule", + "parameters": [ + { + "type": "string", + "description": "Schedule ID", + "name": "scheduleID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/me": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get details of the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Get current user", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.UserResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Updates the details of the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Update a user", + "parameters": [ + { + "description": "Payload of user details to update", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.UserUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.PhoneResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Deletes the currently authenticated user together with all their data.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Delete a user", + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Cancel the subscription of the authenticated user.", + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Cancel the user's subscription", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription-update-url": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Fetches the subscription URL of the authenticated user.", + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Currently authenticated user subscription update URL", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.OkString" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription/invoices/{subscriptionInvoiceID}": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Generates a new invoice PDF file for the given subscription payment with given parameters.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/pdf" + ], + "tags": [ + "Users" + ], + "summary": "Generate a subscription payment invoice", + "parameters": [ + { + "description": "Generate subscription payment invoice parameters", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.UserPaymentInvoice" + } + }, + { + "type": "string", + "description": "ID of the subscription invoice to generate the PDF for", + "name": "subscriptionInvoiceID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "file" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/subscription/payments": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Subscription payments are generated throughout the lifecycle of a subscription, typically there is one at the time of purchase and then one for each renewal.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Get the last 10 subscription payments.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.UserSubscriptionPaymentsResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/{userID}/api-keys": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Rotate the user's API key in case the current API Key is compromised", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Rotate the user's API Key", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the user to update", + "name": "userID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.UserResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/users/{userID}/notifications": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Update the email notification settings for a user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Update notification settings", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the user to update", + "name": "userID", + "in": "path", + "required": true + }, + { + "description": "User notification details to update", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.UserNotificationUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.UserResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/v1/attachments/{userID}/{messageID}/{attachmentIndex}/{filename}": { + "get": { + "description": "Download an MMS attachment by its path components", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Attachments" + ], + "summary": "Download a message attachment", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "userID", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Message ID", + "name": "messageID", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Attachment index", + "name": "attachmentIndex", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Filename with extension", + "name": "filename", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "file" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/responses.NotFound" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/webhooks": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get the webhooks of a user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Webhooks" + ], + "summary": "Get webhooks of a user", + "parameters": [ + { + "minimum": 0, + "type": "integer", + "description": "number of webhooks to skip", + "name": "skip", + "in": "query" + }, + { + "type": "string", + "description": "filter webhooks containing query", + "name": "query", + "in": "query" + }, + { + "maximum": 20, + "minimum": 1, + "type": "integer", + "description": "number of webhooks to return", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.WebhooksResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Store a webhook for the authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Webhooks" + ], + "summary": "Store a webhook", + "parameters": [ + { + "description": "Payload of the webhook request", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.WebhookStore" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.WebhookResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } + }, + "/webhooks/{webhookID}": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Update a webhook for the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Webhooks" + ], + "summary": "Update a webhook", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the webhook", + "name": "webhookID", + "in": "path", + "required": true + }, + { + "description": "Payload of webhook details to update", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.WebhookUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.WebhookResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete a webhook for a user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Webhooks" + ], + "summary": "Delete webhook", + "parameters": [ + { + "type": "string", + "default": "32343a19-da5e-4b1b-a767-3298a73703ca", + "description": "ID of the webhook", + "name": "webhookID", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "$ref": "#/definitions/responses.NoContent" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.BadRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/responses.Unauthorized" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/responses.UnprocessableEntity" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.InternalServerError" + } + } + } + } } - } }, - "responses.WebhookResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "$ref": "#/definitions/entities.Webhook" - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" + "definitions": { + "entities.BillingUsage": { + "type": "object", + "required": [ + "created_at", + "end_timestamp", + "id", + "received_messages", + "sent_messages", + "start_timestamp", + "total_cost", + "updated_at", + "user_id" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "end_timestamp": { + "type": "string", + "example": "2022-01-31T23:59:59+00:00" + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "received_messages": { + "type": "integer", + "example": 465 + }, + "sent_messages": { + "type": "integer", + "example": 321 + }, + "start_timestamp": { + "type": "string", + "example": "2022-01-01T00:00:00+00:00" + }, + "total_cost": { + "type": "integer", + "example": 0 + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "entities.BulkMessage": { + "type": "object", + "required": [ + "created_at", + "delivered_count", + "failed_count", + "pending_count", + "request_id", + "scheduled_count", + "sent_count", + "total" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "delivered_count": { + "type": "integer", + "example": 25 + }, + "failed_count": { + "type": "integer", + "example": 5 + }, + "pending_count": { + "type": "integer", + "example": 30 + }, + "request_id": { + "type": "string", + "example": "bulk-32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "scheduled_count": { + "type": "integer", + "example": 50 + }, + "sent_count": { + "type": "integer", + "example": 40 + }, + "total": { + "type": "integer", + "example": 150 + } + } + }, + "entities.Discord": { + "type": "object", + "required": [ + "created_at", + "id", + "incoming_channel_id", + "name", + "server_id", + "updated_at", + "user_id" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "incoming_channel_id": { + "type": "string", + "example": "1095780203256627291" + }, + "name": { + "type": "string", + "example": "Game Server" + }, + "server_id": { + "type": "string", + "example": "1095778291488653372" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "entities.Heartbeat": { + "type": "object", + "required": [ + "charging", + "id", + "owner", + "timestamp", + "user_id", + "version" + ], + "properties": { + "charging": { + "type": "boolean", + "example": true + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "owner": { + "type": "string", + "example": "+18005550199" + }, + "timestamp": { + "type": "string", + "example": "2022-06-05T14:26:01.520828+03:00" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + }, + "version": { + "type": "string", + "example": "344c10f" + } + } + }, + "entities.Message": { + "type": "object", + "required": [ + "attachments", + "contact", + "content", + "created_at", + "encrypted", + "id", + "max_send_attempts", + "order_timestamp", + "owner", + "request_received_at", + "send_attempt_count", + "sim", + "status", + "type", + "updated_at", + "user_id" + ], + "properties": { + "attachments": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "https://example.com/image.jpg", + "https://example.com/video.mp4" + ] + }, + "contact": { + "type": "string", + "example": "+18005550100" + }, + "content": { + "type": "string", + "example": "This is a sample text message" + }, + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "delivered_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "encrypted": { + "type": "boolean", + "example": false + }, + "expired_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "failed_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "failure_reason": { + "type": "string", + "example": "UNKNOWN" + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "last_attempted_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "max_send_attempts": { + "type": "integer", + "example": 1 + }, + "order_timestamp": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "owner": { + "type": "string", + "example": "+18005550199" + }, + "received_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "request_id": { + "type": "string", + "example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4" + }, + "request_received_at": { + "type": "string", + "example": "2022-06-05T14:26:01.520828+03:00" + }, + "scheduled_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "scheduled_send_time": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "send_attempt_count": { + "type": "integer", + "example": 0 + }, + "send_time": { + "description": "SendDuration is the number of nanoseconds from when the request was received until when the mobile phone send the message", + "type": "integer", + "example": 133414 + }, + "sent_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "sim": { + "description": "SIM is the SIM card to use to send the message\n* SMS1: use the SIM card in slot 1\n* SMS2: use the SIM card in slot 2\n* DEFAULT: used the default communication SIM card", + "allOf": [ + { + "$ref": "#/definitions/entities.SIM" + } + ], + "example": "DEFAULT" + }, + "status": { + "type": "string", + "example": "pending" + }, + "type": { + "type": "string", + "example": "mobile-terminated" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "entities.MessageSendSchedule": { + "type": "object", + "required": [ + "created_at", + "id", + "name", + "timezone", + "updated_at", + "user_id", + "windows" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "name": { + "type": "string", + "example": "Business Hours" + }, + "timezone": { + "type": "string", + "example": "Europe/Tallinn" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + }, + "windows": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.MessageSendScheduleWindow" + } + } + } + }, + "entities.MessageSendScheduleWindow": { + "type": "object", + "required": [ + "day_of_week", + "end_minute", + "start_minute" + ], + "properties": { + "day_of_week": { + "type": "integer", + "example": 1 + }, + "end_minute": { + "type": "integer", + "example": 1020 + }, + "start_minute": { + "type": "integer", + "example": 540 + } + } + }, + "entities.MessageThread": { + "type": "object", + "required": [ + "color", + "contact", + "created_at", + "id", + "is_archived", + "last_message_content", + "last_message_id", + "order_timestamp", + "owner", + "status", + "updated_at", + "user_id" + ], + "properties": { + "color": { + "type": "string", + "example": "indigo" + }, + "contact": { + "type": "string", + "example": "+18005550100" + }, + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703ca" + }, + "is_archived": { + "type": "boolean", + "example": false + }, + "last_message_content": { + "type": "string", + "example": "This is a sample message content" + }, + "last_message_id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703ca" + }, + "order_timestamp": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "owner": { + "type": "string", + "example": "+18005550199" + }, + "status": { + "type": "string", + "example": "PENDING" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "entities.Phone": { + "type": "object", + "required": [ + "created_at", + "id", + "max_send_attempts", + "message_expiration_seconds", + "messages_per_minute", + "phone_number", + "sim", + "updated_at", + "user_id" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "fcm_token": { + "type": "string", + "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "max_send_attempts": { + "description": "MaxSendAttempts determines how many times to retry sending an SMS message", + "type": "integer", + "example": 2 + }, + "message_expiration_seconds": { + "description": "MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired.", + "type": "integer" + }, + "message_send_schedule_id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "messages_per_minute": { + "type": "integer", + "example": 1 + }, + "missed_call_auto_reply": { + "type": "string", + "example": "This phone cannot receive calls. Please send an SMS instead." + }, + "phone_number": { + "type": "string", + "example": "+18005550199" + }, + "sim": { + "$ref": "#/definitions/entities.SIM" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "entities.PhoneAPIKey": { + "type": "object", + "required": [ + "api_key", + "created_at", + "id", + "name", + "phone_ids", + "phone_numbers", + "updated_at", + "user_email", + "user_id" + ], + "properties": { + "api_key": { + "type": "string", + "example": "pk_DGW8NwQp7mxKaSZ72Xq9v6xxxxx" + }, + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "name": { + "type": "string", + "example": "Business Phone Key" + }, + "phone_ids": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "32343a19-da5e-4b1b-a767-3298a73703cb", + "32343a19-da5e-4b1b-a767-3298a73703cc" + ] + }, + "phone_numbers": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "+18005550199", + "+18005550100" + ] + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "user_email": { + "type": "string", + "example": "user@gmail.com" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "entities.SIM": { + "type": "string", + "enum": [ + "SIM1", + "SIM2" + ], + "x-enum-varnames": [ + "SIM1", + "SIM2" + ] + }, + "entities.SubscriptionName": { + "type": "string", + "enum": [ + "free", + "pro-monthly", + "pro-yearly", + "ultra-monthly", + "ultra-yearly", + "pro-lifetime", + "20k-monthly", + "100k-monthly", + "50k-monthly", + "200k-monthly", + "20k-yearly" + ], + "x-enum-varnames": [ + "SubscriptionNameFree", + "SubscriptionNameProMonthly", + "SubscriptionNameProYearly", + "SubscriptionNameUltraMonthly", + "SubscriptionNameUltraYearly", + "SubscriptionNameProLifetime", + "SubscriptionName20KMonthly", + "SubscriptionName100KMonthly", + "SubscriptionName50KMonthly", + "SubscriptionName200KMonthly", + "SubscriptionName20KYearly" + ] + }, + "entities.User": { + "type": "object", + "required": [ + "api_key", + "created_at", + "email", + "id", + "notification_heartbeat_enabled", + "notification_message_status_enabled", + "notification_newsletter_enabled", + "notification_webhook_enabled", + "subscription_id", + "subscription_name", + "timezone", + "updated_at" + ], + "properties": { + "active_phone_id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "api_key": { + "type": "string", + "example": "x-api-key" + }, + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "email": { + "type": "string", + "example": "name@email.com" + }, + "id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + }, + "notification_heartbeat_enabled": { + "type": "boolean", + "example": true + }, + "notification_message_status_enabled": { + "type": "boolean", + "example": true + }, + "notification_newsletter_enabled": { + "type": "boolean", + "example": true + }, + "notification_webhook_enabled": { + "type": "boolean", + "example": true + }, + "subscription_ends_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "subscription_id": { + "type": "string", + "example": "8f9c71b8-b84e-4417-8408-a62274f65a08" + }, + "subscription_name": { + "allOf": [ + { + "$ref": "#/definitions/entities.SubscriptionName" + } + ], + "example": "free" + }, + "subscription_renews_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "subscription_status": { + "type": "string", + "example": "on_trial" + }, + "timezone": { + "type": "string", + "example": "Europe/Helsinki" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + } + } + }, + "entities.Webhook": { + "type": "object", + "required": [ + "created_at", + "events", + "id", + "phone_numbers", + "signing_key", + "updated_at", + "url", + "user_id" + ], + "properties": { + "created_at": { + "type": "string", + "example": "2022-06-05T14:26:02.302718+03:00" + }, + "events": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "message.phone.received" + ] + }, + "id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "phone_numbers": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "+18005550199", + "+18005550100" + ] + }, + "signing_key": { + "type": "string", + "example": "DGW8NwQp7mxKaSZ72Xq9v67SLqSbWQvckzzmK8D6rvd7NywSEkdMJtuxKyEkYnCY" + }, + "updated_at": { + "type": "string", + "example": "2022-06-05T14:26:10.303278+03:00" + }, + "url": { + "type": "string", + "example": "https://example.com" + }, + "user_id": { + "type": "string", + "example": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" + } + } + }, + "requests.DiscordStore": { + "type": "object", + "required": [ + "incoming_channel_id", + "name", + "server_id" + ], + "properties": { + "incoming_channel_id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "server_id": { + "type": "string" + } + } + }, + "requests.DiscordUpdate": { + "type": "object", + "required": [ + "incoming_channel_id", + "name", + "server_id" + ], + "properties": { + "incoming_channel_id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "server_id": { + "type": "string" + } + } + }, + "requests.HeartbeatStore": { + "type": "object", + "required": [ + "charging", + "phone_numbers" + ], + "properties": { + "charging": { + "type": "boolean" + }, + "phone_numbers": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "requests.MessageAttachment": { + "type": "object", + "required": [ + "content", + "content_type", + "name" + ], + "properties": { + "content": { + "description": "Content is the base64-encoded attachment data", + "type": "string", + "example": "base64data..." + }, + "content_type": { + "description": "ContentType is the MIME type of the attachment", + "type": "string", + "example": "image/jpeg" + }, + "name": { + "description": "Name is the original filename of the attachment", + "type": "string", + "example": "photo.jpg" + } + } + }, + "requests.MessageBulkSend": { + "type": "object", + "required": [ + "content", + "from", + "to" + ], + "properties": { + "attachments": { + "description": "Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS", + "type": "array", + "items": { + "type": "string" + } + }, + "content": { + "type": "string", + "example": "This is a sample text message" + }, + "encrypted": { + "description": "Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app", + "type": "boolean", + "example": false + }, + "from": { + "type": "string", + "example": "+18005550199" + }, + "request_id": { + "description": "RequestID is an optional parameter used to track a request from the client's perspective", + "type": "string", + "example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4" + }, + "to": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "+18005550100", + "+18005550100" + ] + } + } + }, + "requests.MessageCallMissed": { + "type": "object", + "required": [ + "from", + "sim", + "timestamp", + "to" + ], + "properties": { + "from": { + "type": "string", + "example": "+18005550199" + }, + "sim": { + "type": "string", + "example": "SIM1" + }, + "timestamp": { + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "to": { + "type": "string", + "example": "+18005550100" + } + } + }, + "requests.MessageEvent": { + "type": "object", + "required": [ + "event_name", + "reason", + "timestamp" + ], + "properties": { + "event_name": { + "description": "EventName is the type of event\n* SENT: is emitted when a message is sent by the mobile phone\n* FAILED: is event is emitted when the message could not be sent by the mobile phone\n* DELIVERED: is event is emitted when a delivery report has been received by the mobile phone", + "type": "string", + "example": "SENT" + }, + "reason": { + "description": "Reason is the exact error message in case the event is an error", + "type": "string" + }, + "timestamp": { + "description": "Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible", + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + } + } + }, + "requests.MessageReceive": { + "type": "object", + "required": [ + "content", + "encrypted", + "from", + "sim", + "timestamp", + "to" + ], + "properties": { + "attachments": { + "description": "Attachments is the list of MMS attachments received with the message", + "type": "array", + "items": { + "$ref": "#/definitions/requests.MessageAttachment" + } + }, + "content": { + "type": "string", + "example": "This is a sample text message received on a phone" + }, + "encrypted": { + "description": "Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app", + "type": "boolean", + "example": false + }, + "from": { + "type": "string", + "example": "+18005550199" + }, + "sim": { + "description": "SIM card that received the message", + "allOf": [ + { + "$ref": "#/definitions/entities.SIM" + } + ], + "example": "SIM1" + }, + "timestamp": { + "description": "Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible", + "type": "string", + "example": "2022-06-05T14:26:09.527976+03:00" + }, + "to": { + "type": "string", + "example": "+18005550100" + } + } + }, + "requests.MessageSend": { + "type": "object", + "required": [ + "content", + "from", + "to" + ], + "properties": { + "attachments": { + "description": "Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS", + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "https://example.com/image.jpg", + "https://example.com/video.mp4" + ] + }, + "content": { + "type": "string", + "example": "This is a sample text message" + }, + "encrypted": { + "description": "Encrypted is an optional parameter used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app", + "type": "boolean", + "example": false + }, + "from": { + "type": "string", + "example": "+18005550199" + }, + "request_id": { + "description": "RequestID is an optional parameter used to track a request from the client's perspective", + "type": "string", + "example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4" + }, + "send_at": { + "description": "SendAt is an optional parameter used to schedule a message to be sent in the future. The time is considered to be in your profile's local timezone and you can queue messages for up to 20 days (480 hours) in the future.", + "type": "string", + "example": "2025-12-19T16:39:57-08:00" + }, + "to": { + "type": "string", + "example": "+18005550100" + } + } + }, + "requests.MessageSendScheduleStore": { + "type": "object", + "required": [ + "name", + "timezone", + "windows" + ], + "properties": { + "name": { + "type": "string" + }, + "timezone": { + "type": "string" + }, + "windows": { + "type": "array", + "items": { + "$ref": "#/definitions/requests.MessageSendScheduleWindow" + } + } + } + }, + "requests.MessageSendScheduleWindow": { + "type": "object", + "required": [ + "day_of_week", + "end_minute", + "start_minute" + ], + "properties": { + "day_of_week": { + "type": "integer" + }, + "end_minute": { + "type": "integer" + }, + "start_minute": { + "type": "integer" + } + } + }, + "requests.MessageThreadUpdate": { + "type": "object", + "required": [ + "is_archived" + ], + "properties": { + "is_archived": { + "type": "boolean", + "example": true + } + } + }, + "requests.PhoneAPIKeyStoreRequest": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "example": "My Phone API Key" + } + } + }, + "requests.PhoneFCMToken": { + "type": "object", + "required": [ + "fcm_token", + "phone_number", + "sim" + ], + "properties": { + "fcm_token": { + "type": "string", + "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." + }, + "phone_number": { + "type": "string", + "example": "[+18005550199]" + }, + "sim": { + "description": "SIM is the SIM slot of the phone in case the phone has more than 1 SIM slot", + "type": "string", + "example": "SIM1" + } + } + }, + "requests.PhoneUpsert": { + "type": "object", + "required": [ + "fcm_token", + "max_send_attempts", + "message_expiration_seconds", + "messages_per_minute", + "missed_call_auto_reply", + "phone_number", + "sim" + ], + "properties": { + "fcm_token": { + "type": "string", + "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." + }, + "max_send_attempts": { + "description": "MaxSendAttempts is the number of attempts when sending an SMS message to handle the case where the phone is offline.", + "type": "integer", + "example": 2 + }, + "message_expiration_seconds": { + "description": "MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired.", + "type": "integer", + "example": 12345 + }, + "message_send_schedule_id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "messages_per_minute": { + "type": "integer", + "example": 1 + }, + "missed_call_auto_reply": { + "type": "string", + "example": "e.g. This phone cannot receive calls. Please send an SMS instead." + }, + "phone_number": { + "type": "string", + "example": "+18005550199" + }, + "sim": { + "description": "SIM is the SIM slot of the phone in case the phone has more than 1 SIM slot", + "type": "string", + "example": "SIM1" + } + } + }, + "requests.UserNotificationUpdate": { + "type": "object", + "required": [ + "heartbeat_enabled", + "message_status_enabled", + "newsletter_enabled", + "webhook_enabled" + ], + "properties": { + "heartbeat_enabled": { + "type": "boolean", + "example": true + }, + "message_status_enabled": { + "type": "boolean", + "example": true + }, + "newsletter_enabled": { + "type": "boolean", + "example": true + }, + "webhook_enabled": { + "type": "boolean", + "example": true + } + } + }, + "requests.UserPaymentInvoice": { + "type": "object", + "required": [ + "address", + "city", + "country", + "name", + "notes", + "state", + "zip_code" + ], + "properties": { + "address": { + "type": "string", + "example": "221B Baker Street, London" + }, + "city": { + "type": "string", + "example": "Los Angeles" + }, + "country": { + "type": "string", + "example": "US" + }, + "name": { + "type": "string", + "example": "Acme Corp" + }, + "notes": { + "type": "string", + "example": "Thank you for your business!" + }, + "state": { + "type": "string", + "example": "CA" + }, + "zip_code": { + "type": "string", + "example": "9800" + } + } + }, + "requests.UserUpdate": { + "type": "object", + "required": [ + "active_phone_id", + "timezone" + ], + "properties": { + "active_phone_id": { + "type": "string", + "example": "32343a19-da5e-4b1b-a767-3298a73703cb" + }, + "timezone": { + "type": "string", + "example": "Europe/Helsinki" + } + } + }, + "requests.WebhookStore": { + "type": "object", + "required": [ + "events", + "phone_numbers", + "signing_key", + "url" + ], + "properties": { + "events": { + "type": "array", + "items": { + "type": "string" + } + }, + "phone_numbers": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "+18005550100", + "+18005550100" + ] + }, + "signing_key": { + "type": "string" + }, + "url": { + "type": "string" + } + } + }, + "requests.WebhookUpdate": { + "type": "object", + "required": [ + "events", + "phone_numbers", + "signing_key", + "url" + ], + "properties": { + "events": { + "type": "array", + "items": { + "type": "string" + } + }, + "phone_numbers": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "+18005550100", + "+18005550100" + ] + }, + "signing_key": { + "type": "string" + }, + "url": { + "type": "string" + } + } + }, + "responses.BadRequest": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "string", + "example": "The request body is not a valid JSON string" + }, + "message": { + "type": "string", + "example": "The request isn't properly formed" + }, + "status": { + "type": "string", + "example": "error" + } + } + }, + "responses.BillingUsageResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.BillingUsage" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.BillingUsagesResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.BillingUsage" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.BulkMessagesResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.BulkMessage" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.DiscordResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.Discord" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.DiscordsResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Discord" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.HeartbeatResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.Heartbeat" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.HeartbeatsResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Heartbeat" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.InternalServerError": { + "type": "object", + "required": [ + "message", + "status" + ], + "properties": { + "message": { + "type": "string", + "example": "We ran into an internal error while handling the request." + }, + "status": { + "type": "string", + "example": "error" + } + } + }, + "responses.MessageResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.Message" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.MessageSendScheduleResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.MessageSendSchedule" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.MessageSendSchedulesResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.MessageSendSchedule" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.MessageThreadsResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.MessageThread" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.MessagesResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Message" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.NoContent": { + "type": "object", + "required": [ + "message", + "status" + ], + "properties": { + "message": { + "type": "string", + "example": "action performed successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.NotFound": { + "type": "object", + "required": [ + "message", + "status" + ], + "properties": { + "message": { + "type": "string", + "example": "cannot find message with ID [32343a19-da5e-4b1b-a767-3298a73703ca]" + }, + "status": { + "type": "string", + "example": "error" + } + } + }, + "responses.OkString": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "string" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.PaymentRequired": { + "type": "object", + "required": [ + "message", + "status" + ], + "properties": { + "message": { + "type": "string", + "example": "You have reached the maximum number of allowed resources. Please upgrade your plan." + }, + "status": { + "type": "string", + "example": "error" + } + } + }, + "responses.PhoneAPIKeyResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.PhoneAPIKey" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.PhoneAPIKeysResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.PhoneAPIKey" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.PhoneResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.Phone" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.PhonesResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Phone" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.Unauthorized": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "string", + "example": "Make sure your API key is set in the [X-API-Key] header in the request" + }, + "message": { + "type": "string", + "example": "You are not authorized to carry out this request." + }, + "status": { + "type": "string", + "example": "error" + } + } + }, + "responses.UnprocessableEntity": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "message": { + "type": "string", + "example": "validation errors while handling request" + }, + "status": { + "type": "string", + "example": "error" + } + } + }, + "responses.UserResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.User" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.UserSubscriptionPaymentsResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "type": "object", + "required": [ + "attributes", + "id", + "type" + ], + "properties": { + "attributes": { + "type": "object", + "required": [ + "billing_reason", + "card_brand", + "card_last_four", + "created_at", + "currency", + "currency_rate", + "discount_total", + "discount_total_formatted", + "discount_total_usd", + "refunded", + "refunded_amount", + "refunded_amount_formatted", + "refunded_amount_usd", + "refunded_at", + "status", + "status_formatted", + "subtotal", + "subtotal_formatted", + "subtotal_usd", + "tax", + "tax_formatted", + "tax_inclusive", + "tax_usd", + "total", + "total_formatted", + "total_usd", + "updated_at" + ], + "properties": { + "billing_reason": { + "type": "string" + }, + "card_brand": { + "type": "string" + }, + "card_last_four": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "currency": { + "type": "string" + }, + "currency_rate": { + "type": "string" + }, + "discount_total": { + "type": "integer" + }, + "discount_total_formatted": { + "type": "string" + }, + "discount_total_usd": { + "type": "integer" + }, + "refunded": { + "type": "boolean" + }, + "refunded_amount": { + "type": "integer" + }, + "refunded_amount_formatted": { + "type": "string" + }, + "refunded_amount_usd": { + "type": "integer" + }, + "refunded_at": {}, + "status": { + "type": "string" + }, + "status_formatted": { + "type": "string" + }, + "subtotal": { + "type": "integer" + }, + "subtotal_formatted": { + "type": "string" + }, + "subtotal_usd": { + "type": "integer" + }, + "tax": { + "type": "integer" + }, + "tax_formatted": { + "type": "string" + }, + "tax_inclusive": { + "type": "boolean" + }, + "tax_usd": { + "type": "integer" + }, + "total": { + "type": "integer" + }, + "total_formatted": { + "type": "string" + }, + "total_usd": { + "type": "integer" + }, + "updated_at": { + "type": "string" + } + } + }, + "id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.WebhookResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "$ref": "#/definitions/entities.Webhook" + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } + }, + "responses.WebhooksResponse": { + "type": "object", + "required": [ + "data", + "message", + "status" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Webhook" + } + }, + "message": { + "type": "string", + "example": "Request handled successfully" + }, + "status": { + "type": "string", + "example": "success" + } + } } - } }, - "responses.WebhooksResponse": { - "type": "object", - "required": ["data", "message", "status"], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/entities.Webhook" - } - }, - "message": { - "type": "string", - "example": "Request handled successfully" - }, - "status": { - "type": "string", - "example": "success" + "securityDefinitions": { + "ApiKeyAuth": { + "type": "apiKey", + "name": "x-api-Key", + "in": "header" } - } - } - }, - "securityDefinitions": { - "ApiKeyAuth": { - "type": "apiKey", - "name": "x-api-Key", - "in": "header" } - } } diff --git a/api/docs/swagger.yaml b/api/docs/swagger.yaml index a4124b82..4c6d0938 100644 --- a/api/docs/swagger.yaml +++ b/api/docs/swagger.yaml @@ -30,15 +30,51 @@ definitions: example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC type: string required: - - created_at - - end_timestamp - - id - - received_messages - - sent_messages - - start_timestamp - - total_cost - - updated_at - - user_id + - created_at + - end_timestamp + - id + - received_messages + - sent_messages + - start_timestamp + - total_cost + - updated_at + - user_id + type: object + entities.BulkMessage: + properties: + created_at: + example: "2022-06-05T14:26:02.302718+03:00" + type: string + delivered_count: + example: 25 + type: integer + failed_count: + example: 5 + type: integer + pending_count: + example: 30 + type: integer + request_id: + example: bulk-32343a19-da5e-4b1b-a767-3298a73703cb + type: string + scheduled_count: + example: 50 + type: integer + sent_count: + example: 40 + type: integer + total: + example: 150 + type: integer + required: + - created_at + - delivered_count + - failed_count + - pending_count + - request_id + - scheduled_count + - sent_count + - total type: object entities.Discord: properties: @@ -64,13 +100,13 @@ definitions: example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC type: string required: - - created_at - - id - - incoming_channel_id - - name - - server_id - - updated_at - - user_id + - created_at + - id + - incoming_channel_id + - name + - server_id + - updated_at + - user_id type: object entities.Heartbeat: properties: @@ -93,18 +129,22 @@ definitions: example: 344c10f type: string required: - - charging - - id - - owner - - timestamp - - user_id - - version + - charging + - id + - owner + - timestamp + - user_id + - version type: object entities.Message: properties: - can_be_polled: - example: false - type: boolean + attachments: + example: + - https://example.com/image.jpg + - https://example.com/video.mp4 + items: + type: string + type: array contact: example: "+18005550100" type: string @@ -163,8 +203,7 @@ definitions: example: 0 type: integer send_time: - description: - SendDuration is the number of nanoseconds from when the request + description: SendDuration is the number of nanoseconds from when the request was received until when the mobile phone send the message example: 133414 type: integer @@ -172,13 +211,14 @@ definitions: example: "2022-06-05T14:26:09.527976+03:00" type: string sim: + allOf: + - $ref: '#/definitions/entities.SIM' description: |- SIM is the SIM card to use to send the message * SMS1: use the SIM card in slot 1 * SMS2: use the SIM card in slot 2 * DEFAULT: used the default communication SIM card example: DEFAULT - type: string status: example: pending type: string @@ -192,33 +232,71 @@ definitions: example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC type: string required: - - can_be_polled - - contact - - content - - created_at - - delivered_at - - encrypted - - expired_at - - failed_at - - failure_reason - - id - - last_attempted_at - - max_send_attempts - - order_timestamp - - owner - - received_at - - request_id - - request_received_at - - scheduled_at - - scheduled_send_time - - send_attempt_count - - send_time - - sent_at - - sim - - status - - type - - updated_at - - user_id + - attachments + - contact + - content + - created_at + - encrypted + - id + - max_send_attempts + - order_timestamp + - owner + - request_received_at + - send_attempt_count + - sim + - status + - type + - updated_at + - user_id + type: object + entities.MessageSendSchedule: + properties: + created_at: + example: "2022-06-05T14:26:02.302718+03:00" + type: string + id: + example: 32343a19-da5e-4b1b-a767-3298a73703cb + type: string + name: + example: Business Hours + type: string + timezone: + example: Europe/Tallinn + type: string + updated_at: + example: "2022-06-05T14:26:10.303278+03:00" + type: string + user_id: + example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC + type: string + windows: + items: + $ref: '#/definitions/entities.MessageSendScheduleWindow' + type: array + required: + - created_at + - id + - name + - timezone + - updated_at + - user_id + - windows + type: object + entities.MessageSendScheduleWindow: + properties: + day_of_week: + example: 1 + type: integer + end_minute: + example: 1020 + type: integer + start_minute: + example: 540 + type: integer + required: + - day_of_week + - end_minute + - start_minute type: object entities.MessageThread: properties: @@ -259,18 +337,18 @@ definitions: example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC type: string required: - - color - - contact - - created_at - - id - - is_archived - - last_message_content - - last_message_id - - order_timestamp - - owner - - status - - updated_at - - user_id + - color + - contact + - created_at + - id + - is_archived + - last_message_content + - last_message_id + - order_timestamp + - owner + - status + - updated_at + - user_id type: object entities.Phone: properties: @@ -284,16 +362,17 @@ definitions: example: 32343a19-da5e-4b1b-a767-3298a73703cb type: string max_send_attempts: - description: - MaxSendAttempts determines how many times to retry sending an + description: MaxSendAttempts determines how many times to retry sending an SMS message example: 2 type: integer message_expiration_seconds: - description: - MessageExpirationSeconds is the duration in seconds after sending + description: MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired. type: integer + message_send_schedule_id: + example: 32343a19-da5e-4b1b-a767-3298a73703cb + type: string messages_per_minute: example: 1 type: integer @@ -304,8 +383,7 @@ definitions: example: "+18005550199" type: string sim: - description: SIM card that received the message - type: string + $ref: '#/definitions/entities.SIM' updated_at: example: "2022-06-05T14:26:10.303278+03:00" type: string @@ -313,17 +391,15 @@ definitions: example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC type: string required: - - created_at - - fcm_token - - id - - max_send_attempts - - message_expiration_seconds - - messages_per_minute - - missed_call_auto_reply - - phone_number - - sim - - updated_at - - user_id + - created_at + - id + - max_send_attempts + - message_expiration_seconds + - messages_per_minute + - phone_number + - sim + - updated_at + - user_id type: object entities.PhoneAPIKey: properties: @@ -341,15 +417,15 @@ definitions: type: string phone_ids: example: - - 32343a19-da5e-4b1b-a767-3298a73703cb - - 32343a19-da5e-4b1b-a767-3298a73703cc + - 32343a19-da5e-4b1b-a767-3298a73703cb + - 32343a19-da5e-4b1b-a767-3298a73703cc items: type: string type: array phone_numbers: example: - - "+18005550199" - - "+18005550100" + - "+18005550199" + - "+18005550100" items: type: string type: array @@ -363,16 +439,50 @@ definitions: example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC type: string required: - - api_key - - created_at - - id - - name - - phone_ids - - phone_numbers - - updated_at - - user_email - - user_id + - api_key + - created_at + - id + - name + - phone_ids + - phone_numbers + - updated_at + - user_email + - user_id type: object + entities.SIM: + enum: + - SIM1 + - SIM2 + type: string + x-enum-varnames: + - SIM1 + - SIM2 + entities.SubscriptionName: + enum: + - free + - pro-monthly + - pro-yearly + - ultra-monthly + - ultra-yearly + - pro-lifetime + - 20k-monthly + - 100k-monthly + - 50k-monthly + - 200k-monthly + - 20k-yearly + type: string + x-enum-varnames: + - SubscriptionNameFree + - SubscriptionNameProMonthly + - SubscriptionNameProYearly + - SubscriptionNameUltraMonthly + - SubscriptionNameUltraYearly + - SubscriptionNameProLifetime + - SubscriptionName20KMonthly + - SubscriptionName100KMonthly + - SubscriptionName50KMonthly + - SubscriptionName200KMonthly + - SubscriptionName20KYearly entities.User: properties: active_phone_id: @@ -409,8 +519,9 @@ definitions: example: 8f9c71b8-b84e-4417-8408-a62274f65a08 type: string subscription_name: + allOf: + - $ref: '#/definitions/entities.SubscriptionName' example: free - type: string subscription_renews_at: example: "2022-06-05T14:26:02.302718+03:00" type: string @@ -424,22 +535,18 @@ definitions: example: "2022-06-05T14:26:10.303278+03:00" type: string required: - - active_phone_id - - api_key - - created_at - - email - - id - - notification_heartbeat_enabled - - notification_message_status_enabled - - notification_newsletter_enabled - - notification_webhook_enabled - - subscription_ends_at - - subscription_id - - subscription_name - - subscription_renews_at - - subscription_status - - timezone - - updated_at + - api_key + - created_at + - email + - id + - notification_heartbeat_enabled + - notification_message_status_enabled + - notification_newsletter_enabled + - notification_webhook_enabled + - subscription_id + - subscription_name + - timezone + - updated_at type: object entities.Webhook: properties: @@ -448,7 +555,7 @@ definitions: type: string events: example: - - message.phone.received + - message.phone.received items: type: string type: array @@ -457,8 +564,8 @@ definitions: type: string phone_numbers: example: - - "+18005550199" - - "+18005550100" + - "+18005550199" + - "+18005550100" items: type: string type: array @@ -475,14 +582,14 @@ definitions: example: WB7DRDWrJZRGbYrv2CKGkqbzvqdC type: string required: - - created_at - - events - - id - - phone_numbers - - signing_key - - updated_at - - url - - user_id + - created_at + - events + - id + - phone_numbers + - signing_key + - updated_at + - url + - user_id type: object requests.DiscordStore: properties: @@ -493,9 +600,9 @@ definitions: server_id: type: string required: - - incoming_channel_id - - name - - server_id + - incoming_channel_id + - name + - server_id type: object requests.DiscordUpdate: properties: @@ -506,9 +613,9 @@ definitions: server_id: type: string required: - - incoming_channel_id - - name - - server_id + - incoming_channel_id + - name + - server_id type: object requests.HeartbeatStore: properties: @@ -519,17 +626,41 @@ definitions: type: string type: array required: - - charging - - phone_numbers + - charging + - phone_numbers + type: object + requests.MessageAttachment: + properties: + content: + description: Content is the base64-encoded attachment data + example: base64data... + type: string + content_type: + description: ContentType is the MIME type of the attachment + example: image/jpeg + type: string + name: + description: Name is the original filename of the attachment + example: photo.jpg + type: string + required: + - content + - content_type + - name type: object requests.MessageBulkSend: properties: + attachments: + description: Attachments are optional. When you provide a list of attachments, + the message will be sent out as an MMS + items: + type: string + type: array content: example: This is a sample text message type: string encrypted: - description: - Encrypted is used to determine if the content is end-to-end encrypted. + description: Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app example: false type: boolean @@ -537,23 +668,21 @@ definitions: example: "+18005550199" type: string request_id: - description: - RequestID is an optional parameter used to track a request from + description: RequestID is an optional parameter used to track a request from the client's perspective example: 153554b5-ae44-44a0-8f4f-7bbac5657ad4 type: string to: example: - - "+18005550100" - - "+18005550100" + - "+18005550100" + - "+18005550100" items: type: string type: array required: - - content - - encrypted - - from - - to + - content + - from + - to type: object requests.MessageCallMissed: properties: @@ -570,10 +699,10 @@ definitions: example: "+18005550100" type: string required: - - from - - sim - - timestamp - - to + - from + - sim + - timestamp + - to type: object requests.MessageEvent: properties: @@ -589,24 +718,28 @@ definitions: description: Reason is the exact error message in case the event is an error type: string timestamp: - description: - Timestamp is the time when the event was emitted, Please send + description: Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible example: "2022-06-05T14:26:09.527976+03:00" type: string required: - - event_name - - reason - - timestamp + - event_name + - reason + - timestamp type: object requests.MessageReceive: properties: + attachments: + description: Attachments is the list of MMS attachments received with the + message + items: + $ref: '#/definitions/requests.MessageAttachment' + type: array content: example: This is a sample text message received on a phone type: string encrypted: - description: - Encrypted is used to determine if the content is end-to-end encrypted. + description: Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app example: false type: boolean @@ -614,12 +747,12 @@ definitions: example: "+18005550199" type: string sim: + allOf: + - $ref: '#/definitions/entities.SIM' description: SIM card that received the message example: SIM1 - type: string timestamp: - description: - Timestamp is the time when the event was emitted, Please send + description: Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible example: "2022-06-05T14:26:09.527976+03:00" type: string @@ -627,21 +760,29 @@ definitions: example: "+18005550100" type: string required: - - content - - encrypted - - from - - sim - - timestamp - - to + - content + - encrypted + - from + - sim + - timestamp + - to type: object requests.MessageSend: properties: + attachments: + description: Attachments are optional. When you provide a list of attachments, + the message will be sent out as an MMS + example: + - https://example.com/image.jpg + - https://example.com/video.mp4 + items: + type: string + type: array content: example: This is a sample text message type: string encrypted: - description: - Encrypted is an optional parameter used to determine if the content + description: Encrypted is an optional parameter used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app example: false @@ -650,24 +791,52 @@ definitions: example: "+18005550199" type: string request_id: - description: - RequestID is an optional parameter used to track a request from + description: RequestID is an optional parameter used to track a request from the client's perspective example: 153554b5-ae44-44a0-8f4f-7bbac5657ad4 type: string send_at: - description: - SendAt is an optional parameter used to schedule a message to - be sent at a later time - example: "2022-06-05T14:26:09.527976+03:00" + description: SendAt is an optional parameter used to schedule a message to + be sent in the future. The time is considered to be in your profile's local + timezone and you can queue messages for up to 20 days (480 hours) in the + future. + example: "2025-12-19T16:39:57-08:00" type: string to: example: "+18005550100" type: string required: - - content - - from - - to + - content + - from + - to + type: object + requests.MessageSendScheduleStore: + properties: + name: + type: string + timezone: + type: string + windows: + items: + $ref: '#/definitions/requests.MessageSendScheduleWindow' + type: array + required: + - name + - timezone + - windows + type: object + requests.MessageSendScheduleWindow: + properties: + day_of_week: + type: integer + end_minute: + type: integer + start_minute: + type: integer + required: + - day_of_week + - end_minute + - start_minute type: object requests.MessageThreadUpdate: properties: @@ -675,7 +844,7 @@ definitions: example: true type: boolean required: - - is_archived + - is_archived type: object requests.PhoneAPIKeyStoreRequest: properties: @@ -683,7 +852,7 @@ definitions: example: My Phone API Key type: string required: - - name + - name type: object requests.PhoneFCMToken: properties: @@ -691,18 +860,17 @@ definitions: example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd..... type: string phone_number: - example: "[+18005550199]" + example: '[+18005550199]' type: string sim: - description: - SIM is the SIM slot of the phone in case the phone has more than + description: SIM is the SIM slot of the phone in case the phone has more than 1 SIM slot example: SIM1 type: string required: - - fcm_token - - phone_number - - sim + - fcm_token + - phone_number + - sim type: object requests.PhoneUpsert: properties: @@ -710,17 +878,18 @@ definitions: example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd..... type: string max_send_attempts: - description: - MaxSendAttempts is the number of attempts when sending an SMS + description: MaxSendAttempts is the number of attempts when sending an SMS message to handle the case where the phone is offline. example: 2 type: integer message_expiration_seconds: - description: - MessageExpirationSeconds is the duration in seconds after sending + description: MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired. example: 12345 type: integer + message_send_schedule_id: + example: 32343a19-da5e-4b1b-a767-3298a73703cb + type: string messages_per_minute: example: 1 type: integer @@ -731,19 +900,18 @@ definitions: example: "+18005550199" type: string sim: - description: - SIM is the SIM slot of the phone in case the phone has more than + description: SIM is the SIM slot of the phone in case the phone has more than 1 SIM slot example: SIM1 type: string required: - - fcm_token - - max_send_attempts - - message_expiration_seconds - - messages_per_minute - - missed_call_auto_reply - - phone_number - - sim + - fcm_token + - max_send_attempts + - message_expiration_seconds + - messages_per_minute + - missed_call_auto_reply + - phone_number + - sim type: object requests.UserNotificationUpdate: properties: @@ -760,10 +928,42 @@ definitions: example: true type: boolean required: - - heartbeat_enabled - - message_status_enabled - - newsletter_enabled - - webhook_enabled + - heartbeat_enabled + - message_status_enabled + - newsletter_enabled + - webhook_enabled + type: object + requests.UserPaymentInvoice: + properties: + address: + example: 221B Baker Street, London + type: string + city: + example: Los Angeles + type: string + country: + example: US + type: string + name: + example: Acme Corp + type: string + notes: + example: Thank you for your business! + type: string + state: + example: CA + type: string + zip_code: + example: "9800" + type: string + required: + - address + - city + - country + - name + - notes + - state + - zip_code type: object requests.UserUpdate: properties: @@ -774,8 +974,8 @@ definitions: example: Europe/Helsinki type: string required: - - active_phone_id - - timezone + - active_phone_id + - timezone type: object requests.WebhookStore: properties: @@ -785,8 +985,8 @@ definitions: type: array phone_numbers: example: - - "+18005550100" - - "+18005550100" + - "+18005550100" + - "+18005550100" items: type: string type: array @@ -795,10 +995,10 @@ definitions: url: type: string required: - - events - - phone_numbers - - signing_key - - url + - events + - phone_numbers + - signing_key + - url type: object requests.WebhookUpdate: properties: @@ -808,8 +1008,8 @@ definitions: type: array phone_numbers: example: - - "+18005550100" - - "+18005550100" + - "+18005550100" + - "+18005550100" items: type: string type: array @@ -818,10 +1018,10 @@ definitions: url: type: string required: - - events - - phone_numbers - - signing_key - - url + - events + - phone_numbers + - signing_key + - url type: object responses.BadRequest: properties: @@ -835,14 +1035,14 @@ definitions: example: error type: string required: - - data - - message - - status + - data + - message + - status type: object responses.BillingUsageResponse: properties: data: - $ref: "#/definitions/entities.BillingUsage" + $ref: '#/definitions/entities.BillingUsage' message: example: Request handled successfully type: string @@ -850,15 +1050,32 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.BillingUsagesResponse: properties: data: items: - $ref: "#/definitions/entities.BillingUsage" + $ref: '#/definitions/entities.BillingUsage' + type: array + message: + example: Request handled successfully + type: string + status: + example: success + type: string + required: + - data + - message + - status + type: object + responses.BulkMessagesResponse: + properties: + data: + items: + $ref: '#/definitions/entities.BulkMessage' type: array message: example: Request handled successfully @@ -867,14 +1084,14 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.DiscordResponse: properties: data: - $ref: "#/definitions/entities.Discord" + $ref: '#/definitions/entities.Discord' message: example: Request handled successfully type: string @@ -882,15 +1099,15 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.DiscordsResponse: properties: data: items: - $ref: "#/definitions/entities.Discord" + $ref: '#/definitions/entities.Discord' type: array message: example: Request handled successfully @@ -899,14 +1116,14 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.HeartbeatResponse: properties: data: - $ref: "#/definitions/entities.Heartbeat" + $ref: '#/definitions/entities.Heartbeat' message: example: Request handled successfully type: string @@ -914,15 +1131,15 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.HeartbeatsResponse: properties: data: items: - $ref: "#/definitions/entities.Heartbeat" + $ref: '#/definitions/entities.Heartbeat' type: array message: example: Request handled successfully @@ -931,9 +1148,9 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.InternalServerError: properties: @@ -944,13 +1161,45 @@ definitions: example: error type: string required: - - message - - status + - message + - status type: object responses.MessageResponse: properties: data: - $ref: "#/definitions/entities.Message" + $ref: '#/definitions/entities.Message' + message: + example: Request handled successfully + type: string + status: + example: success + type: string + required: + - data + - message + - status + type: object + responses.MessageSendScheduleResponse: + properties: + data: + $ref: '#/definitions/entities.MessageSendSchedule' + message: + example: Request handled successfully + type: string + status: + example: success + type: string + required: + - data + - message + - status + type: object + responses.MessageSendSchedulesResponse: + properties: + data: + items: + $ref: '#/definitions/entities.MessageSendSchedule' + type: array message: example: Request handled successfully type: string @@ -958,15 +1207,15 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.MessageThreadsResponse: properties: data: items: - $ref: "#/definitions/entities.MessageThread" + $ref: '#/definitions/entities.MessageThread' type: array message: example: Request handled successfully @@ -975,15 +1224,15 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.MessagesResponse: properties: data: items: - $ref: "#/definitions/entities.Message" + $ref: '#/definitions/entities.Message' type: array message: example: Request handled successfully @@ -992,9 +1241,9 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.NoContent: properties: @@ -1005,8 +1254,8 @@ definitions: example: success type: string required: - - message - - status + - message + - status type: object responses.NotFound: properties: @@ -1017,8 +1266,8 @@ definitions: example: error type: string required: - - message - - status + - message + - status type: object responses.OkString: properties: @@ -1031,14 +1280,27 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status + type: object + responses.PaymentRequired: + properties: + message: + example: You have reached the maximum number of allowed resources. Please + upgrade your plan. + type: string + status: + example: error + type: string + required: + - message + - status type: object responses.PhoneAPIKeyResponse: properties: data: - $ref: "#/definitions/entities.PhoneAPIKey" + $ref: '#/definitions/entities.PhoneAPIKey' message: example: Request handled successfully type: string @@ -1046,15 +1308,15 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.PhoneAPIKeysResponse: properties: data: items: - $ref: "#/definitions/entities.PhoneAPIKey" + $ref: '#/definitions/entities.PhoneAPIKey' type: array message: example: Request handled successfully @@ -1063,14 +1325,14 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.PhoneResponse: properties: data: - $ref: "#/definitions/entities.Phone" + $ref: '#/definitions/entities.Phone' message: example: Request handled successfully type: string @@ -1078,15 +1340,15 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.PhonesResponse: properties: data: items: - $ref: "#/definitions/entities.Phone" + $ref: '#/definitions/entities.Phone' type: array message: example: Request handled successfully @@ -1095,9 +1357,9 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.Unauthorized: properties: @@ -1111,9 +1373,9 @@ definitions: example: error type: string required: - - data - - message - - status + - data + - message + - status type: object responses.UnprocessableEntity: properties: @@ -1130,14 +1392,14 @@ definitions: example: error type: string required: - - data - - message - - status + - data + - message + - status type: object responses.UserResponse: properties: data: - $ref: "#/definitions/entities.User" + $ref: '#/definitions/entities.User' message: example: Request handled successfully type: string @@ -1145,14 +1407,124 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status + type: object + responses.UserSubscriptionPaymentsResponse: + properties: + data: + items: + properties: + attributes: + properties: + billing_reason: + type: string + card_brand: + type: string + card_last_four: + type: string + created_at: + type: string + currency: + type: string + currency_rate: + type: string + discount_total: + type: integer + discount_total_formatted: + type: string + discount_total_usd: + type: integer + refunded: + type: boolean + refunded_amount: + type: integer + refunded_amount_formatted: + type: string + refunded_amount_usd: + type: integer + refunded_at: {} + status: + type: string + status_formatted: + type: string + subtotal: + type: integer + subtotal_formatted: + type: string + subtotal_usd: + type: integer + tax: + type: integer + tax_formatted: + type: string + tax_inclusive: + type: boolean + tax_usd: + type: integer + total: + type: integer + total_formatted: + type: string + total_usd: + type: integer + updated_at: + type: string + required: + - billing_reason + - card_brand + - card_last_four + - created_at + - currency + - currency_rate + - discount_total + - discount_total_formatted + - discount_total_usd + - refunded + - refunded_amount + - refunded_amount_formatted + - refunded_amount_usd + - refunded_at + - status + - status_formatted + - subtotal + - subtotal_formatted + - subtotal_usd + - tax + - tax_formatted + - tax_inclusive + - tax_usd + - total + - total_formatted + - total_usd + - updated_at + type: object + id: + type: string + type: + type: string + required: + - attributes + - id + - type + type: object + type: array + message: + example: Request handled successfully + type: string + status: + example: success + type: string + required: + - data + - message + - status type: object responses.WebhookResponse: properties: data: - $ref: "#/definitions/entities.Webhook" + $ref: '#/definitions/entities.Webhook' message: example: Request handled successfully type: string @@ -1160,15 +1532,15 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object responses.WebhooksResponse: properties: data: items: - $ref: "#/definitions/entities.Webhook" + $ref: '#/definitions/entities.Webhook' type: array message: example: Request handled successfully @@ -1177,18 +1549,17 @@ definitions: example: success type: string required: - - data - - message - - status + - data + - message + - status type: object host: api.httpsms.com info: contact: email: support@httpsms.com - name: HTTP SMS - description: - API to send SMS messages using android [SmsManager](https://developer.android.com/reference/android/telephony/SmsManager) - via HTTP + name: support@httpsms.com + description: Use your Android phone to send and receive SMS messages via a simple + programmable API with end-to-end encryption. license: name: AGPL-3.0 url: https://raw.githubusercontent.com/NdoleStudio/http-sms-manager/main/LICENSE @@ -1198,1842 +1569,2143 @@ paths: /billing/usage: get: consumes: - - application/json - description: - Get the summary of sent and received messages for a user in the + - application/json + description: Get the summary of sent and received messages for a user in the current month produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.BillingUsageResponse" + $ref: '#/definitions/responses.BillingUsageResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get Billing Usage. tags: - - Billing + - Billing /billing/usage-history: get: consumes: - - application/json - description: - Get billing usage records of sent and received messages for a user + - application/json + description: Get billing usage records of sent and received messages for a user in the past. It will be sorted by timestamp in descending order. parameters: - - description: number of heartbeats to skip - in: query - minimum: 0 - name: skip - type: integer - - description: number of heartbeats to return - in: query - maximum: 100 - minimum: 1 - name: limit - type: integer + - description: number of heartbeats to skip + in: query + minimum: 0 + name: skip + type: integer + - description: number of heartbeats to return + in: query + maximum: 100 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.BillingUsagesResponse" + $ref: '#/definitions/responses.BillingUsagesResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get billing usage history. tags: - - Billing + - Billing /bulk-messages: + get: + consumes: + - application/json + description: Fetches the last 10 bulk message order summaries for the authenticated + user showing counts per status. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/responses.BulkMessagesResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: List bulk message orders + tags: + - BulkSMS post: consumes: - - application/json - description: Sends bulk SMS messages to multiple users from a CSV file. + - multipart/form-data + description: Sends bulk SMS messages to multiple users based on our [CSV template](https://httpsms.com/templates/httpsms-bulk.csv) + or our [Excel template](https://httpsms.com/templates/httpsms-bulk.xlsx). + parameters: + - description: The Excel or CSV file containing the messages to be sent. + in: formData + name: document + required: true + type: file produces: - - application/json + - application/json responses: "202": description: Accepted schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Store bulk SMS file tags: - - BulkSMS + - BulkSMS /discord-integrations: get: consumes: - - application/json + - application/json description: Get the discord integrations of a user parameters: - - description: number of discord integrations to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter discord integrations containing query - in: query - name: query - type: string - - description: number of discord integrations to return - in: query - maximum: 20 - minimum: 1 - name: limit - type: integer + - description: number of discord integrations to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter discord integrations containing query + in: query + name: query + type: string + - description: number of discord integrations to return + in: query + maximum: 20 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.DiscordsResponse" + $ref: '#/definitions/responses.DiscordsResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get discord integrations of a user tags: - - DiscordIntegration + - DiscordIntegration post: consumes: - - application/json + - application/json description: Store a discord integration for the authenticated user parameters: - - description: Payload of the discord integration request - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.DiscordStore" + - description: Payload of the discord integration request + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.DiscordStore' produces: - - application/json + - application/json responses: "201": description: Created schema: - $ref: "#/definitions/responses.DiscordResponse" + $ref: '#/definitions/responses.DiscordResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Store discord integration tags: - - DiscordIntegration + - DiscordIntegration /discord-integrations/{discordID}: delete: consumes: - - application/json + - application/json description: Delete a discord integration for a user parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the discord integration - in: path - name: discordID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the discord integration + in: path + name: discordID + required: true + type: string produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Delete discord integration tags: - - Webhooks + - Webhooks put: consumes: - - application/json + - application/json description: Update a discord integration for the currently authenticated user parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the discord integration - in: path - name: discordID - required: true - type: string - - description: Payload of discord integration to update - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.DiscordUpdate" + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the discord integration + in: path + name: discordID + required: true + type: string + - description: Payload of discord integration to update + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.DiscordUpdate' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.DiscordResponse" + $ref: '#/definitions/responses.DiscordResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Update a discord integration tags: - - DiscordIntegration + - DiscordIntegration /discord/event: post: consumes: - - application/json + - application/json description: Publish a discord event to the registered listeners produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' summary: Consume a discord event tags: - - Discord + - Discord /heartbeats: get: consumes: - - application/json - description: - Get the last time a phone number requested for outstanding messages. + - application/json + description: Get the last time a phone number requested for outstanding messages. It will be sorted by timestamp in descending order. parameters: - - default: "+18005550199" - description: the owner's phone number - in: query - name: owner - required: true - type: string - - description: number of heartbeats to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter containing query - in: query - name: query - type: string - - description: number of heartbeats to return - in: query - maximum: 20 - minimum: 1 - name: limit - type: integer + - default: "+18005550199" + description: the owner's phone number + in: query + name: owner + required: true + type: string + - description: number of heartbeats to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter containing query + in: query + name: query + type: string + - description: number of heartbeats to return + in: query + maximum: 20 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.HeartbeatsResponse" + $ref: '#/definitions/responses.HeartbeatsResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get heartbeats of an owner phone number tags: - - Heartbeats + - Heartbeats post: consumes: - - application/json - description: - Store the heartbeat to make notify that a phone number is still + - application/json + description: Store the heartbeat to make notify that a phone number is still active parameters: - - description: Payload of the heartbeat request - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.HeartbeatStore" + - description: Payload of the heartbeat request + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.HeartbeatStore' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.HeartbeatResponse" + $ref: '#/definitions/responses.HeartbeatResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Register heartbeat of an owner phone number tags: - - Heartbeats + - Heartbeats /integration/3cx/messages: post: consumes: - - application/json + - application/json description: Sends an SMS message from the 3CX platform produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' summary: Sends a 3CX SMS message tags: - - 3CXIntegration - /lemonsqueezy/event: - post: - consumes: - - application/json - description: Publish a lemonsqueezy event to the registered listeners - produces: - - application/json - responses: - "204": - description: No Content - schema: - $ref: "#/definitions/responses.NoContent" - "400": - description: Bad Request - schema: - $ref: "#/definitions/responses.BadRequest" - "401": - description: Unauthorized - schema: - $ref: "#/definitions/responses.Unauthorized" - "422": - description: Unprocessable Entity - schema: - $ref: "#/definitions/responses.UnprocessableEntity" - "500": - description: Internal Server Error - schema: - $ref: "#/definitions/responses.InternalServerError" - summary: Consume a lemonsqueezy event - tags: - - Lemonsqueezy + - 3CXIntegration /message-threads: get: consumes: - - application/json - description: - Get list of contacts which a phone number has communicated with + - application/json + description: Get list of contacts which a phone number has communicated with (threads). It will be sorted by timestamp in descending order. parameters: - - default: "+18005550199" - description: owner phone number - in: query - name: owner - required: true - type: string - - description: number of messages to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter message threads containing query - in: query - name: query - type: string - - description: number of messages to return - in: query - maximum: 20 - minimum: 1 - name: limit - type: integer + - default: "+18005550199" + description: owner phone number + in: query + name: owner + required: true + type: string + - description: number of messages to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter message threads containing query + in: query + name: query + type: string + - description: number of messages to return + in: query + maximum: 20 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessageThreadsResponse" + $ref: '#/definitions/responses.MessageThreadsResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get message threads for a phone number tags: - - MessageThreads + - MessageThreads /message-threads/{messageThreadID}: delete: consumes: - - application/json - description: - Delete a message thread from the database and also deletes all + - application/json + description: Delete a message thread from the database and also deletes all the messages in the thread. parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the message thread - in: path - name: messageThreadID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the message thread + in: path + name: messageThreadID + required: true + type: string produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "404": description: Not Found schema: - $ref: "#/definitions/responses.NotFound" + $ref: '#/definitions/responses.NotFound' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Delete a message thread from the database. tags: - - MessageThreads + - MessageThreads put: consumes: - - application/json + - application/json description: Updates the details of a message thread parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the message thread - in: path - name: messageThreadID - required: true - type: string - - description: Payload of message thread details to update - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.MessageThreadUpdate" + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the message thread + in: path + name: messageThreadID + required: true + type: string + - description: Payload of message thread details to update + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageThreadUpdate' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.PhoneResponse" + $ref: '#/definitions/responses.PhoneResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Update a message thread tags: - - MessageThreads + - MessageThreads /messages: get: consumes: - - application/json - description: - Get list of messages which are sent between 2 phone numbers. It + - application/json + description: Get list of messages which are sent between 2 phone numbers. It will be sorted by timestamp in descending order. parameters: - - default: "+18005550199" - description: the owner's phone number - in: query - name: owner - required: true - type: string - - default: "+18005550100" - description: the contact's phone number - in: query - name: contact - required: true - type: string - - description: number of messages to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter messages containing query - in: query - name: query - type: string - - description: number of messages to return - in: query - maximum: 20 - minimum: 1 - name: limit - type: integer + - default: "+18005550199" + description: the owner's phone number + in: query + name: owner + required: true + type: string + - default: "+18005550100" + description: the contact's phone number + in: query + name: contact + required: true + type: string + - description: number of messages to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter messages containing query + in: query + name: query + type: string + - description: number of messages to return + in: query + maximum: 20 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessagesResponse" + $ref: '#/definitions/responses.MessagesResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get messages which are sent between 2 phone numbers tags: - - Messages + - Messages /messages/{messageID}: delete: consumes: - - application/json - description: - Delete a message from the database and removes the message content + - application/json + description: Delete a message from the database and removes the message content from the list of threads. parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the message - in: path - name: messageID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the message + in: path + name: messageID + required: true + type: string produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "404": description: Not Found schema: - $ref: "#/definitions/responses.NotFound" + $ref: '#/definitions/responses.NotFound' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Delete a message from the database. tags: - - Messages + - Messages + get: + consumes: + - application/json + description: Get a message from the database by the message ID. + parameters: + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the message + in: path + name: messageID + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + schema: + $ref: '#/definitions/responses.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/responses.BadRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "404": + description: Not Found + schema: + $ref: '#/definitions/responses.NotFound' + "422": + description: Unprocessable Entity + schema: + $ref: '#/definitions/responses.UnprocessableEntity' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: Get a message from the database. + tags: + - Messages /messages/{messageID}/events: post: consumes: - - application/json - description: - Use this endpoint to send events for a message when it is failed, + - application/json + description: Use this endpoint to send events for a message when it is failed, sent or delivered by the mobile phone. parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the message - in: path - name: messageID - required: true - type: string - - description: Payload of the event emitted. - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.MessageEvent" + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the message + in: path + name: messageID + required: true + type: string + - description: Payload of the event emitted. + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageEvent' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessageResponse" + $ref: '#/definitions/responses.MessageResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "404": description: Not Found schema: - $ref: "#/definitions/responses.NotFound" + $ref: '#/definitions/responses.NotFound' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Upsert an event for a message on the mobile phone tags: - - Messages + - Messages /messages/bulk-send: post: consumes: - - application/json + - application/json description: Add bulk SMS messages to be sent by the android phone parameters: - - description: Bulk send message request payload - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.MessageBulkSend" + - description: Bulk send message request payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageBulkSend' produces: - - application/json + - application/json responses: "200": description: OK schema: items: - $ref: "#/definitions/responses.MessagesResponse" + $ref: '#/definitions/responses.MessagesResponse' type: array "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Send bulk SMS messages tags: - - Messages + - Messages /messages/calls/missed: post: consumes: - - application/json - description: - This endpoint is called by the httpSMS android app to register + - application/json + description: This endpoint is called by the httpSMS android app to register a missed call event on the mobile phone. parameters: - - description: Payload of the missed call event. - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.MessageCallMissed" + - description: Payload of the missed call event. + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageCallMissed' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessageResponse" + $ref: '#/definitions/responses.MessageResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "404": description: Not Found schema: - $ref: "#/definitions/responses.NotFound" + $ref: '#/definitions/responses.NotFound' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Register a missed call event on the mobile phone tags: - - Messages + - Messages /messages/outstanding: get: consumes: - - application/json + - application/json description: Get an outstanding message to be sent by an android phone parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703cb - description: The ID of the message - in: query - name: message_id - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703cb + description: The ID of the message + in: query + name: message_id + required: true + type: string produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessageResponse" + $ref: '#/definitions/responses.MessageResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get an outstanding message tags: - - Messages + - Messages /messages/receive: post: consumes: - - application/json + - application/json description: Add a new message received from a mobile phone parameters: - - description: Received message request payload - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.MessageReceive" + - description: Received message request payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageReceive' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessageResponse" + $ref: '#/definitions/responses.MessageResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Receive a new SMS message from a mobile phone tags: - - Messages + - Messages /messages/search: get: consumes: - - application/json - description: - This returns the list of all messages based on the filter criteria + - application/json + description: This returns the list of all messages based on the filter criteria including missed calls parameters: - - description: Cloudflare turnstile token https://www.cloudflare.com/en-gb/application-services/products/turnstile/ - in: header - name: token - required: true - type: string - - default: +18005550199,+18005550100 - description: the owner's phone numbers - in: query - name: owners - required: true - type: string - - description: number of messages to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter messages containing query - in: query - name: query - type: string - - description: number of messages to return - in: query - maximum: 200 - minimum: 1 - name: limit - type: integer + - description: Cloudflare turnstile token https://www.cloudflare.com/en-gb/application-services/products/turnstile/ + in: header + name: token + required: true + type: string + - default: +18005550199,+18005550100 + description: the owner's phone numbers + in: query + name: owners + required: true + type: string + - description: number of messages to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter messages containing query + in: query + name: query + type: string + - description: number of messages to return + in: query + maximum: 200 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessagesResponse" + $ref: '#/definitions/responses.MessagesResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Search all messages of a user tags: - - Messages + - Messages /messages/send: post: consumes: - - application/json - description: Add a new SMS message to be sent by the android phone + - application/json + description: Add a new SMS message to be sent by your Android phone parameters: - - description: PostSend message request payload - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.MessageSend" + - description: Send message request payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageSend' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.MessageResponse" + $ref: '#/definitions/responses.MessageResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] - summary: Send a new SMS message + - ApiKeyAuth: [] + summary: Send an SMS message tags: - - Messages + - Messages /phone-api-keys: get: consumes: - - application/json - description: - Get list phone API keys which a user has registered on the httpSMS + - application/json + description: Get list phone API keys which a user has registered on the httpSMS application parameters: - - description: number of phone api keys to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter phone api keys with name containing query - in: query - name: query - type: string - - description: number of phone api keys to return - in: query - maximum: 100 - minimum: 1 - name: limit - type: integer + - description: number of phone api keys to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter phone api keys with name containing query + in: query + name: query + type: string + - description: number of phone api keys to return + in: query + maximum: 100 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.PhoneAPIKeysResponse" + $ref: '#/definitions/responses.PhoneAPIKeysResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get the phone API keys of a user tags: - - PhoneAPIKeys + - PhoneAPIKeys post: consumes: - - application/json - description: - Creates a new phone API key which can be used to log in to the + - application/json + description: Creates a new phone API key which can be used to log in to the httpSMS app on your Android phone parameters: - - description: Payload of new phone API key. - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.PhoneAPIKeyStoreRequest" + - description: Payload of new phone API key. + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.PhoneAPIKeyStoreRequest' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.PhoneAPIKeyResponse" + $ref: '#/definitions/responses.PhoneAPIKeyResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' + "402": + description: Payment Required + schema: + $ref: '#/definitions/responses.PaymentRequired' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Store phone API key tags: - - PhoneAPIKeys + - PhoneAPIKeys /phone-api-keys/{phoneAPIKeyID}: delete: consumes: - - application/json - description: - Delete a phone API Key from the database and cannot be used for + - application/json + description: Delete a phone API Key from the database and cannot be used for authentication anymore. parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the phone API key - in: path - name: phoneAPIKeyID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the phone API key + in: path + name: phoneAPIKeyID + required: true + type: string produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "404": description: Not Found schema: - $ref: "#/definitions/responses.NotFound" + $ref: '#/definitions/responses.NotFound' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Delete a phone API key from the database. tags: - - PhoneAPIKeys + - PhoneAPIKeys /phone-api-keys/{phoneAPIKeyID}/phones/{phoneID}: delete: consumes: - - application/json - description: - You will need to login again to the httpSMS app on your Android + - application/json + description: You will need to login again to the httpSMS app on your Android phone with a new phone API key. parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the phone API key - in: path - name: phoneAPIKeyID - required: true - type: string - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the phone - in: path - name: phoneID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the phone API key + in: path + name: phoneAPIKeyID + required: true + type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the phone + in: path + name: phoneID + required: true + type: string produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "404": description: Not Found schema: - $ref: "#/definitions/responses.NotFound" + $ref: '#/definitions/responses.NotFound' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Remove the association of a phone from the phone API key. tags: - - PhoneAPIKeys + - PhoneAPIKeys /phones: get: consumes: - - application/json - description: - Get list of phones which a user has registered on the http sms + - application/json + description: Get list of phones which a user has registered on the http sms application parameters: - - description: number of heartbeats to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter phones containing query - in: query - name: query - type: string - - description: number of phones to return - in: query - maximum: 20 - minimum: 1 - name: limit - type: integer + - description: number of heartbeats to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter phones containing query + in: query + name: query + type: string + - description: number of phones to return + in: query + maximum: 20 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.PhonesResponse" + $ref: '#/definitions/responses.PhonesResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get phones of a user tags: - - Phones + - Phones put: consumes: - - application/json - description: - Updates properties of a user's phone. If the phone with this number + - application/json + description: Updates properties of a user's phone. If the phone with this number does not exist, a new one will be created. Think of this method like an 'upsert' parameters: - - description: Payload of new phone number. - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.PhoneUpsert" + - description: Payload of new phone number. + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.PhoneUpsert' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.PhoneResponse" + $ref: '#/definitions/responses.PhoneResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Upsert Phone tags: - - Phones + - Phones /phones/{phoneID}: delete: consumes: - - application/json + - application/json description: Delete a phone that has been sored in the database parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the phone - in: path - name: phoneID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the phone + in: path + name: phoneID + required: true + type: string produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Delete Phone tags: - - Phones + - Phones /phones/fcm-token: put: consumes: - - application/json - description: - Updates the FCM token of a phone. If the phone with this number + - application/json + description: Updates the FCM token of a phone. If the phone with this number does not exist, a new one will be created. Think of this method like an 'upsert' parameters: - - description: Payload of new FCM token. - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.PhoneFCMToken" + - description: Payload of new FCM token. + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.PhoneFCMToken' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.PhoneResponse" + $ref: '#/definitions/responses.PhoneResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Upserts the FCM token of a phone tags: - - Phones + - Phones + /send-schedules: + get: + description: List all send schedules owned by the authenticated user. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/responses.MessageSendSchedulesResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: List send schedules + tags: + - SendSchedules + post: + consumes: + - application/json + description: Create a new send schedule for the authenticated user. + parameters: + - description: Payload of new send schedule. + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageSendScheduleStore' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/responses.MessageSendScheduleResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/responses.BadRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "402": + description: Payment Required + schema: + $ref: '#/definitions/responses.PaymentRequired' + "422": + description: Unprocessable Entity + schema: + $ref: '#/definitions/responses.UnprocessableEntity' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: Create send schedule + tags: + - SendSchedules + /send-schedules/{scheduleID}: + delete: + description: Delete a send schedule owned by the authenticated user. + parameters: + - description: Schedule ID + in: path + name: scheduleID + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + "400": + description: Bad Request + schema: + $ref: '#/definitions/responses.BadRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "404": + description: Not Found + schema: + $ref: '#/definitions/responses.NotFound' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: Delete send schedule + tags: + - SendSchedules + put: + consumes: + - application/json + description: Update a send schedule owned by the authenticated user. + parameters: + - description: Schedule ID + in: path + name: scheduleID + required: true + type: string + - description: Payload of updated send schedule. + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.MessageSendScheduleStore' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/responses.MessageSendScheduleResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/responses.BadRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "404": + description: Not Found + schema: + $ref: '#/definitions/responses.NotFound' + "422": + description: Unprocessable Entity + schema: + $ref: '#/definitions/responses.UnprocessableEntity' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: Update send schedule + tags: + - SendSchedules /users/{userID}/api-keys: delete: consumes: - - application/json + - application/json description: Rotate the user's API key in case the current API Key is compromised parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the user to update - in: path - name: userID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the user to update + in: path + name: userID + required: true + type: string produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.UserResponse" + $ref: '#/definitions/responses.UserResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Rotate the user's API Key tags: - - Users + - Users /users/{userID}/notifications: put: consumes: - - application/json + - application/json description: Update the email notification settings for a user parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the user to update - in: path - name: userID - required: true - type: string - - description: User notification details to update - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.UserNotificationUpdate" + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the user to update + in: path + name: userID + required: true + type: string + - description: User notification details to update + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.UserNotificationUpdate' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.UserResponse" + $ref: '#/definitions/responses.UserResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Update notification settings tags: - - Users + - Users /users/me: delete: consumes: - - application/json - description: - Deletes the currently authenticated user together with all their + - application/json + description: Deletes the currently authenticated user together with all their data. produces: - - application/json + - application/json responses: "201": description: Created schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Delete a user tags: - - Users + - Users get: consumes: - - application/json + - application/json description: Get details of the currently authenticated user produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.UserResponse" + $ref: '#/definitions/responses.UserResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get current user tags: - - Users + - Users put: consumes: - - application/json + - application/json description: Updates the details of the currently authenticated user parameters: - - description: Payload of user details to update - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.UserUpdate" + - description: Payload of user details to update + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.UserUpdate' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.PhoneResponse" + $ref: '#/definitions/responses.PhoneResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Update a user tags: - - Users + - Users /users/subscription: delete: description: Cancel the subscription of the authenticated user. produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Cancel the user's subscription tags: - - Users + - Users /users/subscription-update-url: get: description: Fetches the subscription URL of the authenticated user. produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.OkString" + $ref: '#/definitions/responses.OkString' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Currently authenticated user subscription update URL tags: - - Users + - Users + /users/subscription/invoices/{subscriptionInvoiceID}: + post: + consumes: + - application/json + description: Generates a new invoice PDF file for the given subscription payment + with given parameters. + parameters: + - description: Generate subscription payment invoice parameters + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.UserPaymentInvoice' + - description: ID of the subscription invoice to generate the PDF for + in: path + name: subscriptionInvoiceID + required: true + type: string + produces: + - application/pdf + responses: + "200": + description: OK + schema: + type: file + "400": + description: Bad Request + schema: + $ref: '#/definitions/responses.BadRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "422": + description: Unprocessable Entity + schema: + $ref: '#/definitions/responses.UnprocessableEntity' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: Generate a subscription payment invoice + tags: + - Users + /users/subscription/payments: + get: + consumes: + - application/json + description: Subscription payments are generated throughout the lifecycle of + a subscription, typically there is one at the time of purchase and then one + for each renewal. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/responses.UserSubscriptionPaymentsResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/responses.BadRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/responses.Unauthorized' + "422": + description: Unprocessable Entity + schema: + $ref: '#/definitions/responses.UnprocessableEntity' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + security: + - ApiKeyAuth: [] + summary: Get the last 10 subscription payments. + tags: + - Users + /v1/attachments/{userID}/{messageID}/{attachmentIndex}/{filename}: + get: + description: Download an MMS attachment by its path components + parameters: + - description: User ID + in: path + name: userID + required: true + type: string + - description: Message ID + in: path + name: messageID + required: true + type: string + - description: Attachment index + in: path + name: attachmentIndex + required: true + type: string + - description: Filename with extension + in: path + name: filename + required: true + type: string + produces: + - application/octet-stream + responses: + "200": + description: OK + schema: + type: file + "404": + description: Not Found + schema: + $ref: '#/definitions/responses.NotFound' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.InternalServerError' + summary: Download a message attachment + tags: + - Attachments /webhooks: get: consumes: - - application/json + - application/json description: Get the webhooks of a user parameters: - - description: number of webhooks to skip - in: query - minimum: 0 - name: skip - type: integer - - description: filter webhooks containing query - in: query - name: query - type: string - - description: number of webhooks to return - in: query - maximum: 20 - minimum: 1 - name: limit - type: integer + - description: number of webhooks to skip + in: query + minimum: 0 + name: skip + type: integer + - description: filter webhooks containing query + in: query + name: query + type: string + - description: number of webhooks to return + in: query + maximum: 20 + minimum: 1 + name: limit + type: integer produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.WebhooksResponse" + $ref: '#/definitions/responses.WebhooksResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Get webhooks of a user tags: - - Webhooks + - Webhooks post: consumes: - - application/json + - application/json description: Store a webhook for the authenticated user parameters: - - description: Payload of the webhook request - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.WebhookStore" + - description: Payload of the webhook request + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.WebhookStore' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.WebhookResponse" + $ref: '#/definitions/responses.WebhookResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Store a webhook tags: - - Webhooks + - Webhooks /webhooks/{webhookID}: delete: consumes: - - application/json + - application/json description: Delete a webhook for a user parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the webhook - in: path - name: webhookID - required: true - type: string + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the webhook + in: path + name: webhookID + required: true + type: string produces: - - application/json + - application/json responses: "204": description: No Content schema: - $ref: "#/definitions/responses.NoContent" + $ref: '#/definitions/responses.NoContent' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Delete webhook tags: - - Webhooks + - Webhooks put: consumes: - - application/json + - application/json description: Update a webhook for the currently authenticated user parameters: - - default: 32343a19-da5e-4b1b-a767-3298a73703ca - description: ID of the webhook - in: path - name: webhookID - required: true - type: string - - description: Payload of webhook details to update - in: body - name: payload - required: true - schema: - $ref: "#/definitions/requests.WebhookUpdate" + - default: 32343a19-da5e-4b1b-a767-3298a73703ca + description: ID of the webhook + in: path + name: webhookID + required: true + type: string + - description: Payload of webhook details to update + in: body + name: payload + required: true + schema: + $ref: '#/definitions/requests.WebhookUpdate' produces: - - application/json + - application/json responses: "200": description: OK schema: - $ref: "#/definitions/responses.WebhookResponse" + $ref: '#/definitions/responses.WebhookResponse' "400": description: Bad Request schema: - $ref: "#/definitions/responses.BadRequest" + $ref: '#/definitions/responses.BadRequest' "401": description: Unauthorized schema: - $ref: "#/definitions/responses.Unauthorized" + $ref: '#/definitions/responses.Unauthorized' "422": description: Unprocessable Entity schema: - $ref: "#/definitions/responses.UnprocessableEntity" + $ref: '#/definitions/responses.UnprocessableEntity' "500": description: Internal Server Error schema: - $ref: "#/definitions/responses.InternalServerError" + $ref: '#/definitions/responses.InternalServerError' security: - - ApiKeyAuth: [] + - ApiKeyAuth: [] summary: Update a webhook tags: - - Webhooks + - Webhooks schemes: - - https +- https securityDefinitions: ApiKeyAuth: in: header diff --git a/api/go.mod b/api/go.mod index 99b4fef7..754baa14 100644 --- a/api/go.mod +++ b/api/go.mod @@ -1,187 +1,208 @@ module github.com/NdoleStudio/httpsms -go 1.24.2 - -toolchain go1.24.3 +go 1.25.0 require ( - cloud.google.com/go/cloudtasks v1.13.6 + cloud.google.com/go/cloudtasks v1.17.0 + cloud.google.com/go/storage v1.62.1 firebase.google.com/go v3.13.0+incompatible - github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0 - github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.27.0 - github.com/NdoleStudio/go-otelroundtripper v0.0.11 - github.com/NdoleStudio/lemonsqueezy-go v1.2.4 - github.com/avast/retry-go v3.0.0+incompatible - github.com/carlmjohnson/requests v0.24.3 - github.com/cloudevents/sdk-go/v2 v2.16.0 - github.com/cockroachdb/cockroach-go/v2 v2.4.0 - github.com/davecgh/go-spew v1.1.1 - github.com/dgraph-io/ristretto v1.0.0 + github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.56.0 + github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.32.0 + github.com/NdoleStudio/go-otelroundtripper v0.0.14 + github.com/NdoleStudio/lemonsqueezy-go v1.3.1 + github.com/NdoleStudio/plunk-go v0.0.2 + github.com/avast/retry-go/v5 v5.0.0 + github.com/carlmjohnson/requests v0.25.1 + github.com/cloudevents/sdk-go/v2 v2.16.2 + github.com/cockroachdb/cockroach-go/v2 v2.4.3 + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc + github.com/dgraph-io/ristretto/v2 v2.4.0 github.com/dustin/go-humanize v1.0.1 + github.com/gertd/go-pluralize v0.2.1 + github.com/go-hermes/hermes/v2 v2.6.2 github.com/gofiber/contrib/otelfiber v1.0.10 - github.com/gofiber/fiber/v2 v2.52.7 + github.com/gofiber/fiber/v2 v2.52.13 github.com/gofiber/swagger v1.1.1 - github.com/golang-jwt/jwt v3.2.2+incompatible + github.com/golang-jwt/jwt/v5 v5.3.1 github.com/google/uuid v1.6.0 - github.com/hashicorp/go-retryablehttp v0.7.7 + github.com/hashicorp/go-retryablehttp v0.7.8 github.com/hirosassa/zerodriver v0.1.4 - github.com/jaswdr/faker/v2 v2.4.0 + github.com/jaswdr/faker/v2 v2.9.1 github.com/jinzhu/now v1.1.5 github.com/joho/godotenv v1.5.1 github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible github.com/jszwec/csvutil v1.10.0 - github.com/lib/pq v1.10.9 - github.com/matcornic/hermes v1.3.0 - github.com/nyaruka/phonenumbers v1.6.1 + github.com/lib/pq v1.12.3 + github.com/matoous/go-nanoid/v2 v2.1.0 + github.com/nyaruka/phonenumbers v1.7.2 github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 github.com/pusher/pusher-http-go/v5 v5.1.1 - github.com/redis/go-redis/extra/redisotel/v9 v9.8.0 - github.com/redis/go-redis/v9 v9.8.0 - github.com/rs/zerolog v1.34.0 - github.com/sendgrid/sendgrid-go v3.16.0+incompatible - github.com/stretchr/testify v1.10.0 - github.com/swaggo/swag v1.16.4 + github.com/redis/go-redis/extra/redisotel/v9 v9.19.0 + github.com/redis/go-redis/v9 v9.19.0 + github.com/rs/zerolog v1.35.1 + github.com/stretchr/testify v1.11.1 + github.com/swaggo/swag v1.16.6 github.com/thedevsaddam/govalidator v1.9.10 - github.com/uptrace/uptrace-go v1.35.1 - github.com/xuri/excelize/v2 v2.9.0 - go.opentelemetry.io/otel v1.35.0 - go.opentelemetry.io/otel/metric v1.35.0 - go.opentelemetry.io/otel/sdk v1.35.0 - go.opentelemetry.io/otel/sdk/metric v1.35.0 - go.opentelemetry.io/otel/trace v1.35.0 - google.golang.org/api v0.231.0 - google.golang.org/protobuf v1.36.6 - gorm.io/driver/postgres v1.5.11 - gorm.io/gorm v1.26.0 - gorm.io/plugin/opentelemetry v0.1.13 + github.com/uptrace/uptrace-go v1.43.0 + github.com/xuri/excelize/v2 v2.10.1 + go.mongodb.org/mongo-driver/v2 v2.6.0 + go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo v0.0.0-20260513205827-ba143fc95a5e + go.opentelemetry.io/otel v1.43.0 + go.opentelemetry.io/otel/metric v1.43.0 + go.opentelemetry.io/otel/sdk v1.43.0 + go.opentelemetry.io/otel/sdk/metric v1.43.0 + go.opentelemetry.io/otel/trace v1.43.0 + golang.org/x/sync v0.20.0 + google.golang.org/api v0.277.0 + google.golang.org/protobuf v1.36.11 + gorm.io/driver/postgres v1.6.0 + gorm.io/gorm v1.31.1 + gorm.io/plugin/opentelemetry v0.1.16 +) + +require ( + github.com/Masterminds/semver/v3 v3.5.0 // indirect + github.com/Masterminds/sprig/v3 v3.3.0 // indirect + github.com/inbucket/html2text v1.0.0 // indirect + github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect + github.com/olekukonko/errors v1.3.0 // indirect + github.com/olekukonko/ll v0.1.8 // indirect + github.com/sirupsen/logrus v1.9.4 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/yuin/goldmark v1.8.2 // indirect ) require ( - cel.dev/expr v0.20.0 // indirect - cloud.google.com/go v0.120.0 // indirect - cloud.google.com/go/auth v0.16.1 // indirect + cel.dev/expr v0.25.1 // indirect + cloud.google.com/go v0.123.0 // indirect + cloud.google.com/go/auth v0.20.0 // indirect cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect - cloud.google.com/go/compute/metadata v0.6.0 // indirect - cloud.google.com/go/firestore v1.18.0 // indirect - cloud.google.com/go/iam v1.5.0 // indirect - cloud.google.com/go/longrunning v0.6.6 // indirect - cloud.google.com/go/monitoring v1.24.0 // indirect - cloud.google.com/go/storage v1.50.0 // indirect - cloud.google.com/go/trace v1.11.3 // indirect - dario.cat/mergo v1.0.1 // indirect - github.com/ClickHouse/ch-go v0.61.5 // indirect - github.com/ClickHouse/clickhouse-go/v2 v2.23.2 // indirect - github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.26.0 // indirect - github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect + cloud.google.com/go/compute/metadata v0.9.0 // indirect + cloud.google.com/go/firestore v1.22.0 // indirect + cloud.google.com/go/iam v1.10.0 // indirect + cloud.google.com/go/longrunning v0.12.0 // indirect + cloud.google.com/go/monitoring v1.28.0 // indirect + cloud.google.com/go/trace v1.15.0 // indirect + dario.cat/mergo v1.0.2 // indirect + filippo.io/edwards25519 v1.2.0 // indirect + github.com/ClickHouse/ch-go v0.71.0 // indirect + github.com/ClickHouse/clickhouse-go/v2 v2.46.0 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.32.0 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.56.0 // indirect github.com/KyleBanks/depth v1.2.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver v1.5.0 // indirect - github.com/Masterminds/sprig v2.22.0+incompatible // indirect - github.com/PuerkitoBio/goquery v1.10.2 // indirect - github.com/andybalholm/brotli v1.1.0 // indirect + github.com/PuerkitoBio/goquery v1.12.0 // indirect + github.com/andybalholm/brotli v1.2.1 // indirect github.com/andybalholm/cascadia v1.3.3 // indirect - github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect - github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect - github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect + github.com/clipperhouse/displaywidth v0.11.0 // indirect + github.com/clipperhouse/uax29/v2 v2.7.0 // indirect + github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 // indirect + github.com/envoyproxy/go-control-plane/envoy v1.37.0 // indirect + github.com/envoyproxy/protoc-gen-validate v1.3.3 // indirect + github.com/fatih/color v1.19.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-faster/city v1.0.1 // indirect github.com/go-faster/errors v0.7.1 // indirect - github.com/go-jose/go-jose/v4 v4.0.5 // indirect - github.com/go-logr/logr v1.4.2 // indirect + github.com/go-jose/go-jose/v4 v4.1.4 // indirect + github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-openapi/jsonpointer v0.21.0 // indirect - github.com/go-openapi/jsonreference v0.21.0 // indirect - github.com/go-openapi/spec v0.21.0 // indirect - github.com/go-openapi/swag v0.23.0 // indirect - github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/go-openapi/jsonpointer v0.23.1 // indirect + github.com/go-openapi/jsonreference v0.21.5 // indirect + github.com/go-openapi/spec v0.22.4 // indirect + github.com/go-openapi/swag/conv v0.26.0 // indirect + github.com/go-openapi/swag/jsonname v0.26.0 // indirect + github.com/go-openapi/swag/jsonutils v0.26.0 // indirect + github.com/go-openapi/swag/loading v0.26.0 // indirect + github.com/go-openapi/swag/stringutils v0.26.0 // indirect + github.com/go-openapi/swag/typeutils v0.26.0 // indirect + github.com/go-openapi/swag/yamlutils v0.26.0 // indirect + github.com/go-sql-driver/mysql v1.10.0 // indirect + github.com/goccy/go-json v0.10.6 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/s2a-go v0.1.9 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect - github.com/googleapis/gax-go/v2 v2.14.1 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.15 // indirect + github.com/googleapis/gax-go/v2 v2.22.0 // indirect github.com/gorilla/css v1.0.1 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-version v1.6.0 // indirect + github.com/hashicorp/go-version v1.9.0 // indirect github.com/huandu/xstrings v1.5.0 // indirect - github.com/imdario/mergo v0.3.16 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect - github.com/jackc/pgx/v5 v5.7.2 // indirect + github.com/jackc/pgx/v5 v5.9.2 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect - github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 // indirect github.com/jinzhu/inflection v1.0.0 // indirect - github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.17.9 // indirect - github.com/mailru/easyjson v0.7.7 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/klauspost/compress v1.18.6 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.22 // indirect + github.com/mattn/go-runewidth v0.0.23 // indirect + github.com/mattn/go-sqlite3 v1.14.44 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect - github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/paulmach/orb v0.11.1 // indirect - github.com/pierrec/lz4/v4 v4.1.21 // indirect + github.com/olekukonko/tablewriter v1.1.4 // indirect + github.com/paulmach/orb v0.13.0 // indirect + github.com/pierrec/lz4/v4 v4.1.26 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/redis/go-redis/extra/rediscmd/v9 v9.8.0 // indirect - github.com/richardlehane/mscfb v1.0.4 // indirect - github.com/richardlehane/msoleps v1.0.4 // indirect - github.com/rivo/uniseg v0.4.7 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/segmentio/asm v1.2.0 // indirect - github.com/sendgrid/rest v2.6.9+incompatible // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/redis/go-redis/extra/rediscmd/v9 v9.19.0 // indirect + github.com/richardlehane/mscfb v1.0.6 // indirect + github.com/richardlehane/msoleps v1.0.6 // indirect + github.com/segmentio/asm v1.2.1 // indirect github.com/shopspring/decimal v1.4.0 // indirect - github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect + github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/swaggo/files/v2 v2.0.2 // indirect + github.com/tiendc/go-deepcopy v1.7.2 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.54.0 // indirect - github.com/valyala/tcplisten v1.0.0 // indirect + github.com/valyala/fasthttp v1.71.0 // indirect github.com/vanng822/css v1.0.1 // indirect - github.com/vanng822/go-premailer v1.24.0 // indirect - github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d // indirect - github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect - github.com/zeebo/errs v1.4.0 // indirect - go.opentelemetry.io/auto/sdk v1.1.0 // indirect - go.opentelemetry.io/contrib v1.27.0 // indirect - go.opentelemetry.io/contrib/detectors/gcp v1.34.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect - go.opentelemetry.io/contrib/instrumentation/runtime v0.60.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.11.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.35.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 // indirect - go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.35.0 // indirect - go.opentelemetry.io/otel/log v0.11.0 // indirect - go.opentelemetry.io/otel/sdk/log v0.11.0 // indirect - go.opentelemetry.io/proto/otlp v1.5.0 // indirect + github.com/vanng822/go-premailer v1.33.0 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.2.0 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/xuri/efp v0.0.1 // indirect + github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect + github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect + go.opentelemetry.io/auto/sdk v1.2.1 // indirect + go.opentelemetry.io/contrib v1.43.0 // indirect + go.opentelemetry.io/contrib/detectors/gcp v1.43.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.68.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.68.0 // indirect + go.opentelemetry.io/contrib/instrumentation/runtime v0.68.0 // indirect + go.opentelemetry.io/contrib/processors/minsev v0.16.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 // indirect + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 // indirect + go.opentelemetry.io/otel/log v0.19.0 // indirect + go.opentelemetry.io/otel/sdk/log v0.19.0 // indirect + go.opentelemetry.io/proto/otlp v1.10.0 // indirect + go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.27.0 // indirect - golang.org/x/crypto v0.37.0 // indirect - golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect - golang.org/x/net v0.39.0 // indirect - golang.org/x/oauth2 v0.29.0 // indirect - golang.org/x/sync v0.13.0 // indirect - golang.org/x/sys v0.32.0 // indirect - golang.org/x/text v0.24.0 // indirect - golang.org/x/time v0.11.0 // indirect - golang.org/x/tools v0.31.0 // indirect + go.uber.org/zap v1.28.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/crypto v0.51.0 // indirect + golang.org/x/mod v0.35.0 // indirect + golang.org/x/net v0.53.0 // indirect + golang.org/x/oauth2 v0.36.0 // indirect + golang.org/x/sys v0.44.0 // indirect + golang.org/x/text v0.37.0 // indirect + golang.org/x/time v0.15.0 // indirect + golang.org/x/tools v0.44.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20250422160041-2d3770c4ea7f // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197 // indirect - google.golang.org/grpc v1.72.0 // indirect + google.golang.org/genproto v0.0.0-20260504160031-60b97b32f348 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260504160031-60b97b32f348 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260504160031-60b97b32f348 // indirect + google.golang.org/grpc v1.81.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/driver/clickhouse v0.6.1 // indirect - gorm.io/driver/mysql v1.5.7 // indirect + gorm.io/driver/clickhouse v0.7.0 // indirect + gorm.io/driver/mysql v1.6.0 // indirect ) diff --git a/api/go.sum b/api/go.sum index 6f4fe4e2..cb11e652 100644 --- a/api/go.sum +++ b/api/go.sum @@ -1,194 +1,220 @@ bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI= bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA= -cel.dev/expr v0.20.0 h1:OunBvVCfvpWlt4dN7zg3FM6TDkzOePe1+foGJ9AXeeI= -cel.dev/expr v0.20.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw= -cloud.google.com/go v0.120.0 h1:wc6bgG9DHyKqF5/vQvX1CiZrtHnxJjBlKUyF9nP6meA= -cloud.google.com/go v0.120.0/go.mod h1:/beW32s8/pGRuj4IILWQNd4uuebeT4dkOhKmkfit64Q= -cloud.google.com/go/auth v0.16.1 h1:XrXauHMd30LhQYVRHLGvJiYeczweKQXZxsTbV9TiguU= -cloud.google.com/go/auth v0.16.1/go.mod h1:1howDHJ5IETh/LwYs3ZxvlkXF48aSqqJUM+5o02dNOI= +cel.dev/expr v0.25.1 h1:1KrZg61W6TWSxuNZ37Xy49ps13NUovb66QLprthtwi4= +cel.dev/expr v0.25.1/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= +cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE= +cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU= +cloud.google.com/go/auth v0.20.0 h1:kXTssoVb4azsVDoUiF8KvxAqrsQcQtB53DcSgta74CA= +cloud.google.com/go/auth v0.20.0/go.mod h1:942/yi/itH1SsmpyrbnTMDgGfdy2BUqIKyd0cyYLc5Q= cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc= cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c= -cloud.google.com/go/cloudtasks v1.13.6 h1:Fwan19UiNoFD+3KY0MnNHE5DyixOxNzS1mZ4ChOdpy0= -cloud.google.com/go/cloudtasks v1.13.6/go.mod h1:/IDaQqGKMixD+ayM43CfsvWF2k36GeomEuy9gL4gLmU= -cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I= -cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg= -cloud.google.com/go/firestore v1.18.0 h1:cuydCaLS7Vl2SatAeivXyhbhDEIR8BDmtn4egDhIn2s= -cloud.google.com/go/firestore v1.18.0/go.mod h1:5ye0v48PhseZBdcl0qbl3uttu7FIEwEYVaWm0UIEOEU= -cloud.google.com/go/iam v1.5.0 h1:QlLcVMhbLGOjRcGe6VTGGTyQib8dRLK2B/kYNV0+2xs= -cloud.google.com/go/iam v1.5.0/go.mod h1:U+DOtKQltF/LxPEtcDLoobcsZMilSRwR7mgNL7knOpo= -cloud.google.com/go/logging v1.13.0 h1:7j0HgAp0B94o1YRDqiqm26w4q1rDMH7XNRU34lJXHYc= -cloud.google.com/go/logging v1.13.0/go.mod h1:36CoKh6KA/M0PbhPKMq6/qety2DCAErbhXT62TuXALA= -cloud.google.com/go/longrunning v0.6.6 h1:XJNDo5MUfMM05xK3ewpbSdmt7R2Zw+aQEMbdQR65Rbw= -cloud.google.com/go/longrunning v0.6.6/go.mod h1:hyeGJUrPHcx0u2Uu1UFSoYZLn4lkMrccJig0t4FI7yw= -cloud.google.com/go/monitoring v1.24.0 h1:csSKiCJ+WVRgNkRzzz3BPoGjFhjPY23ZTcaenToJxMM= -cloud.google.com/go/monitoring v1.24.0/go.mod h1:Bd1PRK5bmQBQNnuGwHBfUamAV1ys9049oEPHnn4pcsc= -cloud.google.com/go/storage v1.50.0 h1:3TbVkzTooBvnZsk7WaAQfOsNrdoM8QHusXA1cpk6QJs= -cloud.google.com/go/storage v1.50.0/go.mod h1:l7XeiD//vx5lfqE3RavfmU9yvk5Pp0Zhcv482poyafY= -cloud.google.com/go/trace v1.11.3 h1:c+I4YFjxRQjvAhRmSsmjpASUKq88chOX854ied0K/pE= -cloud.google.com/go/trace v1.11.3/go.mod h1:pt7zCYiDSQjC9Y2oqCsh9jF4GStB/hmjrYLsxRR27q8= -dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= -dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +cloud.google.com/go/cloudtasks v1.17.0 h1:3+U2YGq0fvEqQxdgknsjD5m+QNwah0QZYJOylNQLA1U= +cloud.google.com/go/cloudtasks v1.17.0/go.mod h1:3KeCxwtGEyaySL7CR3lMmEa2I4mq1ynXdgmfNiO4RYE= +cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs= +cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10= +cloud.google.com/go/firestore v1.22.0 h1:avooeboIq37vKXobrbPUFhFBxS/c3FqmWoX0xs8dO6E= +cloud.google.com/go/firestore v1.22.0/go.mod h1:PaM4i7i7ruALSKmlpHXXZaPObcZw0W7ie5UOPr72iTU= +cloud.google.com/go/iam v1.10.0 h1:cWWt8u8jXv3MzpvBmQgNClvvbVCRukruCJAnoK3fIJY= +cloud.google.com/go/iam v1.10.0/go.mod h1:KP+nKGugNJW4LcLx1uEZcq1ok5sQHFaQehQNl4QDgV4= +cloud.google.com/go/logging v1.17.0 h1:rUFekZYwHiKElXCyz3zYBGz4BOeIqzgCKxVLdgrZ5mY= +cloud.google.com/go/logging v1.17.0/go.mod h1:ZGKnpBaURITh+g/uom2VhbiFoFWvejcrHPDhxFtU/gI= +cloud.google.com/go/longrunning v0.12.0 h1:wLv2hXvID9zHejLtcPo1B0JBjErnwZCYAPKSTa65xpY= +cloud.google.com/go/longrunning v0.12.0/go.mod h1:8nqFBPOO1U/XkhWl0I19AMZEphrHi73VNABIpKYaTwM= +cloud.google.com/go/monitoring v1.28.0 h1:jOe0Wkm+a56ptZnEeyHevXo7+KPWAPPP5wUTEJdP7GY= +cloud.google.com/go/monitoring v1.28.0/go.mod h1:72NOVjJXHY/HBfoLT0+qlCZBT059+9VXLeAnL2PeeVM= +cloud.google.com/go/storage v1.62.1 h1:Os0G3XbUbjZumkpDUf2Y0rLoXJTCF1kU2kWUujKYXD8= +cloud.google.com/go/storage v1.62.1/go.mod h1:cpYz/kRVZ+UQAF1uHeea10/9ewcRbxGoGNKsS9daSXA= +cloud.google.com/go/trace v1.15.0 h1:kAYkTwKyYHkGtAGFuu6qaUFRBkOVr+d1Yo44yZtGtgg= +cloud.google.com/go/trace v1.15.0/go.mod h1:r+bdAn16dKLSV1G2D5v3e58IlQlizfxWrUfjx7kM7X0= +dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= +dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= +filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo= +filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc= firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= -github.com/ClickHouse/ch-go v0.61.5 h1:zwR8QbYI0tsMiEcze/uIMK+Tz1D3XZXLdNrlaOpeEI4= -github.com/ClickHouse/ch-go v0.61.5/go.mod h1:s1LJW/F/LcFs5HJnuogFMta50kKDO0lf9zzfrbl0RQg= -github.com/ClickHouse/clickhouse-go/v2 v2.23.2 h1:+DAKPMnxLS7pduQZsrJc8OhdLS2L9MfDEJ2TS+hpYDM= -github.com/ClickHouse/clickhouse-go/v2 v2.23.2/go.mod h1:aNap51J1OM3yxQJRgM+AlP/MPkGBCL8A74uQThoQhR0= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.26.0 h1:f2Qw/Ehhimh5uO1fayV0QIW7DShEQqhtUfhYc+cBPlw= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.26.0/go.mod h1:2bIszWvQRlJVmJLiuLhukLImRjKPcYdzzsx6darK02A= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0 h1:fYE9p3esPxA/C0rQ0AHhP0drtPXDRhaWiwg1DPqO7IU= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0/go.mod h1:BnBReJLvVYx2CS/UHOgVz2BXKXD9wsQPxZug20nZhd0= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.27.0 h1:Jtr816GUk6+I2ox9L/v+VcOwN6IyGOEDTSNHfD6m9sY= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.27.0/go.mod h1:E05RN++yLx9W4fXPtX978OLo9P0+fBacauUdET1BckA= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.51.0 h1:OqVGm6Ei3x5+yZmSJG1Mh2NwHvpVmZ08CB5qJhT9Nuk= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.51.0/go.mod h1:SZiPHWGOOk3bl8tkevxkoiwPgsIl6CwrWcbwjfHZpdM= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 h1:6/0iUd0xrnX7qt+mLNRwg5c0PGv8wpE8K90ryANQwMI= -github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0/go.mod h1:otE2jQekW/PqXk1Awf5lmfokJx4uwuqcj1ab5SpGeW0= +github.com/ClickHouse/ch-go v0.71.0 h1:bUdZ/EZj/LcVHsMqaRUP2holqygrPWQKeMjc6nZoyRM= +github.com/ClickHouse/ch-go v0.71.0/go.mod h1:NwbNc+7jaqfY58dmdDUbG4Jl22vThgx1cYjBw0vtgXw= +github.com/ClickHouse/clickhouse-go/v2 v2.46.0 h1:s3eRy+hYmu5uzotB6ZhDofgHu8kDgGN/fpmjxRkqSpk= +github.com/ClickHouse/clickhouse-go/v2 v2.46.0/go.mod h1:giJfUVlMkcfUEPVfRpt51zZaGEx9i17gCos8gBl392c= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.32.0 h1:rIkQfkCOVKc1OiRCNcSDD8ml5RJlZbH/Xsq7lbpynwc= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.32.0/go.mod h1:RD2SsorTmYhF6HkTmDw7KmPYQk8OBYwTkuasChwv7R4= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.56.0 h1:O2sXMyJh8b7devAGdE+163xtRurt0RVpB6DIzX5vGfg= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.56.0/go.mod h1:hEpiGU18xf70qb3jbTcIggWAiEfX/cOIVc2OTe4OegA= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.32.0 h1:ftVmySBwuOJafpEJnnZvco+iV3p6Lokgu2sd89/qY7M= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.32.0/go.mod h1:nikqFGPI5OGwEsdxXzd3f58sB3tzkjqpqwYOV/S1rmo= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.56.0 h1:ZIT85vKP7LBS84XJ0WdJ3dPOX3iz4j3c0+lpajGQMyo= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.56.0/go.mod h1:rqP9UEhOXv9WhQ7Gjz+G5y/pf8+BJZW5/Ts0AhE0PwE= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.56.0 h1:0YP0+/ixwu+Uqeu/FGiBZNQ19huiUxxiPXIc9WsLKuQ= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.56.0/go.mod h1:6ZZMQhZKDvUvkJw2rc+oDP90tMMzuU/J+5HG1ZmPOmE= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= -github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60= -github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= -github.com/NdoleStudio/go-otelroundtripper v0.0.11 h1:+3xN52xtLTH7NiF3O7Wc7H9WzqBYGz0fRYQ21BUnt8E= -github.com/NdoleStudio/go-otelroundtripper v0.0.11/go.mod h1:r26FzXvqXbyJf+xZnre/Head4K/LyVJDywP14hh+HdA= -github.com/NdoleStudio/lemonsqueezy-go v1.2.4 h1:BhWlCUH+DIPfSn4g/V7f2nFkMCQuzno9DXKZ7YDrXXA= -github.com/NdoleStudio/lemonsqueezy-go v1.2.4/go.mod h1:2uZlWgn9sbNxOx3JQWLlPrDOC6NT/wmSTOgL3U/fMMw= -github.com/PuerkitoBio/goquery v1.10.2 h1:7fh2BdHcG6VFZsK7toXBT/Bh1z5Wmy8Q9MV9HqT2AM8= -github.com/PuerkitoBio/goquery v1.10.2/go.mod h1:0guWGjcLu9AYC7C1GHnpysHy056u9aEkUHwhdnePMCU= -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= +github.com/Masterminds/semver/v3 v3.5.0 h1:kQceYJfbupGfZOKZQg0kou0DgAKhzDg2NZPAwZ/2OOE= +github.com/Masterminds/semver/v3 v3.5.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs= +github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0= +github.com/NdoleStudio/go-otelroundtripper v0.0.14 h1:t/VoW2772wTDQnjdECxxWbtZtbnpJyuRSKxRC/hHfTg= +github.com/NdoleStudio/go-otelroundtripper v0.0.14/go.mod h1:ObQjHo1D/daXeESbFIi0UXJN0yJu4zQ7mMeSKvm4a1I= +github.com/NdoleStudio/lemonsqueezy-go v1.3.1 h1:lMUVgdAx2onbOUJIVPR05xAANYuCMXBRaGWpAdA4LiM= +github.com/NdoleStudio/lemonsqueezy-go v1.3.1/go.mod h1:xKRsRX1jSI6mLrVXyWh2sF/1isxTioZrSjWy6HpA3xQ= +github.com/NdoleStudio/plunk-go v0.0.2 h1:afPW7MHK4Z3rsybpJBnmTmxKCLKF1M7sPI+BNGPf35A= +github.com/NdoleStudio/plunk-go v0.0.2/go.mod h1:pqG3zKhpn/A2bL1K+WsWzvfTpOeSkYgXhNk5H65uEc8= +github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO8RIBo= +github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ= +github.com/andybalholm/brotli v1.2.1 h1:R+f5xP285VArJDRgowrfb9DqL18yVK0gKAW/F+eTWro= +github.com/andybalholm/brotli v1.2.1/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= -github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0= -github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= +github.com/avast/retry-go/v5 v5.0.0 h1:kf1Qc2UsTZ4qq8elDymqfbISvkyMuhgRxuJqX2NHP7k= +github.com/avast/retry-go/v5 v5.0.0/go.mod h1://d+usmKWio1agtZfS1H/ltTqwtIfBnRq9zEwjc3eH8= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= -github.com/carlmjohnson/requests v0.24.3 h1:LYcM/jVIVPkioigMjEAnBACXl2vb42TVqiC8EYNoaXQ= -github.com/carlmjohnson/requests v0.24.3/go.mod h1:duYA/jDnyZ6f3xbcF5PpZ9N8clgopubP2nK5i6MVMhU= -github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= -github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/carlmjohnson/requests v0.25.1 h1:17zNRLecxtAjhtdEIV+F+wrYfe+AGZUjWJtpndcOUYA= +github.com/carlmjohnson/requests v0.25.1/go.mod h1:z3UEf8IE4sZxZ78spW6/tLdqBkfCu1Fn4RaYMnZ8SRM= +github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= +github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cloudevents/sdk-go/v2 v2.16.0 h1:wnunjgiLQCfYlyo+E4+mFlZtAh7pKn7vT8MMD3lSwCg= -github.com/cloudevents/sdk-go/v2 v2.16.0/go.mod h1:5YWqklyhDSmGzBK/JENKKXdulbPq0JFf3c/KEnMLqgg= -github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 h1:Om6kYQYDUk5wWbT0t0q6pvyM49i9XZAv9dDrkDA7gjk= -github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= -github.com/cockroachdb/cockroach-go/v2 v2.4.0 h1:7K5vpE3m7LylIbmpbr4eEhApDTPMgFgR+eDPy1sdJjM= -github.com/cockroachdb/cockroach-go/v2 v2.4.0/go.mod h1:9U179XbCx4qFWtNhc7BiWLPfuyMVQ7qdAhfrwLz1vH0= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= +github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= +github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= +github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= +github.com/cloudevents/sdk-go/v2 v2.16.2 h1:ZYDFrYke4FD+jM8TZTJJO6JhKHzOQl2oqpFK1D+NnQM= +github.com/cloudevents/sdk-go/v2 v2.16.2/go.mod h1:laOcGImm4nVJEU+PHnUrKL56CKmRL65RlQF0kRmW/kg= +github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 h1:aBangftG7EVZoUb69Os8IaYg++6uMOdKK83QtkkvJik= +github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2/go.mod h1:qwXFYgsP6T7XnJtbKlf1HP8AjxZZyzxMmc+Lq5GjlU4= +github.com/cockroachdb/cockroach-go/v2 v2.4.3 h1:LJO3K3jC5WXvMePRQSJE1NsIGoFGcEx1LW83W6RAlhw= +github.com/cockroachdb/cockroach-go/v2 v2.4.3/go.mod h1:9U179XbCx4qFWtNhc7BiWLPfuyMVQ7qdAhfrwLz1vH0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgraph-io/ristretto v1.0.0 h1:SYG07bONKMlFDUYu5pEu3DGAh8c2OFNzKm6G9J4Si84= -github.com/dgraph-io/ristretto v1.0.0/go.mod h1:jTi2FiYEhQ1NsMmA7DeBykizjOuY88NhKBkepyu1jPc= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgraph-io/ristretto/v2 v2.4.0 h1:I/w09yLjhdcVD2QV192UJcq8dPBaAJb9pOuMyNy0XlU= +github.com/dgraph-io/ristretto/v2 v2.4.0/go.mod h1:0KsrXtXvnv0EqnzyowllbVJB8yBonswa2lTCK2gGo9E= +github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38= +github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/envoyproxy/go-control-plane v0.13.4 h1:zEqyPVyku6IvWCFwux4x9RxkLOMUL+1vC9xUFv5l2/M= -github.com/envoyproxy/go-control-plane v0.13.4/go.mod h1:kDfuBlDVsSj2MjrLEtRWtHlsWIFcGyB2RMO44Dc5GZA= -github.com/envoyproxy/go-control-plane/envoy v1.32.4 h1:jb83lalDRZSpPWW2Z7Mck/8kXZ5CQAFYVjQcdVIr83A= -github.com/envoyproxy/go-control-plane/envoy v1.32.4/go.mod h1:Gzjc5k8JcJswLjAx1Zm+wSYE20UrLtt7JZMWiWQXQEw= +github.com/envoyproxy/go-control-plane v0.14.0 h1:hbG2kr4RuFj222B6+7T83thSPqLjwBIfQawTkC++2HA= +github.com/envoyproxy/go-control-plane v0.14.0/go.mod h1:NcS5X47pLl/hfqxU70yPwL9ZMkUlwlKxtAohpi2wBEU= +github.com/envoyproxy/go-control-plane/envoy v1.37.0 h1:u3riX6BoYRfF4Dr7dwSOroNfdSbEPe9Yyl09/B6wBrQ= +github.com/envoyproxy/go-control-plane/envoy v1.37.0/go.mod h1:DReE9MMrmecPy+YvQOAOHNYMALuowAnbjjEMkkWOi6A= github.com/envoyproxy/go-control-plane/ratelimit v0.1.0 h1:/G9QYbddjL25KvtKTv3an9lx6VBE2cnb8wp1vEGNYGI= github.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJPzVVHnPgRKdUdwW/KdbRt94AzgRee4= -github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8= -github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU= -github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= -github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/envoyproxy/protoc-gen-validate v1.3.3 h1:MVQghNeW+LZcmXe7SY1V36Z+WFMDjpqGAGacLe2T0ds= +github.com/envoyproxy/protoc-gen-validate v1.3.3/go.mod h1:TsndJ/ngyIdQRhMcVVGDDHINPLWB7C82oDArY51KfB0= +github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= +github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/gertd/go-pluralize v0.2.1 h1:M3uASbVjMnTsPb0PNqg+E/24Vwigyo/tvyMTtAlLgiA= +github.com/gertd/go-pluralize v0.2.1/go.mod h1:rbYaKDbsXxmRfr8uygAEKhOWsjyrrqrkHVpZvoOp8zk= github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw= github.com/go-faster/city v1.0.1/go.mod h1:jKcUJId49qdW3L1qKHH/3wPeUstCVpVSXTM6vO3VcTw= github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYg= github.com/go-faster/errors v0.7.1/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo= -github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE= -github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA= +github.com/go-hermes/hermes/v2 v2.6.2 h1:RuGQlICVtIHixfxtYwN7hAoqGyGxr+D3kE42oE6emcw= +github.com/go-hermes/hermes/v2 v2.6.2/go.mod h1:RLVNk31/1KqF35vK3mAaQVuJvMH+K5//6OTGJk+j/80= +github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= +github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= -github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= -github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= -github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= -github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= -github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY= -github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk= -github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= -github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= -github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= -github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/go-openapi/jsonpointer v0.23.1 h1:1HBACs7XIwR2RcmItfdSFlALhGbe6S92p0ry4d1GWg4= +github.com/go-openapi/jsonpointer v0.23.1/go.mod h1:iWRmZTrGn7XwYhtPt/fvdSFj1OfNBngqRT2UG3BxSqY= +github.com/go-openapi/jsonreference v0.21.5 h1:6uCGVXU/aNF13AQNggxfysJ+5ZcU4nEAe+pJyVWRdiE= +github.com/go-openapi/jsonreference v0.21.5/go.mod h1:u25Bw85sX4E2jzFodh1FOKMTZLcfifd1Q+iKKOUxExw= +github.com/go-openapi/spec v0.22.4 h1:4pxGjipMKu0FzFiu/DPwN3CTBRlVM2yLf/YTWorYfDQ= +github.com/go-openapi/spec v0.22.4/go.mod h1:WQ6Ai0VPWMZgMT4XySjlRIE6GP1bGQOtEThn3gcWLtQ= +github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= +github.com/go-openapi/swag/conv v0.26.0 h1:5yGGsPYI1ZCva93U0AoKi/iZrNhaJEjr324YVsiD89I= +github.com/go-openapi/swag/conv v0.26.0/go.mod h1:tpAmIL7X58VPnHHiSO4uE3jBeRamGsFsfdDeDtb5ECE= +github.com/go-openapi/swag/jsonname v0.26.0 h1:gV1NFX9M8avo0YSpmWogqfQISigCmpaiNci8cGECU5w= +github.com/go-openapi/swag/jsonname v0.26.0/go.mod h1:urBBR8bZNoDYGr653ynhIx+gTeIz0ARZxHkAPktJK2M= +github.com/go-openapi/swag/jsonutils v0.26.0 h1:FawFML2iAXsPqmERscuMPIHmFsoP1tOqWkxBaKNMsnA= +github.com/go-openapi/swag/jsonutils v0.26.0/go.mod h1:2VmA0CJlyFqgawOaPI9psnjFDqzyivIqLYN34t9p91E= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.26.0 h1:apqeINu/ICHouqiRZbyFvuDge5jCmmLTqGQ9V95EaOM= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.26.0/go.mod h1:AyM6QT8uz5IdKxk5akv0y6u4QvcL9GWERt0Jx/F/R8Y= +github.com/go-openapi/swag/loading v0.26.0 h1:Apg6zaKhCJurpJer0DCxq99qwmhFddBhaMX7kilDcko= +github.com/go-openapi/swag/loading v0.26.0/go.mod h1:dBxQ/6V2uBaAQdevN18VELE6xSpJWZxLX4txe12JwDg= +github.com/go-openapi/swag/stringutils v0.26.0 h1:qZQngLxs5s7SLijc3N2ZO+fUq2o8LjuWAASSrJuh+xg= +github.com/go-openapi/swag/stringutils v0.26.0/go.mod h1:sWn5uY+QIIspwPhvgnqJsH8xqFT2ZbYcvbcFanRyhFE= +github.com/go-openapi/swag/typeutils v0.26.0 h1:2kdEwdiNWy+JJdOvu5MA2IIg2SylWAFuuyQIKYybfq4= +github.com/go-openapi/swag/typeutils v0.26.0/go.mod h1:oovDuIUvTrEHVMqWilQzKzV4YlSKgyZmFh7AlfABNVE= +github.com/go-openapi/swag/yamlutils v0.26.0 h1:H7O8l/8NJJQ/oiReEN+oMpnGMyt8G0hl460nRZxhLMQ= +github.com/go-openapi/swag/yamlutils v0.26.0/go.mod h1:1evKEGAtP37Pkwcc7EWMF0hedX0/x3Rkvei2wtG/TbU= +github.com/go-openapi/testify/enable/yaml/v2 v2.4.2 h1:5zRca5jw7lzVREKCZVNBpysDNBjj74rBh0N2BGQbSR0= +github.com/go-openapi/testify/enable/yaml/v2 v2.4.2/go.mod h1:XVevPw5hUXuV+5AkI1u1PeAm27EQVrhXTTCPAF85LmE= +github.com/go-openapi/testify/v2 v2.4.2 h1:tiByHpvE9uHrrKjOszax7ZvKB7QOgizBWGBLuq0ePx4= +github.com/go-openapi/testify/v2 v2.4.2/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw= +github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw= +github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk= +github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU= +github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gofiber/contrib/otelfiber v1.0.10 h1:Bu28Pi4pfYmGfIc/9+sNaBbFwTHGY/zpSIK5jBxuRtM= github.com/gofiber/contrib/otelfiber v1.0.10/go.mod h1:jN6AvS1HolDHTQHFURsV+7jSX96FpXYeKH6nmkq8AIw= -github.com/gofiber/fiber/v2 v2.52.7 h1:6xJpE4sSqErvMiEZo9ZpJLRSVcpkNBvioeqAHKwhTZY= -github.com/gofiber/fiber/v2 v2.52.7/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw= +github.com/gofiber/fiber/v2 v2.52.13 h1:TOKP64iqC9b5P49VrBW5tHhUOvDyrtJ0xePEfzJbCbk= +github.com/gofiber/fiber/v2 v2.52.13/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw= github.com/gofiber/swagger v1.1.1 h1:FZVhVQQ9s1ZKLHL/O0loLh49bYB5l1HEAgxDlcTtkRA= github.com/gofiber/swagger v1.1.1/go.mod h1:vtvY/sQAMc/lGTUCg0lqmBL7Ht9O7uzChpbvJeJQINw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= +github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc= github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0= github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0= github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU9uHLo7OnF5tL52HFAgMmyrf4= -github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA= -github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q= -github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA= +github.com/googleapis/enterprise-certificate-proxy v0.3.15 h1:xolVQTEXusUcAA5UgtyRLjelpFFHWlPQ4XfWGc7MBas= +github.com/googleapis/enterprise-certificate-proxy v0.3.15/go.mod h1:vqVt9yG9480NtzREnTlmGSBmFrA+bzb0yl0TxoBQXOg= +github.com/googleapis/gax-go/v2 v2.22.0 h1:PjIWBpgGIVKGoCXuiCoP64altEJCj3/Ei+kSU5vlZD4= +github.com/googleapis/gax-go/v2 v2.22.0/go.mod h1:irWBbALSr0Sk3qlqb9SyJ1h68WjgeFuiOzI4Rqw5+aY= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= -github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= -github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= -github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48= +github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw= +github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA= +github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hirosassa/zerodriver v0.1.4 h1:8bzamKUOHHq03aEk12qi/lnji2dM+IhFOe+RpKpIZFM= github.com/hirosassa/zerodriver v0.1.4/go.mod h1:hHOOAQvVGwBV1iVVYujM6vwOBBqQcBIFpJxCD9mJU7Y= github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI= github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= -github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/inbucket/html2text v1.0.0 h1:N5kza++4uBBDJ2Z3KUnTRyPNoBcW+YfOgNiNmNB+sgs= +github.com/inbucket/html2text v1.0.0/go.mod h1:5TrhXQKGU+LXurODaSm55Y9eXoPBRnYiOz4x2XfUoJU= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI= -github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= +github.com/jackc/pgx/v5 v5.9.2 h1:3ZhOzMWnR4yJ+RW1XImIPsD1aNSz4T4fyP7zlQb56hw= +github.com/jackc/pgx/v5 v5.9.2/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= -github.com/jaswdr/faker/v2 v2.4.0 h1:qNmS/k60ODLMmzDdQOEUha69qcbdMZVnqZjPdOjNHGU= -github.com/jaswdr/faker/v2 v2.4.0/go.mod h1:ROK8xwQV0hYOLDUtxCQgHGcl10jbVzIvqHxcIDdwY2Q= -github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 h1:iCHtR9CQyktQ5+f3dMVZfwD2KWJUgm7M0gdL9NGr8KA= -github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk= +github.com/jaswdr/faker/v2 v2.9.1 h1:J0Rjqb2/FquZnoZplzkGVL5LmhNkeIpvsSMoJKzn+8E= +github.com/jaswdr/faker/v2 v2.9.1/go.mod h1:jZq+qzNQr8/P+5fHd9t3txe2GNPnthrTfohtnJ7B+68= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= @@ -197,41 +223,30 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA= github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jszwec/csvutil v1.10.0 h1:upMDUxhQKqZ5ZDCs/wy+8Kib8rZR8I8lOR34yJkdqhI= github.com/jszwec/csvutil v1.10.0/go.mod h1:/E4ONrmGkwmWsk9ae9jpXnv9QT8pLHEPcCirMFhxG9I= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= -github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao= +github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= +github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= -github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/matcornic/hermes v1.3.0 h1:k6rih7zpUgfIF/57F3WeBi9n68XkvhC/z8eQTRIsQqc= -github.com/matcornic/hermes v1.3.0/go.mod h1:X3MXWWBHjKSfgQl0xjv+NQTAGWSiNr/fZTlhAEQJ63Q= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= -github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= -github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ= +github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA= +github.com/matoous/go-nanoid/v2 v2.1.0 h1:P64+dmq21hhWdtvZfEAofnvJULaRR1Yib0+PnU669bE= +github.com/matoous/go-nanoid/v2 v2.1.0/go.mod h1:KlbGNQ+FhrUNIHUxZdL63t7tl4LaPkZNpUULS8H4uVM= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4= +github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= +github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw= +github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= +github.com/mattn/go-sqlite3 v1.14.44 h1:3VSe+xafpbzsLbdr2AWlAZk9yRHiBhTBakioXaCKTF8= +github.com/mattn/go-sqlite3 v1.14.44/go.mod h1:pjEuOr8IwzLJP2MfGeTb0A35jauH+C2kbHKBr7yXKVQ= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= @@ -241,185 +256,186 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/nyaruka/phonenumbers v1.6.1 h1:XAJcTdYow16VrVKfglznMpJZz8KMJoMjx/91sX+K940= -github.com/nyaruka/phonenumbers v1.6.1/go.mod h1:7gjs+Lchqm49adhAKB5cdcng5ZXgt6x7Jgvi0ZorUtU= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/nyaruka/phonenumbers v1.7.2 h1:biMUpF5TWuHtYXVzuNE7pSCjlA9tkvd8Vaq8b1CYaaQ= +github.com/nyaruka/phonenumbers v1.7.2/go.mod h1:fsKPJ70O9JetEA4ggnJadYTFWwtGPvu/lETTXNXq6Cs= +github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 h1:zrbMGy9YXpIeTnGj4EljqMiZsIcE09mmF8XsD5AYOJc= +github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6/go.mod h1:rEKTHC9roVVicUIfZK7DYrdIoM0EOr8mK1Hj5s3JjH0= +github.com/olekukonko/errors v1.3.0 h1:teJvgLGUEqMzBUms+Dj3/3szNqCG/Jdw9iDbum8fR6U= +github.com/olekukonko/errors v1.3.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y= +github.com/olekukonko/ll v0.1.8 h1:ysHCJRGHYKzmBSdz9w5AySztx7lG8SQY+naTGYUbsz8= +github.com/olekukonko/ll v0.1.8/go.mod h1:RPRC6UcscfFZgjo1nulkfMH5IM0QAYim0LfnMvUuozw= +github.com/olekukonko/tablewriter v1.1.4 h1:ORUMI3dXbMnRlRggJX3+q7OzQFDdvgbN9nVWj1drm6I= +github.com/olekukonko/tablewriter v1.1.4/go.mod h1:+kedxuyTtgoZLwif3P1Em4hARJs+mVnzKxmsCL/C5RY= github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177 h1:nRlQD0u1871kaznCnn1EvYiMbum36v7hw1DLPEjds4o= github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177/go.mod h1:ao5zGxj8Z4x60IOVYZUbDSmt3R8Ddo080vEgPosHpak= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU= -github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU= -github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY= -github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= -github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/paulmach/orb v0.13.0 h1:r7n7mQGGF+cj/CbcivEj9J3HGK+XR+yXnvzRdq9saIw= +github.com/paulmach/orb v0.13.0/go.mod h1:6scRWINywA2Jf05dcjOfLfxrUIMECvTSG2MVbRLxu/k= +github.com/pierrec/lz4/v4 v4.1.26 h1:GrpZw1gZttORinvzBdXPUXATeqlJjqUG/D87TKMnhjY= +github.com/pierrec/lz4/v4 v4.1.26/go.mod h1:EoQMVJgeeEOMsCqCzqFm2O0cJvljX2nGZjcRIPL34O4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo= github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pusher/pusher-http-go/v5 v5.1.1 h1:ZLUGdLA8yXMvByafIkS47nvuXOHrYmlh4bsQvuZnYVQ= github.com/pusher/pusher-http-go/v5 v5.1.1/go.mod h1:Ibji4SGoUDtOy7CVRhCiEpgy+n5Xv6hSL/QqYOhmWW8= -github.com/redis/go-redis/extra/rediscmd/v9 v9.8.0 h1:/A+PnpT6ufTUt/6YPXiZlCRoyyfEnDag5WGrEK8Gq0I= -github.com/redis/go-redis/extra/rediscmd/v9 v9.8.0/go.mod h1:FGO4BNjl5TfH9U771826GIW2Ul4pOEqHAN+0xjfw+dU= -github.com/redis/go-redis/extra/redisotel/v9 v9.8.0 h1:mnKrl8WqyGJK4pletf2itS+Te/ng3Qm4YjtveY406J8= -github.com/redis/go-redis/extra/redisotel/v9 v9.8.0/go.mod h1:iObamxrrXt4hGWiCWv5BAs68xPYc/MfrLd34H9TaKyk= -github.com/redis/go-redis/v9 v9.8.0 h1:q3nRvjrlge/6UD7eTu/DSg2uYiU2mCL0G/uzBWqhicI= -github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= -github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM= -github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk= -github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= -github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM/9/g00= -github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= -github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= -github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= -github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= -github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= -github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= -github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= -github.com/sendgrid/rest v2.6.9+incompatible h1:1EyIcsNdn9KIisLW50MKwmSRSK+ekueiEMJ7NEoxJo0= -github.com/sendgrid/rest v2.6.9+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE= -github.com/sendgrid/sendgrid-go v3.16.0+incompatible h1:i8eE6IMkiCy7vusSdacHHSBUpXyTcTXy/Rl9N9aZ/Qw= -github.com/sendgrid/sendgrid-go v3.16.0+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8= +github.com/redis/go-redis/extra/rediscmd/v9 v9.19.0 h1:QL3vQTj64ZQpxiDZx6bFYS7oN37EdHHqiYGz3grgTRI= +github.com/redis/go-redis/extra/rediscmd/v9 v9.19.0/go.mod h1:kGroOkFJzE2Si+mojCi3PCvuAnGnzEh1FAzy1Oh9mI8= +github.com/redis/go-redis/extra/redisotel/v9 v9.19.0 h1:yXeFe+EFMUirnzzy8MI5iazoqlpBdzVC6pk+K2Mu7do= +github.com/redis/go-redis/extra/redisotel/v9 v9.19.0/go.mod h1:GgAFS1Cg26tQEiHzDd8cHXPKUzzTineQ91Ei9glAxQs= +github.com/redis/go-redis/v9 v9.19.0 h1:XPVaaPSnG6RhYf7p+rmSa9zZfeVAnWsH5h3lxthOm/k= +github.com/redis/go-redis/v9 v9.19.0/go.mod h1:v/M13XI1PVCDcm01VtPFOADfZtHf8YW3baQf57KlIkA= +github.com/richardlehane/mscfb v1.0.6 h1:eN3bvvZCp00bs7Zf52bxNwAx5lJDBK1tCuH19qq5aC8= +github.com/richardlehane/mscfb v1.0.6/go.mod h1:pe0+IUIc0AHh0+teNzBlJCtSyZdFOGgV4ZK9bsoV+Jo= +github.com/richardlehane/msoleps v1.0.6 h1:9BvkpjvD+iUBalUY4esMwv6uBkfOip/Lzvd93jvR9gg= +github.com/richardlehane/msoleps v1.0.6/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/rs/zerolog v1.35.1 h1:m7xQeoiLIiV0BCEY4Hs+j2NG4Gp2o2KPKmhnnLiazKI= +github.com/rs/zerolog v1.35.1/go.mod h1:EjML9kdfa/RMA7h/6z6pYmq1ykOuA8/mjWaEvGI+jcw= +github.com/segmentio/asm v1.2.1 h1:DTNbBqs57ioxAD4PrArqftgypG4/qNpXoJx8TVXxPR0= +github.com/segmentio/asm v1.2.1/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= -github.com/spiffe/go-spiffe/v2 v2.5.0 h1:N2I01KCUkv1FAjZXJMwh95KK1ZIQLYbPfhaxw8WS0hE= -github.com/spiffe/go-spiffe/v2 v2.5.0/go.mod h1:P+NxobPc6wXhVtINNtFjNWGBTreew1GBUCwT2wPmb7g= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= +github.com/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo= +github.com/spiffe/go-spiffe/v2 v2.6.0/go.mod h1:gm2SeUoMZEtpnzPNs2Csc0D/gX33k1xIx7lEzqblHEs= github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo= github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggo/files/v2 v2.0.2 h1:Bq4tgS/yxLB/3nwOMcul5oLEUKa877Ykgz3CJMVbQKU= github.com/swaggo/files/v2 v2.0.2/go.mod h1:TVqetIzZsO9OhHX1Am9sRf9LdrFZqoK49N37KON/jr0= -github.com/swaggo/swag v1.16.4 h1:clWJtd9LStiG3VeijiCfOVODP6VpHtKdQy9ELFG3s1A= -github.com/swaggo/swag v1.16.4/go.mod h1:VBsHJRsDvfYvqoiMKnsdwhNV9LEMHgEDZcyVYX0sxPg= +github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI= +github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg= github.com/thedevsaddam/govalidator v1.9.10 h1:m3dLRbSZ5Hts3VUWYe+vxLMG+FdyQuWOjzTeQRiMCvU= github.com/thedevsaddam/govalidator v1.9.10/go.mod h1:Ilx8u7cg5g3LXbSS943cx5kczyNuUn7LH/cK5MYuE90= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/uptrace/uptrace-go v1.35.1 h1:ZK+YwrPyZcpC9nJUrFiVogI8pBuPtlTbGyjs8LAhirk= -github.com/uptrace/uptrace-go v1.35.1/go.mod h1:N+XGgxkQP1/6iw8fvbP2PrkbK1adyTutLmMgm3Xw7x8= +github.com/tiendc/go-deepcopy v1.7.2 h1:Ut2yYR7W9tWjTQitganoIue4UGxZwCcJy3orjrrIj44= +github.com/tiendc/go-deepcopy v1.7.2/go.mod h1:4bKjNC2r7boYOkD2IOuZpYjmlDdzjbpTRyCx+goBCJQ= +github.com/uptrace/uptrace-go v1.43.0 h1:5QuCdyFJdWUEXx6Fr6sYfezdgO6n6lnkOvUTLlyQO7U= +github.com/uptrace/uptrace-go v1.43.0/go.mod h1:ehDTIdtBSolg4Z0CCvg1C8yR6VX1YFDqBcg2KmsXWn0= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0= -github.com/valyala/fasthttp v1.54.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM= -github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= -github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +github.com/valyala/fasthttp v1.71.0 h1:tepR7H+Guh9VUqxxcPggYi8R3lGUu2Rsdh+z7/FCY3k= +github.com/valyala/fasthttp v1.71.0/go.mod h1:z1sDUvOShhXq/C9mwH/fSm1Vb71tUJwmQdgkBrBNwnA= github.com/vanng822/css v1.0.1 h1:10yiXc4e8NI8ldU6mSrWmSWMuyWgPr9DZ63RSlsgDw8= github.com/vanng822/css v1.0.1/go.mod h1:tcnB1voG49QhCrwq1W0w5hhGasvOg+VQp9i9H1rCM1w= -github.com/vanng822/go-premailer v1.24.0 h1:b4MpHLVdlA7QOwk5OJIEvWnIpCCdEhEDQpJ/AkEYcpo= -github.com/vanng822/go-premailer v1.24.0/go.mod h1:gjLku4P5inmyu+MM7544lOjhaW8F3TdIqboFVcZGwZE= +github.com/vanng822/go-premailer v1.33.0 h1:nglIpKn/7e3kIAwYByiH5xpauFur7RwAucqyZ59hcic= +github.com/vanng822/go-premailer v1.33.0/go.mod h1:LGYI7ym6FQ7KcHN16LiQRF+tlan7qwhP1KEhpTINFpo= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= -github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= -github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7psK/lVsjIS2otl+1WyRyY= -github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= -github.com/xuri/excelize/v2 v2.9.0 h1:1tgOaEq92IOEumR1/JfYS/eR0KHOCsRv/rYXXh6YJQE= -github.com/xuri/excelize/v2 v2.9.0/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE= -github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A= -github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/xdg-go/scram v1.2.0 h1:bYKF2AEwG5rqd1BumT4gAnvwU/M9nBp2pTSxeZw7Wvs= +github.com/xdg-go/scram v1.2.0/go.mod h1:3dlrS0iBaWKYVt2ZfA4cj48umJZ+cAEbR6/SjLA88I8= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/xuri/efp v0.0.1 h1:fws5Rv3myXyYni8uwj2qKjVaRP30PdjeYe2Y6FDsCL8= +github.com/xuri/efp v0.0.1/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= +github.com/xuri/excelize/v2 v2.10.1 h1:V62UlqopMqha3kOpnlHy2CcRVw1V8E63jFoWUmMzxN0= +github.com/xuri/excelize/v2 v2.10.1/go.mod h1:iG5tARpgaEeIhTqt3/fgXCGoBRt4hNXgCp3tfXKoOIc= +github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 h1:+C0TIdyyYmzadGaL/HBLbf3WdLgC29pgyhTjAT/0nuE= +github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= +github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= +github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zeebo/errs v1.4.0 h1:XNdoD/RRMKP7HD0UhJnIzUy74ISdGGxURlYG8HSWSfM= -github.com/zeebo/errs v1.4.0/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4= -go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= -go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= -go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/contrib v1.27.0 h1:0dNzbHzLqdAT2qoHr9tooz2Iqh+QPyaW01UxNWPZmQ4= -go.opentelemetry.io/contrib v1.27.0/go.mod h1:Tmhw9grdWtmXy6DxZNpIAudzYJqLeEM2P6QTZQSRwU8= -go.opentelemetry.io/contrib/detectors/gcp v1.34.0 h1:JRxssobiPg23otYU5SbWtQC//snGVIM3Tx6QRzlQBao= -go.opentelemetry.io/contrib/detectors/gcp v1.34.0/go.mod h1:cV4BMFcscUR/ckqLkbfQmF0PRsq8w/lMGzdbCSveBHo= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 h1:x7wzEgXfnzJcHDwStJT+mxOz4etr2EcexjqhBvmoakw= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0/go.mod h1:rg+RlpR5dKwaS95IyyZqj5Wd4E13lk/msnTS0Xl9lJM= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 h1:sbiXRNDSWJOTobXh5HyQKjq6wUC5tNybqjIqDpAY4CU= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0/go.mod h1:69uWxva0WgAA/4bu2Yy70SLDBwZXuQ6PbBpbsa5iZrQ= -go.opentelemetry.io/contrib/instrumentation/runtime v0.60.0 h1:0NgN/3SYkqYJ9NBlDfl/2lzVlwos/YQLvi8sUrzJRBE= -go.opentelemetry.io/contrib/instrumentation/runtime v0.60.0/go.mod h1:oxpUfhTkhgQaYIjtBt3T3w135dLoxq//qo3WPlPIKkE= +github.com/yuin/goldmark v1.8.2 h1:kEGpgqJXdgbkhcOgBxkC0X0PmoPG1ZyoZ117rDVp4zE= +github.com/yuin/goldmark v1.8.2/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= +github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs= +github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s= +go.mongodb.org/mongo-driver/v2 v2.6.0 h1:b9sJOYrkmt4l8bY43ZenFBcPlhYIjaOfYHLtbB/5qi8= +go.mongodb.org/mongo-driver/v2 v2.6.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= +go.opentelemetry.io/contrib v1.43.0 h1:rv+pngknCr4qpZDxSpEvEoRioutgfbkk82x6MChJQ3U= +go.opentelemetry.io/contrib v1.43.0/go.mod h1:JYdNU7Pl/2ckKMGp8/G7zeyhEbtRmy9Q8bcrtv75Znk= +go.opentelemetry.io/contrib/detectors/gcp v1.43.0 h1:62yY3dT7/ShwOxzA0RsKRgshBmfElKI4d/Myu2OxDFU= +go.opentelemetry.io/contrib/detectors/gcp v1.43.0/go.mod h1:RyaZMFY7yi1kAs45S6mbFGz8O8rqB0dTY14uzvG4LCs= +go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo v0.0.0-20260513205827-ba143fc95a5e h1:OX282aWfZNOrSVUPF59HlRhyA+MDcyi4kI8WWXt6A8I= +go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo v0.0.0-20260513205827-ba143fc95a5e/go.mod h1:lw7VQzmNsmkZBRQqOQiREGxO3GtzG/pOVEmKufablmA= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.68.0 h1:0Qx7VGBacMm9ZENQ7TnNObTYI4ShC+lHI16seduaxZo= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.68.0/go.mod h1:Sje3i3MjSPKTSPvVWCaL8ugBzJwik3u4smCjUeuupqg= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.68.0 h1:CqXxU8VOmDefoh0+ztfGaymYbhdB/tT3zs79QaZTNGY= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.68.0/go.mod h1:BuhAPThV8PBHBvg8ZzZ/Ok3idOdhWIodywz2xEcRbJo= +go.opentelemetry.io/contrib/instrumentation/runtime v0.68.0 h1:jhVIQEprwUTV+KfzzliLidclhoTOoHTgdz96kAyR8mU= +go.opentelemetry.io/contrib/instrumentation/runtime v0.68.0/go.mod h1:4HsdbLUbernaTnA8CNaNE+1g026SciXb3juRYe3l8EY= +go.opentelemetry.io/contrib/processors/minsev v0.16.0 h1:bjTZkvAKnG1mqWgCjU7RkOkHRTMsGlJO/UlqjRCweeU= +go.opentelemetry.io/contrib/processors/minsev v0.16.0/go.mod h1:R2mmaDsqsWb+Y0mQkPifiCwifdotrG4fFoD4z0tim+g= go.opentelemetry.io/contrib/propagators/b3 v1.19.0 h1:ulz44cpm6V5oAeg5Aw9HyqGFMS6XM7untlMEhD7YzzA= go.opentelemetry.io/contrib/propagators/b3 v1.19.0/go.mod h1:OzCmE2IVS+asTI+odXQstRGVfXQ4bXv9nMBRK0nNyqQ= -go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= -go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= -go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.11.0 h1:C/Wi2F8wEmbxJ9Kuzw/nhP+Z9XaHYMkyDmXy6yR2cjw= -go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.11.0/go.mod h1:0Lr9vmGKzadCTgsiBydxr6GEZ8SsZ7Ks53LzjWG5Ar4= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.35.0 h1:0NIXxOCFx+SKbhCVxwl3ETG8ClLPAa0KuKV6p3yhxP8= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.35.0/go.mod h1:ChZSJbbfbl/DcRZNc9Gqh6DYGlfjw4PvO1pEOZH1ZsE= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 h1:1fTNlAIJZGWLP5FVu0fikVry1IsiUnXjf7QFvoNN3Xw= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0/go.mod h1:zjPK58DtkqQFn+YUMbx0M2XV3QgKU0gS9LeGohREyK4= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 h1:xJ2qHD0C1BeYVTLLR9sX12+Qb95kfeD/byKj6Ky1pXg= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0/go.mod h1:u5BF1xyjstDowA1R5QAO9JHzqK+ublenEW/dyqTjBVk= -go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.29.0 h1:WDdP9acbMYjbKIyJUhTvtzj601sVJOqgWdUxSdR/Ysc= -go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.29.0/go.mod h1:BLbf7zbNIONBLPwvFnwNHGj4zge8uTCM/UPIVW1Mq2I= -go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.35.0 h1:T0Ec2E+3YZf5bgTNQVet8iTDW7oIk03tXHq+wkwIDnE= -go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.35.0/go.mod h1:30v2gqH+vYGJsesLWFov8u47EpYTcIQcBjKpI6pJThg= -go.opentelemetry.io/otel/log v0.11.0 h1:c24Hrlk5WJ8JWcwbQxdBqxZdOK7PcP/LFtOtwpDTe3Y= -go.opentelemetry.io/otel/log v0.11.0/go.mod h1:U/sxQ83FPmT29trrifhQg+Zj2lo1/IPN1PF6RTFqdwc= -go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= -go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= +go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= +go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0 h1:HIBTQ3VO5aupLKjC90JgMqpezVXwFuq6Ryjn0/izoag= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0/go.mod h1:ji9vId85hMxqfvICA0Jt8JqEdrXaAkcpkI9HPXya0ro= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0 h1:w1K+pCJoPpQifuVpsKamUdn9U0zM3xUziVOqsGksUrY= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0/go.mod h1:HBy4BjzgVE8139ieRI75oXm3EcDN+6GhD88JT1Kjvxg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 h1:88Y4s2C8oTui1LGM6bTWkw0ICGcOLCAI5l6zsD1j20k= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0/go.mod h1:Vl1/iaggsuRlrHf/hfPJPvVag77kKyvrLeD10kpMl+A= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 h1:3iZJKlCZufyRzPzlQhUIWVmfltrXuGyfjREgGP3UUjc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0/go.mod h1:/G+nUPfhq2e+qiXMGxMwumDrP5jtzU+mWN7/sjT2rak= +go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.43.0 h1:TC+BewnDpeiAmcscXbGMfxkO+mwYUwE/VySwvw88PfA= +go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.43.0/go.mod h1:J/ZyF4vfPwsSr9xJSPyQ4LqtcTPULFR64KwTikGLe+A= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 h1:mS47AX77OtFfKG4vtp+84kuGSFZHTyxtXIN269vChY0= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0/go.mod h1:PJnsC41lAGncJlPUniSwM81gc80GkgWJWr3cu2nKEtU= +go.opentelemetry.io/otel/log v0.19.0 h1:KUZs/GOsw79TBBMfDWsXS+KZ4g2Ckzksd1ymzsIEbo4= +go.opentelemetry.io/otel/log v0.19.0/go.mod h1:5DQYeGmxVIr4n0/BcJvF4upsraHjg6vudJJpnkL6Ipk= +go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= +go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= go.opentelemetry.io/otel/oteltest v1.0.0-RC3 h1:MjaeegZTaX0Bv9uB9CrdVjOFM/8slRjReoWoV9xDCpY= go.opentelemetry.io/otel/oteltest v1.0.0-RC3/go.mod h1:xpzajI9JBRr7gX63nO6kAmImmYIAtuQblZ36Z+LfCjE= -go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY= -go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg= -go.opentelemetry.io/otel/sdk/log v0.11.0 h1:7bAOpjpGglWhdEzP8z0VXc4jObOiDEwr3IYbhBnjk2c= -go.opentelemetry.io/otel/sdk/log v0.11.0/go.mod h1:dndLTxZbwBstZoqsJB3kGsRPkpAgaJrWfQg3lhlHFFY= -go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o= -go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w= -go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= -go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= -go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4= -go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4= +go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= +go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= +go.opentelemetry.io/otel/sdk/log v0.19.0 h1:scYVLqT22D2gqXItnWiocLUKGH9yvkkeql5dBDiXyko= +go.opentelemetry.io/otel/sdk/log v0.19.0/go.mod h1:vFBowwXGLlW9AvpuF7bMgnNI95LiW10szrOdvzBHlAg= +go.opentelemetry.io/otel/sdk/log/logtest v0.19.0 h1:BEbF7ZBB6qQloV/Ub1+3NQoOUnVtcGkU3XX4Ws3GQfk= +go.opentelemetry.io/otel/sdk/log/logtest v0.19.0/go.mod h1:Lua81/3yM0wOmoHTokLj9y9ADeA02v1naRrVrkAZuKk= +go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= +go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= +go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= +go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= +go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g= +go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= -go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo= +go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= -golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= -golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw= -golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM= -golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= -golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI= +golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8= +golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ= +golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= -golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= +golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM= +golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= @@ -427,40 +443,33 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= -golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= -golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= -golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= -golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= +golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA= +golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs= +golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs= +golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= -golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ= +golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -472,7 +481,6 @@ golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= @@ -481,43 +489,39 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= -golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= -golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= -golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= +golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= +golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= +golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= +golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= -golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU= -golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ= +golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c= +golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.231.0 h1:LbUD5FUl0C4qwia2bjXhCMH65yz1MLPzA/0OYEsYY7Q= -google.golang.org/api v0.231.0/go.mod h1:H52180fPI/QQlUc0F4xWfGZILdv09GCWKt2bcsn164A= +gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= +gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= +google.golang.org/api v0.277.0 h1:HJfyJUiNeBBUMai7ez8u14wkp/gH/I4wpGbbO9o+cSk= +google.golang.org/api v0.277.0/go.mod h1:B9TqLBwJqVjp1mtt7WeoQwWRwvu/400y5lETOql+giQ= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb h1:ITgPrl429bc6+2ZraNSzMDk3I95nmQln2fuPstKwFDE= -google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb/go.mod h1:sAo5UzpjUwgFBCzupwhcLcxHVDK7vG5IqI30YnwX2eE= -google.golang.org/genproto/googleapis/api v0.0.0-20250422160041-2d3770c4ea7f h1:tjZsroqekhC63+WMqzmWyW5Twj/ZfR5HAlpd5YQ1Vs0= -google.golang.org/genproto/googleapis/api v0.0.0-20250422160041-2d3770c4ea7f/go.mod h1:Cd8IzgPo5Akum2c9R6FsXNaZbH3Jpa2gpHlW89FqlyQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197 h1:29cjnHVylHwTzH66WfFZqgSQgnxzvWE+jvBwpZCLRxY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= -google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM= -google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= +google.golang.org/genproto v0.0.0-20260504160031-60b97b32f348 h1:JjVGDZYWkJWZcxveJGzfkXC5myDVWAd4dZdgbzrDUv8= +google.golang.org/genproto v0.0.0-20260504160031-60b97b32f348/go.mod h1:95PqD4xM+AdOcBGsmgfaofXsiA37uXDtDufVbntT3TU= +google.golang.org/genproto/googleapis/api v0.0.0-20260504160031-60b97b32f348 h1:U8orV30l6KpDsi9dxU0CoJZGbjS8EEpw+6ba+XwGPQA= +google.golang.org/genproto/googleapis/api v0.0.0-20260504160031-60b97b32f348/go.mod h1:Yzdzr5OOZFgSsEV2D/Xi9NL3bszpXFAg0hFJiRohcD8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260504160031-60b97b32f348 h1:pfIbyB44sWzHiCpRqIen67ZQnVXSfIxWrqUMk1qwODE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260504160031-60b97b32f348/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.81.0 h1:W3G9N3KQf3BU+YuCtGKJk0CmxQNbAISICD/9AORxLIw= +google.golang.org/grpc v1.81.0/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= -google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/stretchr/testify.v1 v1.2.2 h1:yhQC6Uy5CqibAIlk1wlusa/MJ3iAN49/BsR/dCCKz3M= @@ -525,16 +529,15 @@ gopkg.in/stretchr/testify.v1 v1.2.2/go.mod h1:QI5V/q6UbPmuhtm10CaFZxED9NreB8PnFY gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/clickhouse v0.6.1 h1:t7JMB6sLBXxN8hEO6RdzCbJCwq/jAEVZdwXlmQs1Sd4= -gorm.io/driver/clickhouse v0.6.1/go.mod h1:riMYpJcGZ3sJ/OAZZ1rEP1j/Y0H6cByOAnwz7fo2AyM= -gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= -gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= -gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= -gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= -gorm.io/driver/sqlite v1.5.0 h1:zKYbzRCpBrT1bNijRnxLDJWPjVfImGEn0lSnUY5gZ+c= -gorm.io/driver/sqlite v1.5.0/go.mod h1:kDMDfntV9u/vuMmz8APHtHF0b4nyBB7sfCieC6G8k8I= -gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= -gorm.io/gorm v1.26.0 h1:9lqQVPG5aNNS6AyHdRiwScAVnXHg/L/Srzx55G5fOgs= -gorm.io/gorm v1.26.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= -gorm.io/plugin/opentelemetry v0.1.13 h1:aUtOF1vXPxYGHKW93ULAG9WmNBNT3F+fLx4zrV4duQg= -gorm.io/plugin/opentelemetry v0.1.13/go.mod h1:ZAp4v5vU1CCcK9Oo8/va5rl6NStrzpSU+a70evd+W/g= +gorm.io/driver/clickhouse v0.7.0 h1:BCrqvgONayvZRgtuA6hdya+eAW5P2QVagV3OlEp1vtA= +gorm.io/driver/clickhouse v0.7.0/go.mod h1:TmNo0wcVTsD4BBObiRnCahUgHJHjBIwuRejHwYt3JRs= +gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg= +gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo= +gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4= +gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo= +gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= +gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8= +gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg= +gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= +gorm.io/plugin/opentelemetry v0.1.16 h1:Kypj2YYAliJqkIczDZDde6P6sFMhKSlG5IpngMFQGpc= +gorm.io/plugin/opentelemetry v0.1.16/go.mod h1:P3RmTeZXT+9n0F1ccUqR5uuTvEXDxF8k2UpO7mTIB2Y= diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go index 20bbc780..df2e5d6f 100644 --- a/api/pkg/di/container.go +++ b/api/pkg/di/container.go @@ -7,21 +7,23 @@ import ( "net/http" "os" "strconv" + "strings" "time" - "github.com/pusher/pusher-http-go/v5" - "github.com/NdoleStudio/httpsms/docs" + plunk "github.com/NdoleStudio/plunk-go" + "github.com/pusher/pusher-http-go/v5" otelMetric "go.opentelemetry.io/otel/metric" - "github.com/dgraph-io/ristretto" + "github.com/dgraph-io/ristretto/v2" "github.com/gofiber/contrib/otelfiber" "gorm.io/plugin/opentelemetry/tracing" "github.com/NdoleStudio/httpsms/pkg/discord" + "cloud.google.com/go/storage" mexporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric" cloudtrace "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" "github.com/NdoleStudio/httpsms/pkg/cache" @@ -45,7 +47,6 @@ import ( "go.opentelemetry.io/otel/sdk/resource" semconv "go.opentelemetry.io/otel/semconv/v1.10.0" - "firebase.google.com/go/messaging" "github.com/hirosassa/zerodriver" "github.com/rs/zerolog" "go.opentelemetry.io/otel/sdk/trace" @@ -55,6 +56,7 @@ import ( "github.com/NdoleStudio/httpsms/pkg/middlewares" "google.golang.org/api/option" + "github.com/gofiber/fiber/v2/middleware/compress" "github.com/gofiber/fiber/v2/middleware/cors" "github.com/NdoleStudio/httpsms/pkg/entities" @@ -71,19 +73,25 @@ import ( "github.com/NdoleStudio/httpsms/pkg/handlers" "github.com/NdoleStudio/httpsms/pkg/telemetry" "github.com/NdoleStudio/httpsms/pkg/validators" + mongoDriver "go.mongodb.org/mongo-driver/v2/mongo" "gorm.io/driver/postgres" gormLogger "gorm.io/gorm/logger" ) // Container is used to resolve services at runtime type Container struct { - projectID string - db *gorm.DB - dedicatedDB *gorm.DB - version string - app *fiber.App - eventDispatcher *services.EventDispatcher - logger telemetry.Logger + projectID string + db *gorm.DB + dedicatedDB *gorm.DB + mongoDB *mongoDriver.Database + version string + app *fiber.App + eventDispatcher *services.EventDispatcher + logger telemetry.Logger + attachmentRepository repositories.AttachmentRepository + userRistrettoCache *ristretto.Cache[string, entities.AuthContext] + phoneRistrettoCache *ristretto.Cache[string, *entities.Phone] + inMemoryCache cache.Cache } // NewLiteContainer creates a Container without any routes or listeners @@ -115,6 +123,7 @@ func NewContainer(projectID string, version string) (container *Container) { container.RegisterMessageListeners() container.RegisterMessageRoutes() + container.RegisterAttachmentRoutes() container.RegisterBulkMessageRoutes() container.RegisterMessageThreadRoutes() @@ -124,9 +133,12 @@ func NewContainer(projectID string, version string) (container *Container) { container.RegisterHeartbeatListeners() container.RegisterUserRoutes() + container.RegisterMessageSendScheduleRoutes() + container.RegisterMessageSendScheduleListeners() container.RegisterUserListeners() container.RegisterPhoneRoutes() + container.RegisterPhoneListeners() container.RegisterEventRoutes() @@ -169,6 +181,15 @@ func (container *Container) App() (app *fiber.App) { app = fiber.New() + // Health check endpoint registered before middleware for reliable Docker health checks + app.Get("/health", func(c *fiber.Ctx) error { + return c.SendStatus(fiber.StatusOK) + }) + + app.Use(compress.New(compress.Config{ + Level: compress.LevelBestCompression, + })) + if os.Getenv("USE_HTTP_LOGGER") == "true" { app.Use(fiberLogger.New()) } @@ -227,6 +248,10 @@ func (container *Container) GormLogger() gormLogger.Interface { ) } +func (container *Container) connect(dsn string, config *gorm.Config) (db *gorm.DB, err error) { + return gorm.Open(postgres.Open(dsn), config) +} + // DedicatedDB creates an instance of gorm.DB if it has not been created already func (container *Container) DedicatedDB() (db *gorm.DB) { container.logger.Debug(fmt.Sprintf("creating %T", db)) @@ -241,23 +266,21 @@ func (container *Container) DedicatedDB() (db *gorm.DB) { config = &gorm.Config{Logger: container.GormLogger()} } - db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL_DEDICATED")), config) + db, err := container.connect(os.Getenv("DATABASE_URL_DEDICATED"), config) if err != nil { container.logger.Fatal(err) } - sqlDB, err := db.DB() - if err != nil { - container.logger.Fatal(stacktrace.Propagate(err, "cannot get sql.DB from GORM")) - } - - sqlDB.SetMaxOpenConns(2) - sqlDB.SetConnMaxLifetime(time.Hour) - if err = db.Use(tracing.NewPlugin()); err != nil { container.logger.Fatal(stacktrace.Propagate(err, "cannot use GORM tracing plugin")) } + container.dedicatedDB = db + if os.Getenv("DATABASE_MIGRATION_SKIP") != "" { + container.logger.Debug(fmt.Sprintf("skipping migrations for [%T]", db)) + return container.dedicatedDB + } + container.logger.Debug(fmt.Sprintf("Running migrations for dedicated [%T]", db)) if err = db.AutoMigrate(&entities.Heartbeat{}); err != nil { container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Heartbeat{}))) @@ -267,10 +290,26 @@ func (container *Container) DedicatedDB() (db *gorm.DB) { container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.HeartbeatMonitor{}))) } - container.dedicatedDB = db return container.dedicatedDB } +// MongoDB creates a *mongo.Database connection to MongoDB Atlas +func (container *Container) MongoDB() *mongoDriver.Database { + if container.mongoDB != nil { + return container.mongoDB + } + + container.logger.Debug("creating MongoDB *mongo.Database connection") + + db, err := repositories.NewMongoDB(os.Getenv("MONGODB_URI")) + if err != nil { + container.logger.Fatal(err) + } + + container.mongoDB = db + return container.mongoDB +} + // DBWithoutMigration creates an instance of gorm.DB if it has not been created already func (container *Container) DBWithoutMigration() (db *gorm.DB) { if container.db != nil { @@ -319,13 +358,21 @@ func (container *Container) DB() (db *gorm.DB) { container.logger.Fatal(stacktrace.Propagate(err, "cannot use GORM tracing plugin")) } + if os.Getenv("DATABASE_MIGRATION_SKIP") != "" { + container.logger.Debug(fmt.Sprintf("skipping migrations for [%T]", db)) + return container.db + } + container.logger.Debug(fmt.Sprintf("Running migrations for %T", db)) // This prevents a bug in the Gorm AutoMigrate where it tries to delete this no existent constraints - db.Exec(` + // This is only applicable to PROD on cockroachDB + if os.Getenv("DATABASE_MIGRATION_CONSTRAINT_FIX") == "1" { + db.Exec(` ALTER TABLE users ADD CONSTRAINT IF NOT EXISTS uni_users_api_key CHECK (api_key IS NOT NULL); ALTER TABLE phone_api_keys ADD CONSTRAINT IF NOT EXISTS uni_phone_api_keys_api_key CHECK (api_key IS NOT NULL); ALTER TABLE discords ADD CONSTRAINT IF NOT EXISTS uni_discords_server_id CHECK (server_id IS NOT NULL);`) + } if err = db.AutoMigrate(&entities.Message{}); err != nil { container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Message{}))) @@ -339,6 +386,10 @@ ALTER TABLE discords ADD CONSTRAINT IF NOT EXISTS uni_discords_server_id CHECK ( container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.User{}))) } + if err = db.AutoMigrate(&entities.MessageSendSchedule{}); err != nil { + container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.MessageSendSchedule{}))) + } + if err = db.AutoMigrate(&entities.Phone{}); err != nil { container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Phone{}))) } @@ -373,6 +424,7 @@ ALTER TABLE discords ADD CONSTRAINT IF NOT EXISTS uni_discords_server_id CHECK ( // FirebaseApp creates a new instance of firebase.App func (container *Container) FirebaseApp() (app *firebase.App) { container.logger.Debug(fmt.Sprintf("creating %T", app)) + app, err := firebase.NewApp(context.Background(), nil, option.WithCredentialsJSON(container.FirebaseCredentials())) if err != nil { msg := "cannot initialize firebase application" @@ -381,11 +433,15 @@ func (container *Container) FirebaseApp() (app *firebase.App) { return app } -// InMemoryCache creates a new instance of the in memory cache.Cache +// InMemoryCache returns the shared in-memory cache.Cache, creating it on the first call. func (container *Container) InMemoryCache() cache.Cache { + if container.inMemoryCache != nil { + return container.inMemoryCache + } container.logger.Debug("creating an in memory cache") c := ttlCache.New(time.Hour, time.Hour*2) - return cache.NewMemoryCache(container.Tracer(), c) + container.inMemoryCache = cache.NewMemoryCache(container.Tracer(), c) + return container.inMemoryCache } // Cache creates a new instance of cache.Cache @@ -395,8 +451,10 @@ func (container *Container) Cache() cache.Cache { if err != nil { container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot parse redis url [%s]", os.Getenv("REDIS_URL")))) } - opt.TLSConfig = &tls.Config{ - MinVersion: tls.VersionTLS12, + if strings.HasPrefix(os.Getenv("REDIS_URL"), "rediss://") { + opt.TLSConfig = &tls.Config{ + MinVersion: tls.VersionTLS12, + } } redisClient := redis.NewClient(opt) @@ -482,15 +540,27 @@ func (container *Container) CloudTaskEventsQueue() (queue services.PushQueue) { ) } -// FirebaseMessagingClient creates a new instance of messaging.Client -func (container *Container) FirebaseMessagingClient() (client *messaging.Client) { - container.logger.Debug(fmt.Sprintf("creating %T", client)) +// FCMClient creates the appropriate FCM client based on configuration. +// When FCM_ENDPOINT is set, it returns an EmulatorFCMClient that sends +// notifications directly to the phone emulator via HTTP. +// Otherwise, it returns a FirebaseFCMClient that uses the real Firebase SDK. +func (container *Container) FCMClient() services.FCMClient { + if fcmEndpoint := os.Getenv("FCM_ENDPOINT"); fcmEndpoint != "" { + container.logger.Info(fmt.Sprintf("using emulator FCM client with endpoint: %s", fcmEndpoint)) + return services.NewEmulatorFCMClient( + container.HTTPClient("emulator_fcm"), + fcmEndpoint, + container.Logger(), + ) + } + + container.logger.Debug("creating FirebaseFCMClient") messagingClient, err := container.FirebaseApp().Messaging(context.Background()) if err != nil { msg := "cannot initialize firebase messaging client" container.logger.Fatal(stacktrace.Propagate(err, msg)) } - return messagingClient + return services.NewFirebaseFCMClient(messagingClient) } // FirebaseCredentials returns firebase credentials as bytes. @@ -516,6 +586,7 @@ func (container *Container) MessageHandlerValidator() (validator *validators.Mes container.Tracer(), container.PhoneService(), container.TurnstileTokenValidator(), + container.Cache(), ) } @@ -538,6 +609,7 @@ func (container *Container) BulkMessageHandlerValidator() (validator *validators container.Tracer(), container.PhoneService(), container.UserService(), + container.Cache(), ) } @@ -638,6 +710,7 @@ func (container *Container) PhoneHandlerValidator() (validator *validators.Phone return validators.NewPhoneHandlerValidator( container.Logger(), container.Tracer(), + container.MessageSendScheduleService(), ) } @@ -647,6 +720,7 @@ func (container *Container) UserHandlerValidator() (validator *validators.UserHa return validators.NewUserHandlerValidator( container.Logger(), container.Tracer(), + container.UserService(), ) } @@ -721,6 +795,49 @@ func (container *Container) PhoneRepository() (repository repositories.PhoneRepo container.Logger(), container.Tracer(), container.DB(), + container.PhoneRistrettoCache(), + ) +} + +// MessageSendScheduleRepository creates a new instance of repositories.MessageSendScheduleRepository +func (container *Container) MessageSendScheduleRepository() repositories.MessageSendScheduleRepository { + container.logger.Debug("creating GORM repositories.MessageSendScheduleRepository") + return repositories.NewGormMessageSendScheduleRepository( + container.Logger(), + container.Tracer(), + container.DB(), + ) +} + +// MessageSendScheduleService creates a new instance of services.MessageSendScheduleService +func (container *Container) MessageSendScheduleService() *services.MessageSendScheduleService { + container.logger.Debug("creating services.MessageSendScheduleService") + return services.NewMessageSendScheduleService( + container.Logger(), + container.Tracer(), + container.MessageSendScheduleRepository(), + container.EventDispatcher(), + ) +} + +// MessageSendScheduleHandlerValidator creates a new instance of validators.MessageSendScheduleHandlerValidator +func (container *Container) MessageSendScheduleHandlerValidator() *validators.MessageSendScheduleHandlerValidator { + container.logger.Debug("creating validators.MessageSendScheduleHandlerValidator") + return validators.NewMessageSendScheduleHandlerValidator( + container.Logger(), + container.Tracer(), + ) +} + +// MessageSendScheduleHandler creates a new instance of handlers.MessageSendScheduleHandler +func (container *Container) MessageSendScheduleHandler() *handlers.MessageSendScheduleHandler { + container.logger.Debug("creating handlers.MessageSendScheduleHandler") + return handlers.NewMessageSendScheduleHandler( + container.Logger(), + container.Tracer(), + container.MessageSendScheduleHandlerValidator(), + container.MessageSendScheduleService(), + container.EntitlementService(), ) } @@ -734,6 +851,17 @@ func (container *Container) BillingUsageRepository() (repository repositories.Bi ) } +// EntitlementService creates a new instance of services.EntitlementService +func (container *Container) EntitlementService() *services.EntitlementService { + container.logger.Debug("creating services.EntitlementService") + return services.NewEntitlementService( + container.Logger(), + container.Tracer(), + os.Getenv("ENTITLEMENT_ENABLED") == "true", + container.UserRepository(), + ) +} + // DiscordRepository creates a new instance of repositories.DiscordRepository func (container *Container) DiscordRepository() (repository repositories.DiscordRepository) { container.logger.Debug("creating GORM repositories.DiscordRepository") @@ -776,12 +904,22 @@ func (container *Container) MessageThreadRepository() (repository repositories.M // HeartbeatMonitorRepository creates a new instance of repositories.HeartbeatMonitorRepository func (container *Container) HeartbeatMonitorRepository() (repository repositories.HeartbeatMonitorRepository) { - container.logger.Debug("creating GORM repositories.HeartbeatMonitorRepository") - return repositories.NewGormHeartbeatMonitorRepository( - container.Logger(), - container.Tracer(), - container.DedicatedDB(), - ) + switch os.Getenv("HEARTBEAT_DB_BACKEND") { + case "mongodb": + container.logger.Debug("creating MongoDB repositories.HeartbeatMonitorRepository") + return repositories.NewMongoHeartbeatMonitorRepository( + container.Logger(), + container.Tracer(), + container.MongoDB(), + ) + default: + container.logger.Debug("creating GORM repositories.HeartbeatMonitorRepository") + return repositories.NewGormHeartbeatMonitorRepository( + container.Logger(), + container.Tracer(), + container.DedicatedDB(), + ) + } } // HeartbeatService creates a new instance of services.HeartbeatService @@ -828,7 +966,10 @@ func (container *Container) WebhookService() (service *services.WebhookService) return services.NewWebhookService( container.Logger(), container.Tracer(), - container.HTTPClient("webhook"), + &http.Client{ + Timeout: 6 * time.Second, + Transport: container.HTTPRoundTripperWithoutRetry("webhook"), + }, container.WebhookRepository(), container.EventDispatcher(), ) @@ -865,6 +1006,16 @@ func (container *Container) HTTPRoundTripper(name string) http.RoundTripper { ) } +// HTTPRoundTripperWithoutRetry creates an open telemetry http.RoundTripper without retry +func (container *Container) HTTPRoundTripperWithoutRetry(name string) http.RoundTripper { + container.logger.Debug(fmt.Sprintf("Debug: initializing %s %T", name, http.DefaultTransport)) + return otelroundtripper.New( + otelroundtripper.WithName(name), + otelroundtripper.WithMeter(otel.GetMeterProvider().Meter(container.projectID)), + otelroundtripper.WithAttributes(container.OtelResources(container.version, container.projectID).Attributes()...), + ) +} + // OtelResources generates default open telemetry resources func (container *Container) OtelResources(version string, namespace string) *resource.Resource { return resource.NewWithAttributes( @@ -881,6 +1032,7 @@ func (container *Container) RetryHTTPRoundTripper() http.RoundTripper { container.logger.Debug(fmt.Sprintf("initializing retry %T", http.DefaultTransport)) retryClient := retryablehttp.NewClient() retryClient.Logger = container.Logger() + retryClient.RetryMax = 2 return retryClient.StandardClient().Transport } @@ -902,8 +1054,7 @@ func (container *Container) MarketingService() (service *services.MarketingServi container.Logger(), container.Tracer(), container.FirebaseAuthClient(), - os.Getenv("SENDGRID_API_KEY"), - os.Getenv("SENDGRID_LIST_ID"), + container.PlunkClient(), ) } @@ -916,10 +1067,10 @@ func (container *Container) UserService() (service *services.UserService) { container.UserRepository(), container.Mailer(), container.UserEmailFactory(), - container.MarketingService(), container.LemonsqueezyClient(), container.EventDispatcher(), container.FirebaseAuthClient(), + container.HTTPClient("lemonsqueezy"), ) } @@ -1055,6 +1206,20 @@ func (container *Container) RegisterMessageListeners() { } } +// RegisterMessageSendScheduleListeners registers event listeners for listeners.MessageSendScheduleListener +func (container *Container) RegisterMessageSendScheduleListeners() { + container.logger.Debug(fmt.Sprintf("registering listeners for %T", listeners.MessageSendScheduleListener{})) + _, routes := listeners.NewMessageSendScheduleListener( + container.Logger(), + container.Tracer(), + container.MessageSendScheduleService(), + ) + + for event, handler := range routes { + container.EventDispatcher().Subscribe(event, handler) + } +} + // LemonsqueezyService creates a new instance of services.LemonsqueezyService func (container *Container) LemonsqueezyService() (service *services.LemonsqueezyService) { container.logger.Debug(fmt.Sprintf("creating %T", service)) @@ -1099,6 +1264,7 @@ func (container *Container) PhoneAPIKeyHandler() (handler *handlers.PhoneAPIKeyH container.Tracer(), container.PhoneAPIKeyHandlerValidator(), container.PhoneAPIKeyService(), + container.EntitlementService(), ) } @@ -1168,6 +1334,16 @@ func (container *Container) DiscordClient() (client *discord.Client) { ) } +// PlunkClient creates a new instance of plunk.Client +func (container *Container) PlunkClient() (client *plunk.Client) { + container.logger.Debug(fmt.Sprintf("creating %T", client)) + return plunk.New( + plunk.WithHTTPClient(container.HTTPClient("plunk")), + plunk.WithSecretKey(os.Getenv("PLUNK_SECRET_KEY")), + plunk.WithPublicKey(os.Getenv("PLUNK_PUBLIC_KEY")), + ) +} + // RegisterLemonsqueezyRoutes registers routes for the /lemonsqueezy prefix func (container *Container) RegisterLemonsqueezyRoutes() { container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.LemonsqueezyHandler{})) @@ -1293,6 +1469,12 @@ func (container *Container) RegisterDiscordListeners() { // RegisterMarketingListeners registers event listeners for listeners.MarketingListener func (container *Container) RegisterMarketingListeners() { container.logger.Debug(fmt.Sprintf("registering listeners for %T", listeners.MarketingListener{})) + + if os.Getenv("PLUNK_SECRET_KEY") == "" { + container.logger.Debug("skipping marketing listeners because the PLUNK_SECRET_KEY env variable is not set") + return + } + _, routes := listeners.NewMarketingListener( container.Logger(), container.Tracer(), @@ -1332,6 +1514,20 @@ func (container *Container) RegisterPhoneAPIKeyListeners() { } } +// RegisterPhoneListeners registers event listeners for listeners.PhoneListener +func (container *Container) RegisterPhoneListeners() { + container.logger.Debug(fmt.Sprintf("registering listeners for %T", listeners.PhoneListener{})) + _, routes := listeners.NewPhoneListener( + container.Logger(), + container.Tracer(), + container.PhoneService(), + ) + + for event, handler := range routes { + container.EventDispatcher().Subscribe(event, handler) + } +} + // RegisterWebsocketListeners registers event listeners for listeners.WebsocketListener func (container *Container) RegisterWebsocketListeners() { container.logger.Debug(fmt.Sprintf("registering listeners for %T", listeners.WebsocketListener{})) @@ -1375,9 +1571,63 @@ func (container *Container) MessageService() (service *services.MessageService) container.MessageRepository(), container.EventDispatcher(), container.PhoneService(), + container.AttachmentRepository(), + container.APIBaseURL(), ) } +// AttachmentRepository creates a cached AttachmentRepository based on configuration +func (container *Container) AttachmentRepository() repositories.AttachmentRepository { + if container.attachmentRepository != nil { + return container.attachmentRepository + } + + bucket := os.Getenv("GCS_BUCKET_NAME") + if bucket != "" { + container.logger.Debug("creating GoogleCloudStorageAttachmentRepository") + client, err := storage.NewClient(context.Background(), option.WithAuthCredentialsJSON(option.ServiceAccount, container.FirebaseCredentials())) + if err != nil { + container.logger.Fatal(stacktrace.Propagate(err, "cannot create GCS client")) + } + container.attachmentRepository = repositories.NewGoogleCloudStorageAttachmentRepository( + container.Logger(), + container.Tracer(), + client, + bucket, + ) + } else { + container.logger.Debug("creating MemoryAttachmentRepository (GCS_BUCKET_NAME not set)") + container.attachmentRepository = repositories.NewMemoryAttachmentRepository( + container.Logger(), + container.Tracer(), + ) + } + + return container.attachmentRepository +} + +// APIBaseURL returns the API base URL derived from EVENTS_QUEUE_ENDPOINT +func (container *Container) APIBaseURL() string { + endpoint := os.Getenv("EVENTS_QUEUE_ENDPOINT") + return strings.TrimSuffix(endpoint, "/v1/events") +} + +// AttachmentHandler creates a new AttachmentHandler +func (container *Container) AttachmentHandler() (handler *handlers.AttachmentHandler) { + container.logger.Debug(fmt.Sprintf("creating %T", handler)) + return handlers.NewAttachmentHandler( + container.Logger(), + container.Tracer(), + container.AttachmentRepository(), + ) +} + +// RegisterAttachmentRoutes registers routes for the /attachments prefix +func (container *Container) RegisterAttachmentRoutes() { + container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.AttachmentHandler{})) + container.AttachmentHandler().RegisterRoutes(container.App()) +} + // PhoneAPIKeyService creates a new instance of services.PhoneAPIKeyService func (container *Container) PhoneAPIKeyService() (service *services.PhoneAPIKeyService) { container.logger.Debug(fmt.Sprintf("creating %T", service)) @@ -1395,9 +1645,10 @@ func (container *Container) NotificationService() (service *services.PhoneNotifi return services.NewNotificationService( container.Logger(), container.Tracer(), - container.FirebaseMessagingClient(), + container.FCMClient(), container.PhoneRepository(), container.PhoneNotificationRepository(), + container.MessageSendScheduleRepository(), container.EventDispatcher(), ) } @@ -1405,8 +1656,8 @@ func (container *Container) NotificationService() (service *services.PhoneNotifi // RegisterMessageRoutes registers routes for the /messages prefix func (container *Container) RegisterMessageRoutes() { container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.MessageHandler{})) - container.MessageHandler().RegisterRoutes(container.App(), container.AuthenticatedMiddleware()) container.MessageHandler().RegisterPhoneAPIKeyRoutes(container.App(), container.PhoneAPIKeyMiddleware(), container.AuthenticatedMiddleware()) + container.MessageHandler().RegisterRoutes(container.App(), container.AuthenticatedMiddleware()) } // RegisterBulkMessageRoutes registers routes for the /bulk-messages prefix @@ -1453,6 +1704,12 @@ func (container *Container) RegisterUserRoutes() { container.UserHandler().RegisterRoutes(container.App(), container.AuthenticatedMiddleware()) } +// RegisterMessageSendScheduleRoutes registers routes for the /send-schedules prefix +func (container *Container) RegisterMessageSendScheduleRoutes() { + container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.MessageSendScheduleHandler{})) + container.MessageSendScheduleHandler().RegisterRoutes(container.App(), container.AuthenticatedMiddleware()) +} + // RegisterEventRoutes registers routes for the /events prefix func (container *Container) RegisterEventRoutes() { container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.EventsHandler{})) @@ -1466,6 +1723,7 @@ func (container *Container) RegisterSwaggerRoutes() { Title: docs.SwaggerInfo.Title, CustomScript: ` document.addEventListener("DOMContentLoaded", function(event) { + document.body.style.margin = '0'; var links = document.querySelectorAll("link[rel~='icon']"); links.forEach(function (link) { link.href = 'https://httpsms.com/favicon.ico'; @@ -1476,12 +1734,22 @@ func (container *Container) RegisterSwaggerRoutes() { // HeartbeatRepository registers a new instance of repositories.HeartbeatRepository func (container *Container) HeartbeatRepository() repositories.HeartbeatRepository { - container.logger.Debug("creating GORM repositories.HeartbeatRepository") - return repositories.NewGormHeartbeatRepository( - container.Logger(), - container.Tracer(), - container.DedicatedDB(), - ) + switch os.Getenv("HEARTBEAT_DB_BACKEND") { + case "mongodb": + container.logger.Debug("creating MongoDB repositories.HeartbeatRepository") + return repositories.NewMongoHeartbeatRepository( + container.Logger(), + container.Tracer(), + container.MongoDB(), + ) + default: + container.logger.Debug("creating GORM repositories.HeartbeatRepository") + return repositories.NewGormHeartbeatRepository( + container.Logger(), + container.Tracer(), + container.DedicatedDB(), + ) + } } // UserRepository registers a new instance of repositories.UserRepository @@ -1495,9 +1763,30 @@ func (container *Container) UserRepository() repositories.UserRepository { ) } +// PhoneRistrettoCache creates an in-memory *ristretto.Cache[string, *entities.Phone] +func (container *Container) PhoneRistrettoCache() *ristretto.Cache[string, *entities.Phone] { + if container.phoneRistrettoCache != nil { + return container.phoneRistrettoCache + } + container.logger.Debug(fmt.Sprintf("creating %T", container.phoneRistrettoCache)) + ristrettoCache, err := ristretto.NewCache[string, *entities.Phone](&ristretto.Config[string, *entities.Phone]{ + MaxCost: 5000, + NumCounters: 5000 * 10, + BufferItems: 64, + }) + if err != nil { + container.logger.Fatal(stacktrace.Propagate(err, "cannot create phone ristretto cache")) + } + container.phoneRistrettoCache = ristrettoCache + return container.phoneRistrettoCache +} + // UserRistrettoCache creates an in-memory *ristretto.Cache[string, entities.AuthContext] -func (container *Container) UserRistrettoCache() (cache *ristretto.Cache[string, entities.AuthContext]) { - container.logger.Debug(fmt.Sprintf("creating %T", cache)) +func (container *Container) UserRistrettoCache() *ristretto.Cache[string, entities.AuthContext] { + if container.userRistrettoCache != nil { + return container.userRistrettoCache + } + container.logger.Debug(fmt.Sprintf("creating %T", container.userRistrettoCache)) ristrettoCache, err := ristretto.NewCache[string, entities.AuthContext](&ristretto.Config[string, entities.AuthContext]{ MaxCost: 5000, NumCounters: 5000 * 10, @@ -1506,6 +1795,7 @@ func (container *Container) UserRistrettoCache() (cache *ristretto.Cache[string, if err != nil { container.logger.Fatal(stacktrace.Propagate(err, "cannot create user ristretto cache")) } + container.userRistrettoCache = ristrettoCache return ristrettoCache } diff --git a/api/pkg/emails/hermes_mailer.go b/api/pkg/emails/hermes_mailer.go index 0afce49d..7efe0f8a 100644 --- a/api/pkg/emails/hermes_mailer.go +++ b/api/pkg/emails/hermes_mailer.go @@ -5,7 +5,7 @@ import ( "strconv" "time" - "github.com/matcornic/hermes" + "github.com/go-hermes/hermes/v2" ) // HermesGeneratorConfig contains details for the generator diff --git a/api/pkg/emails/hermes_notification_email_factory.go b/api/pkg/emails/hermes_notification_email_factory.go index 0447997d..7c4b7bc5 100644 --- a/api/pkg/emails/hermes_notification_email_factory.go +++ b/api/pkg/emails/hermes_notification_email_factory.go @@ -7,7 +7,7 @@ import ( "github.com/NdoleStudio/httpsms/pkg/events" "github.com/NdoleStudio/httpsms/pkg/entities" - "github.com/matcornic/hermes" + "github.com/go-hermes/hermes/v2" "github.com/palantir/stacktrace" ) @@ -33,11 +33,11 @@ func (factory *hermesNotificationEmailFactory) DiscordSendFailed(user *entities. fmt.Sprintf("We ran into an error while fowarding an incoming SMS to your discord server at %s", user.UserTimeString(time.Now())), }, Dictionary: []hermes.Entry{ - {"Discord Channel ID", payload.DiscordChannelID}, - {"Event Name", payload.EventType}, - {"Phone Number", factory.formatPhoneNumber(payload.Owner)}, - {"HTTP Response Code", factory.formatHTTPResponseCode(payload.HTTPResponseStatusCode)}, - {"Error Message / HTTP Response", payload.ErrorMessage}, + {Key: "Discord Channel ID", Value: payload.DiscordChannelID}, + {Key: "Event Name", Value: payload.EventType}, + {Key: "Phone Number", Value: factory.formatPhoneNumber(payload.Owner)}, + {Key: "HTTP Response Code", Value: factory.formatHTTPResponseCode(payload.HTTPResponseStatusCode)}, + {Key: "Error Message / HTTP Response", Value: payload.ErrorMessage}, }, Actions: []hermes.Action{ { @@ -83,13 +83,13 @@ func (factory *hermesNotificationEmailFactory) WebhookSendFailed(user *entities. fmt.Sprintf("We ran into an error while fowarding a webhook event from httpSMS to your webserver at %s", user.UserTimeString(time.Now())), }, Dictionary: []hermes.Entry{ - {"Server URL", payload.WebhookURL}, - {"Event Name", payload.EventType}, - {"Event ID", payload.EventID}, - {"Phone Number", factory.formatPhoneNumber(payload.Owner)}, - {"HTTP Response Code", factory.formatHTTPResponseCode(payload.HTTPResponseStatusCode)}, - {"Error Message / HTTP Response", payload.ErrorMessage}, - {"Event Payload", payload.EventPayload}, + {Key: "Server URL", Value: payload.WebhookURL}, + {Key: "Event Name", Value: payload.EventType}, + {Key: "Event ID", Value: payload.EventID}, + {Key: "Phone Number", Value: factory.formatPhoneNumber(payload.Owner)}, + {Key: "HTTP Response Code", Value: factory.formatHTTPResponseCode(payload.HTTPResponseStatusCode)}, + {Key: "Error Message / HTTP Response", Value: payload.ErrorMessage}, + {Key: "Event Payload", Value: payload.EventPayload}, }, Actions: []hermes.Action{ { @@ -135,11 +135,11 @@ func (factory *hermesNotificationEmailFactory) MessageExpired(user *entities.Use fmt.Sprintf("The SMS message which you sent to %s has expired at %s and you will need to resend this message.", factory.formatPhoneNumber(payload.Contact), user.UserTimeString(time.Now())), }, Dictionary: []hermes.Entry{ - {"ID", payload.MessageID.String()}, - {"From", factory.formatPhoneNumber(payload.Owner)}, - {"To", factory.formatPhoneNumber(payload.Contact)}, - {"Message", payload.Content}, - {"Encrypted", factory.formatBool(payload.Encrypted)}, + {Key: "ID", Value: payload.MessageID.String()}, + {Key: "From", Value: factory.formatPhoneNumber(payload.Owner)}, + {Key: "To", Value: factory.formatPhoneNumber(payload.Contact)}, + {Key: "Message", Value: payload.Content}, + {Key: "Encrypted", Value: factory.formatBool(payload.Encrypted)}, }, Actions: []hermes.Action{ { @@ -185,12 +185,12 @@ func (factory *hermesNotificationEmailFactory) MessageFailed(user *entities.User fmt.Sprintf("The SMS message which you sent to %s has failed at %s and you will need to resend this message.", factory.formatPhoneNumber(payload.Contact), user.UserTimeString(time.Now())), }, Dictionary: []hermes.Entry{ - {"ID", payload.ID.String()}, - {"From", factory.formatPhoneNumber(payload.Owner)}, - {"To", factory.formatPhoneNumber(payload.Contact)}, - {"Message", payload.Content}, - {"Encrypted", factory.formatBool(payload.Encrypted)}, - {"Failure Reason", payload.ErrorMessage}, + {Key: "ID", Value: payload.ID.String()}, + {Key: "From", Value: factory.formatPhoneNumber(payload.Owner)}, + {Key: "To", Value: factory.formatPhoneNumber(payload.Contact)}, + {Key: "Message", Value: payload.Content}, + {Key: "Encrypted", Value: factory.formatBool(payload.Encrypted)}, + {Key: "Failure Reason", Value: payload.ErrorMessage}, }, Actions: []hermes.Action{ { diff --git a/api/pkg/emails/hermes_theme.go b/api/pkg/emails/hermes_theme.go index 56b49759..9d8cc471 100644 --- a/api/pkg/emails/hermes_theme.go +++ b/api/pkg/emails/hermes_theme.go @@ -1,10 +1,14 @@ package emails -import "github.com/matcornic/hermes" +import "github.com/go-hermes/hermes/v2" // hermesTheme is the theme by default type hermesTheme struct{} +func (dt *hermesTheme) Styles() hermes.StylesDefinition { + return hermes.Default{}.Styles() +} + func newHermesTheme() hermes.Theme { return &hermesTheme{} } diff --git a/api/pkg/emails/hermes_user_email_factory.go b/api/pkg/emails/hermes_user_email_factory.go index 3d50f6cc..9ec5754a 100644 --- a/api/pkg/emails/hermes_user_email_factory.go +++ b/api/pkg/emails/hermes_user_email_factory.go @@ -5,7 +5,7 @@ import ( "time" "github.com/NdoleStudio/httpsms/pkg/entities" - "github.com/matcornic/hermes" + "github.com/go-hermes/hermes/v2" "github.com/palantir/stacktrace" ) diff --git a/api/pkg/entities/bulk_message.go b/api/pkg/entities/bulk_message.go new file mode 100644 index 00000000..86227ffa --- /dev/null +++ b/api/pkg/entities/bulk_message.go @@ -0,0 +1,16 @@ +package entities + +import "time" + +// BulkMessage represents a summary of a bulk message batch +type BulkMessage struct { + RequestID string `json:"request_id" example:"bulk-csv-a1B2c3D4e5"` + Total int64 `json:"total" example:"150"` + ScheduledCount int64 `json:"scheduled_count" example:"50"` + PendingCount int64 `json:"pending_count" example:"30"` + FailedCount int64 `json:"failed_count" example:"5"` + ExpiredCount int64 `json:"expired_count" example:"3"` + SentCount int64 `json:"sent_count" example:"40"` + DeliveredCount int64 `json:"delivered_count" example:"25"` + CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"` +} diff --git a/api/pkg/entities/event_listener_log.go b/api/pkg/entities/event_listener_log.go deleted file mode 100644 index 50f0662c..00000000 --- a/api/pkg/entities/event_listener_log.go +++ /dev/null @@ -1,18 +0,0 @@ -package entities - -import ( - "time" - - "github.com/google/uuid" -) - -// EventListenerLog stores the log of all the events handled -type EventListenerLog struct { - ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;"` - EventID string `json:"event_id" gorm:"index:idx_event_listener_log_event_id_handler"` - EventType string `json:"event_type"` - Handler string `json:"handler" gorm:"index:idx_event_listener_log_event_id_handler"` - Duration time.Duration `json:"duration"` - HandledAt time.Time `json:"handled_at"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/api/pkg/entities/heartbeat.go b/api/pkg/entities/heartbeat.go index 629efd29..abc070e9 100644 --- a/api/pkg/entities/heartbeat.go +++ b/api/pkg/entities/heartbeat.go @@ -8,10 +8,10 @@ import ( // Heartbeat represents is a pulse from an active phone type Heartbeat struct { - ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` - Owner string `json:"owner" gorm:"index:idx_heartbeats_owner_timestamp" example:"+18005550199"` - Version string `json:"version" example:"344c10f"` - Charging bool `json:"charging" example:"true"` - UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` - Timestamp time.Time `json:"timestamp" gorm:"index:idx_heartbeats_owner_timestamp" example:"2022-06-05T14:26:01.520828+03:00"` + ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" bson:"_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` + Owner string `json:"owner" gorm:"index:idx_heartbeats_owner_timestamp" bson:"owner" example:"+18005550199"` + Version string `json:"version" bson:"version" example:"344c10f"` + Charging bool `json:"charging" bson:"charging" example:"true"` + UserID UserID `json:"user_id" bson:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` + Timestamp time.Time `json:"timestamp" gorm:"index:idx_heartbeats_owner_timestamp" bson:"timestamp" example:"2022-06-05T14:26:01.520828+03:00"` } diff --git a/api/pkg/entities/heartbeat_monitor.go b/api/pkg/entities/heartbeat_monitor.go index 6b41a31a..7151f195 100644 --- a/api/pkg/entities/heartbeat_monitor.go +++ b/api/pkg/entities/heartbeat_monitor.go @@ -8,14 +8,14 @@ import ( // HeartbeatMonitor is used to monitor heartbeats of a phone type HeartbeatMonitor struct { - ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` - PhoneID uuid.UUID `json:"phone_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` - UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` - QueueID string `json:"queue_id" example:"0360259236613675274"` - Owner string `json:"owner" example:"+18005550199"` - PhoneOnline bool `json:"phone_online" example:"true" default:"true"` - CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"` - UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"` + ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" bson:"_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` + PhoneID uuid.UUID `json:"phone_id" bson:"phone_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` + UserID UserID `json:"user_id" bson:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` + QueueID string `json:"queue_id" bson:"queue_id" example:"0360259236613675274"` + Owner string `json:"owner" bson:"owner" example:"+18005550199"` + PhoneOnline bool `json:"phone_online" bson:"phone_online" example:"true" default:"true"` + CreatedAt time.Time `json:"created_at" bson:"created_at" example:"2022-06-05T14:26:02.302718+03:00"` + UpdatedAt time.Time `json:"updated_at" bson:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"` } // RequiresCheck returns true if the heartbeat monitor requires a check diff --git a/api/pkg/entities/message.go b/api/pkg/entities/message.go index fcec05a4..52a9a221 100644 --- a/api/pkg/entities/message.go +++ b/api/pkg/entities/message.go @@ -4,6 +4,7 @@ import ( "time" "github.com/google/uuid" + "github.com/lib/pq" ) // MessageType is the type of message if it is incoming or outgoing @@ -83,15 +84,16 @@ func (s SIM) String() string { // Message represents a message sent between 2 phone numbers type Message struct { - ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` - RequestID *string `json:"request_id" example:"153554b5-ae44-44a0-8f4f-7bbac5657ad4"` - Owner string `json:"owner" example:"+18005550199"` - UserID UserID `json:"user_id" gorm:"index:idx_messages__user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` - Contact string `json:"contact" example:"+18005550100"` - Content string `json:"content" example:"This is a sample text message"` - Encrypted bool `json:"encrypted" example:"false" gorm:"default:false"` - Type MessageType `json:"type" example:"mobile-terminated"` - Status MessageStatus `json:"status" example:"pending"` + ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` + RequestID *string `json:"request_id" example:"153554b5-ae44-44a0-8f4f-7bbac5657ad4" validate:"optional"` + Owner string `json:"owner" example:"+18005550199"` + UserID UserID `json:"user_id" gorm:"index:idx_messages__user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` + Contact string `json:"contact" example:"+18005550100"` + Content string `json:"content" example:"This is a sample text message"` + Attachments pq.StringArray `json:"attachments" gorm:"type:text[]" swaggertype:"array,string" example:"https://example.com/image.jpg,https://example.com/video.mp4"` + Encrypted bool `json:"encrypted" example:"false" gorm:"default:false"` + Type MessageType `json:"type" example:"mobile-terminated"` + Status MessageStatus `json:"status" example:"pending"` // SIM is the SIM card to use to send the message // * SMS1: use the SIM card in slot 1 // * SMS2: use the SIM card in slot 2 @@ -99,24 +101,24 @@ type Message struct { SIM SIM `json:"sim" example:"DEFAULT"` // SendDuration is the number of nanoseconds from when the request was received until when the mobile phone send the message - SendDuration *int64 `json:"send_time" example:"133414"` + SendDuration *int64 `json:"send_time" example:"133414" validate:"optional"` RequestReceivedAt time.Time `json:"request_received_at" example:"2022-06-05T14:26:01.520828+03:00"` CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"` UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"` OrderTimestamp time.Time `json:"order_timestamp" example:"2022-06-05T14:26:09.527976+03:00"` - LastAttemptedAt *time.Time `json:"last_attempted_at" example:"2022-06-05T14:26:09.527976+03:00"` - NotificationScheduledAt *time.Time `json:"scheduled_at" example:"2022-06-05T14:26:09.527976+03:00"` - SentAt *time.Time `json:"sent_at" example:"2022-06-05T14:26:09.527976+03:00"` - ScheduledSendTime *time.Time `json:"scheduled_send_time" example:"2022-06-05T14:26:09.527976+03:00"` - DeliveredAt *time.Time `json:"delivered_at" example:"2022-06-05T14:26:09.527976+03:00"` - ExpiredAt *time.Time `json:"expired_at" example:"2022-06-05T14:26:09.527976+03:00"` - FailedAt *time.Time `json:"failed_at" example:"2022-06-05T14:26:09.527976+03:00"` - CanBePolled bool `json:"can_be_polled" example:"false"` + LastAttemptedAt *time.Time `json:"last_attempted_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + NotificationScheduledAt *time.Time `json:"scheduled_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + SentAt *time.Time `json:"sent_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + ScheduledSendTime *time.Time `json:"scheduled_send_time" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + DeliveredAt *time.Time `json:"delivered_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + ExpiredAt *time.Time `json:"expired_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + FailedAt *time.Time `json:"failed_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + CanBePolled bool `json:"-" example:"false" swaggerignore:"true"` SendAttemptCount uint `json:"send_attempt_count" example:"0"` MaxSendAttempts uint `json:"max_send_attempts" example:"1"` - ReceivedAt *time.Time `json:"received_at" example:"2022-06-05T14:26:09.527976+03:00"` - FailureReason *string `json:"failure_reason" example:"UNKNOWN"` + ReceivedAt *time.Time `json:"received_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + FailureReason *string `json:"failure_reason" example:"UNKNOWN" validate:"optional"` } // IsSending determines if a message is being sent diff --git a/api/pkg/entities/message_send_schedule.go b/api/pkg/entities/message_send_schedule.go new file mode 100644 index 00000000..7be7dc2b --- /dev/null +++ b/api/pkg/entities/message_send_schedule.go @@ -0,0 +1,90 @@ +package entities + +import ( + "time" + + "github.com/google/uuid" +) + +// EntityNameMessageSendSchedule is the entitlement entity name for message send schedules. +const EntityNameMessageSendSchedule = "MessageSendSchedule" + +// MessageSendScheduleWindow represents a single availability window for a day of the week. +type MessageSendScheduleWindow struct { + DayOfWeek int `json:"day_of_week" example:"1"` + StartMinute int `json:"start_minute" example:"540"` + EndMinute int `json:"end_minute" example:"1020"` +} + +// MessageSendSchedule controls when a phone is allowed to send outgoing SMS messages. +type MessageSendSchedule struct { + ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` + UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` + Name string `json:"name" example:"Business Hours"` + Timezone string `json:"timezone" example:"Europe/Tallinn"` + Windows []MessageSendScheduleWindow `json:"windows" gorm:"type:jsonb;serializer:json"` + CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"` + UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"` +} + +// ResolveScheduledAt returns the next allowed send time based on the schedule. +// If the schedule is inactive, has no windows, or has an invalid timezone, +// the current time is returned in UTC. An active schedule with no windows +// is treated as inactive (messages are sent immediately). +func (schedule *MessageSendSchedule) ResolveScheduledAt(current time.Time) time.Time { + if schedule == nil || len(schedule.Windows) == 0 { + return current.UTC() + } + + location, err := time.LoadLocation(schedule.Timezone) + if err != nil { + return current.UTC() + } + + base := current.In(location) + var best time.Time + + for dayOffset := 0; dayOffset <= 7; dayOffset++ { + day := base.AddDate(0, 0, dayOffset) + weekday := int(day.Weekday()) + + for _, window := range schedule.Windows { + if window.DayOfWeek != weekday { + continue + } + + start := time.Date(day.Year(), day.Month(), day.Day(), 0, 0, 0, 0, location). + Add(time.Duration(window.StartMinute) * time.Minute) + + end := time.Date(day.Year(), day.Month(), day.Day(), 0, 0, 0, 0, location). + Add(time.Duration(window.EndMinute) * time.Minute) + + var candidate time.Time + + switch { + case dayOffset == 0 && base.Before(start): + candidate = start + case dayOffset == 0 && (base.Equal(start) || (base.After(start) && base.Before(end))): + candidate = base + case dayOffset > 0: + candidate = start + default: + continue + } + + if best.IsZero() || candidate.Before(best) { + best = candidate + } + } + + if !best.IsZero() { + break + } + } + + if best.IsZero() { + return current.UTC() + } + + return best.UTC() +} diff --git a/api/pkg/entities/message_send_schedule_test.go b/api/pkg/entities/message_send_schedule_test.go new file mode 100644 index 00000000..2554fda3 --- /dev/null +++ b/api/pkg/entities/message_send_schedule_test.go @@ -0,0 +1,59 @@ +package entities + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestResolveScheduledAt_NilSchedule_ReturnsCurrentUTC(t *testing.T) { + now := time.Now() + var schedule *MessageSendSchedule + result := schedule.ResolveScheduledAt(now) + assert.Equal(t, now.UTC(), result) +} + +func TestResolveScheduledAt_InactiveSchedule_ReturnsCurrentUTC(t *testing.T) { + now := time.Now() + schedule := &MessageSendSchedule{} + result := schedule.ResolveScheduledAt(now) + assert.Equal(t, now.UTC(), result) +} + +func TestResolveScheduledAt_NoWindows_ReturnsCurrentUTC(t *testing.T) { + now := time.Now() + schedule := &MessageSendSchedule{ + Timezone: "UTC", + Windows: []MessageSendScheduleWindow{}, + } + result := schedule.ResolveScheduledAt(now) + assert.Equal(t, now.UTC(), result) +} + +func TestResolveScheduledAt_WithinWindow_ReturnsCurrentUTC(t *testing.T) { + // Wednesday at 10:00 UTC, window is Wed 9:00-17:00 (540-1020 minutes) + now := time.Date(2025, 1, 1, 10, 0, 0, 0, time.UTC) // Wednesday + schedule := &MessageSendSchedule{ + Timezone: "UTC", + Windows: []MessageSendScheduleWindow{ + {DayOfWeek: int(now.Weekday()), StartMinute: 540, EndMinute: 1020}, + }, + } + result := schedule.ResolveScheduledAt(now) + assert.Equal(t, now.UTC(), result) +} + +func TestResolveScheduledAt_BeforeWindow_ReturnsWindowStart(t *testing.T) { + // Wednesday at 7:00 UTC, window is Wed 9:00-17:00 + now := time.Date(2025, 1, 1, 7, 0, 0, 0, time.UTC) // Wednesday + schedule := &MessageSendSchedule{ + Timezone: "UTC", + Windows: []MessageSendScheduleWindow{ + {DayOfWeek: int(now.Weekday()), StartMinute: 540, EndMinute: 1020}, + }, + } + result := schedule.ResolveScheduledAt(now) + expected := time.Date(2025, 1, 1, 9, 0, 0, 0, time.UTC) + assert.Equal(t, expected, result) +} diff --git a/api/pkg/entities/phone.go b/api/pkg/entities/phone.go index 7e6d9b26..97df6631 100644 --- a/api/pkg/entities/phone.go +++ b/api/pkg/entities/phone.go @@ -8,19 +8,21 @@ import ( // Phone represents an android phone which has installed the http sms app type Phone struct { - ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` - UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` - FcmToken *string `json:"fcm_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....."` - PhoneNumber string `json:"phone_number" example:"+18005550199"` - MessagesPerMinute uint `json:"messages_per_minute" example:"1"` - SIM SIM `json:"sim" gorm:"default:SIM1"` + ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` + UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` + FcmToken *string `json:"fcm_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." validate:"optional"` + PhoneNumber string `json:"phone_number" example:"+18005550199"` + MessagesPerMinute uint `json:"messages_per_minute" example:"1"` + SIM SIM `json:"sim" gorm:"default:SIM1"` + MessageSendScheduleID *uuid.UUID `json:"message_send_schedule_id" gorm:"type:uuid" example:"32343a19-da5e-4b1b-a767-3298a73703cb" validate:"optional"` + // MaxSendAttempts determines how many times to retry sending an SMS message MaxSendAttempts uint `json:"max_send_attempts" example:"2"` // MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired. MessageExpirationSeconds uint `json:"message_expiration_seconds"` - MissedCallAutoReply *string `json:"missed_call_auto_reply" example:"This phone cannot receive calls. Please send an SMS instead."` + MissedCallAutoReply *string `json:"missed_call_auto_reply" example:"This phone cannot receive calls. Please send an SMS instead." validate:"optional"` CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"` UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"` diff --git a/api/pkg/entities/phone_api_key.go b/api/pkg/entities/phone_api_key.go index 5a32c234..d8dda328 100644 --- a/api/pkg/entities/phone_api_key.go +++ b/api/pkg/entities/phone_api_key.go @@ -7,6 +7,9 @@ import ( "github.com/lib/pq" ) +// EntityNamePhoneAPIKey is the entitlement entity name for phone API keys. +const EntityNamePhoneAPIKey = "PhoneAPIKey" + // PhoneAPIKey represents the API key for a phone type PhoneAPIKey struct { ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` diff --git a/api/pkg/entities/user.go b/api/pkg/entities/user.go index 0d4cbbe7..f26a8135 100644 --- a/api/pkg/entities/user.go +++ b/api/pkg/entities/user.go @@ -76,12 +76,12 @@ type User struct { Email string `json:"email" example:"name@email.com"` APIKey string `json:"api_key" gorm:"uniqueIndex:idx_users_api_key;NOT NULL" example:"x-api-key"` Timezone string `json:"timezone" example:"Europe/Helsinki" gorm:"default:Africa/Accra"` - ActivePhoneID *uuid.UUID `json:"active_phone_id" gorm:"type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"` + ActivePhoneID *uuid.UUID `json:"active_phone_id" gorm:"type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb" validate:"optional"` SubscriptionName SubscriptionName `json:"subscription_name" example:"free"` SubscriptionID *string `json:"subscription_id" example:"8f9c71b8-b84e-4417-8408-a62274f65a08"` - SubscriptionStatus *string `json:"subscription_status" example:"on_trial"` - SubscriptionRenewsAt *time.Time `json:"subscription_renews_at" example:"2022-06-05T14:26:02.302718+03:00"` - SubscriptionEndsAt *time.Time `json:"subscription_ends_at" example:"2022-06-05T14:26:02.302718+03:00"` + SubscriptionStatus *string `json:"subscription_status" example:"on_trial" validate:"optional"` + SubscriptionRenewsAt *time.Time `json:"subscription_renews_at" example:"2022-06-05T14:26:02.302718+03:00" validate:"optional"` + SubscriptionEndsAt *time.Time `json:"subscription_ends_at" example:"2022-06-05T14:26:02.302718+03:00" validate:"optional"` NotificationMessageStatusEnabled bool `json:"notification_message_status_enabled" gorm:"default:true" example:"true"` NotificationWebhookEnabled bool `json:"notification_webhook_enabled" gorm:"default:true" example:"true"` NotificationHeartbeatEnabled bool `json:"notification_heartbeat_enabled" gorm:"default:true" example:"true"` diff --git a/api/pkg/events/message_api_sent_event.go b/api/pkg/events/message_api_sent_event.go index 7abea843..e86c911e 100644 --- a/api/pkg/events/message_api_sent_event.go +++ b/api/pkg/events/message_api_sent_event.go @@ -20,8 +20,10 @@ type MessageAPISentPayload struct { MaxSendAttempts uint `json:"max_send_attempts"` Contact string `json:"contact"` ScheduledSendTime *time.Time `json:"scheduled_send_time"` + ExactSendTime bool `json:"exact_send_time"` RequestReceivedAt time.Time `json:"request_received_at"` Content string `json:"content"` + Attachments []string `json:"attachments"` Encrypted bool `json:"encrypted"` SIM entities.SIM `json:"sim"` } diff --git a/api/pkg/events/message_phone_received_event.go b/api/pkg/events/message_phone_received_event.go index abe3a014..04dd6c2e 100644 --- a/api/pkg/events/message_phone_received_event.go +++ b/api/pkg/events/message_phone_received_event.go @@ -13,12 +13,13 @@ const EventTypeMessagePhoneReceived = "message.phone.received" // MessagePhoneReceivedPayload is the payload of the EventTypeMessagePhoneReceived event type MessagePhoneReceivedPayload struct { - MessageID uuid.UUID `json:"message_id"` - UserID entities.UserID `json:"user_id"` - Owner string `json:"owner"` - Encrypted bool `json:"encrypted"` - Contact string `json:"contact"` - Timestamp time.Time `json:"timestamp"` - Content string `json:"content"` - SIM entities.SIM `json:"sim"` + MessageID uuid.UUID `json:"message_id"` + UserID entities.UserID `json:"user_id"` + Owner string `json:"owner"` + Encrypted bool `json:"encrypted"` + Contact string `json:"contact"` + Timestamp time.Time `json:"timestamp"` + Content string `json:"content"` + SIM entities.SIM `json:"sim"` + Attachments []string `json:"attachments"` } diff --git a/api/pkg/events/message_send_schedule_deleted_event.go b/api/pkg/events/message_send_schedule_deleted_event.go new file mode 100644 index 00000000..3a32361c --- /dev/null +++ b/api/pkg/events/message_send_schedule_deleted_event.go @@ -0,0 +1,18 @@ +package events + +import ( + "time" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/google/uuid" +) + +// EventTypeMessageSendScheduleDeleted is emitted when a message send schedule is deleted +const EventTypeMessageSendScheduleDeleted = "message-send-schedule.deleted" + +// MessageSendScheduleDeletedPayload is the payload of the EventTypeMessageSendScheduleDeleted event +type MessageSendScheduleDeletedPayload struct { + ScheduleID uuid.UUID `json:"schedule_id"` + UserID entities.UserID `json:"user_id"` + Timestamp time.Time `json:"timestamp"` +} diff --git a/api/pkg/events/user_account_created_event.go b/api/pkg/events/user_account_created_event.go new file mode 100644 index 00000000..2b37ef8a --- /dev/null +++ b/api/pkg/events/user_account_created_event.go @@ -0,0 +1,16 @@ +package events + +import ( + "time" + + "github.com/NdoleStudio/httpsms/pkg/entities" +) + +// UserAccountCreated is raised when a user's account is created. +const UserAccountCreated = "user.account.created" + +// UserAccountCreatedPayload stores the data for the UserAccountCreated event +type UserAccountCreatedPayload struct { + UserID entities.UserID `json:"user_id"` + Timestamp time.Time `json:"timestamp"` +} diff --git a/api/pkg/events/user_account_deleted_event.go b/api/pkg/events/user_account_deleted_event.go index 581b44ef..bf8f68db 100644 --- a/api/pkg/events/user_account_deleted_event.go +++ b/api/pkg/events/user_account_deleted_event.go @@ -9,8 +9,9 @@ import ( // UserAccountDeleted is raised when a user's account is deleted. const UserAccountDeleted = "user.account.deleted" -// UserAccountDeletedPayload stores the data for the UserAccountDeletedPayload event +// UserAccountDeletedPayload stores the data for the UserAccountDeleted event type UserAccountDeletedPayload struct { UserID entities.UserID `json:"user_id"` + UserEmail string `json:"user_email"` Timestamp time.Time `json:"timestamp"` } diff --git a/api/pkg/handlers/attachment_handler.go b/api/pkg/handlers/attachment_handler.go new file mode 100644 index 00000000..46a4397b --- /dev/null +++ b/api/pkg/handlers/attachment_handler.go @@ -0,0 +1,85 @@ +package handlers + +import ( + "fmt" + "path/filepath" + + "github.com/NdoleStudio/httpsms/pkg/repositories" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/gofiber/fiber/v2" + "github.com/palantir/stacktrace" +) + +// AttachmentHandler handles attachment download requests +type AttachmentHandler struct { + handler + logger telemetry.Logger + tracer telemetry.Tracer + storage repositories.AttachmentRepository +} + +// NewAttachmentHandler creates a new AttachmentHandler +func NewAttachmentHandler( + logger telemetry.Logger, + tracer telemetry.Tracer, + storage repositories.AttachmentRepository, +) (h *AttachmentHandler) { + return &AttachmentHandler{ + logger: logger.WithService(fmt.Sprintf("%T", h)), + tracer: tracer, + storage: storage, + } +} + +// RegisterRoutes registers the routes for the AttachmentHandler (no auth middleware — public endpoint) +func (h *AttachmentHandler) RegisterRoutes(router fiber.Router) { + router.Get("/v1/attachments/:userID/:messageID/:attachmentIndex/:filename", h.GetAttachment) +} + +// GetAttachment Downloads an attachment +// @Summary Download a message attachment +// @Description Download an MMS attachment by its path components +// @Tags Attachments +// @Produce application/octet-stream +// @Param userID path string true "User ID" +// @Param messageID path string true "Message ID" +// @Param attachmentIndex path string true "Attachment index" +// @Param filename path string true "Filename with extension" +// @Success 200 {file} binary +// @Failure 404 {object} responses.NotFound +// @Failure 500 {object} responses.InternalServerError +// @Router /v1/attachments/{userID}/{messageID}/{attachmentIndex}/{filename} [get] +func (h *AttachmentHandler) GetAttachment(c *fiber.Ctx) error { + ctx, span := h.tracer.StartFromFiberCtx(c) + defer span.End() + + ctxLogger := h.tracer.CtxLogger(h.logger, span) + + userID := c.Params("userID") + messageID := c.Params("messageID") + attachmentIndex := c.Params("attachmentIndex") + filename := c.Params("filename") + + path := fmt.Sprintf("attachments/%s/%s/%s/%s", userID, messageID, attachmentIndex, filename) + + ctxLogger.Info(fmt.Sprintf("downloading attachment from path [%s]", path)) + + data, err := h.storage.Download(ctx, path) + if err != nil { + msg := fmt.Sprintf("cannot download attachment from path [%s]", path) + ctxLogger.Warn(stacktrace.Propagate(err, msg)) + if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { + return h.responseNotFound(c, "attachment not found") + } + return h.responseInternalServerError(c) + } + + ext := filepath.Ext(filename) + contentType := repositories.ContentTypeFromExtension(ext) + + c.Set("Content-Type", contentType) + c.Set("Content-Disposition", "attachment") + c.Set("X-Content-Type-Options", "nosniff") + + return c.Send(data) +} diff --git a/api/pkg/handlers/billing_handler.go b/api/pkg/handlers/billing_handler.go index bcdb5248..3d65ee9a 100644 --- a/api/pkg/handlers/billing_handler.go +++ b/api/pkg/handlers/billing_handler.go @@ -65,7 +65,7 @@ func (h *BillingHandler) UsageHistory(c *fiber.Ctx) error { var request requests.BillingUsageHistory if err := c.QueryParser(&request); err != nil { - msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request) + msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.Body(), request) ctxLogger.Warn(stacktrace.Propagate(err, msg)) return h.responseBadRequest(c, err) } diff --git a/api/pkg/handlers/bulk_message_handler.go b/api/pkg/handlers/bulk_message_handler.go index d29a907d..27d6286d 100644 --- a/api/pkg/handlers/bulk_message_handler.go +++ b/api/pkg/handlers/bulk_message_handler.go @@ -1,17 +1,18 @@ package handlers import ( + "crypto/rand" "fmt" "sync" + "sync/atomic" "github.com/NdoleStudio/httpsms/pkg/requests" - "github.com/google/uuid" - "github.com/NdoleStudio/httpsms/pkg/services" "github.com/NdoleStudio/httpsms/pkg/telemetry" "github.com/NdoleStudio/httpsms/pkg/validators" "github.com/davecgh/go-spew/spew" "github.com/gofiber/fiber/v2" + gonanoid "github.com/matoous/go-nanoid/v2" "github.com/palantir/stacktrace" ) @@ -44,16 +45,43 @@ func NewBulkMessageHandler( // RegisterRoutes registers the routes for the MessageHandler func (h *BulkMessageHandler) RegisterRoutes(router fiber.Router, middlewares ...fiber.Handler) { + router.Get("/v1/bulk-messages", h.computeRoute(middlewares, h.Index)...) router.Post("/v1/bulk-messages", h.computeRoute(middlewares, h.Store)...) } -// Store sends bulk SMS messages from a CSV file. -// @Summary Store bulk SMS file -// @Description Sends bulk SMS messages to multiple users from a CSV file. +// Index fetches the bulk message order history. +// @Summary List bulk message orders +// @Description Fetches the last 10 bulk message order summaries for the authenticated user showing counts per status. // @Security ApiKeyAuth // @Tags BulkSMS // @Accept json // @Produce json +// @Success 200 {object} responses.BulkMessagesResponse +// @Failure 401 {object} responses.Unauthorized +// @Failure 500 {object} responses.InternalServerError +// @Router /bulk-messages [get] +func (h *BulkMessageHandler) Index(c *fiber.Ctx) error { + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) + defer span.End() + + orders, err := h.messageService.GetBulkMessages(ctx, h.userIDFomContext(c)) + if err != nil { + msg := fmt.Sprintf("cannot fetch bulk messages for user [%s]", h.userIDFomContext(c)) + ctxLogger.Error(stacktrace.Propagate(err, msg)) + return h.responseInternalServerError(c) + } + + return h.responseOK(c, fmt.Sprintf("fetched %d bulk %s", len(orders), h.pluralize("message", len(orders))), orders) +} + +// Store sends bulk SMS messages from a CSV or Excel file. +// @Summary Store bulk SMS file +// @Description Sends bulk SMS messages to multiple users based on our [CSV template](https://httpsms.com/templates/httpsms-bulk.csv) or our [Excel template](https://httpsms.com/templates/httpsms-bulk.xlsx). +// @Security ApiKeyAuth +// @Tags BulkSMS +// @Accept multipart/form-data +// @Produce json +// @Param document formData file true "The Excel or CSV file containing the messages to be sent." // @Success 202 {object} responses.NoContent // @Failure 400 {object} responses.BadRequest // @Failure 401 {object} responses.Unauthorized @@ -71,7 +99,7 @@ func (h *BulkMessageHandler) Store(c *fiber.Ctx) error { return h.responseBadRequest(c, err) } - messages, validationErrors := h.validator.ValidateStore(ctx, h.userIDFomContext(c), file) + messages, fileType, userLocation, validationErrors := h.validator.ValidateStore(ctx, h.userIDFomContext(c), file) if len(validationErrors) != 0 { msg := fmt.Sprintf("validation errors [%s], while sending bulk sms from CSV file [%s] for [%s]", spew.Sdump(validationErrors), file.Filename, h.userIDFomContext(c)) ctxLogger.Warn(stacktrace.NewError(msg)) @@ -83,24 +111,55 @@ func (h *BulkMessageHandler) Store(c *fiber.Ctx) error { return h.responsePaymentRequired(c, *msg) } - requestID := uuid.New() + requestID := h.generateRequestID(fileType, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") wg := sync.WaitGroup{} + count := atomic.Int64{} + + // Compute per-phone index for rate-based dispatch delay + phoneIndexCounter := make(map[string]int) + for _, message := range messages { wg.Add(1) - go func(message *requests.BulkMessage) { + var perPhoneIndex int + if message.GetSendTime(userLocation) == nil { + perPhoneIndex = phoneIndexCounter[message.FromPhoneNumber] + phoneIndexCounter[message.FromPhoneNumber]++ + } + + go func(message *requests.BulkMessage, index int) { + count.Add(1) _, err = h.messageService.SendMessage( ctx, - message.ToMessageSendParams(h.userIDFomContext(c), requestID, c.OriginalURL()), + message.ToMessageSendParams(h.userIDFomContext(c), requestID, c.OriginalURL(), index, userLocation), ) - if err != nil { - msg := fmt.Sprintf("cannot send message with paylod [%s]", c.Body()) + count.Add(-1) + msg := fmt.Sprintf("cannot send message with payload [%s] at index [%d]", spew.Sdump(message), index) ctxLogger.Error(stacktrace.Propagate(err, msg)) } wg.Done() - }(message) + }(message, perPhoneIndex) } wg.Wait() - return h.responseAccepted(c, fmt.Sprintf("Added %d messages to the queue", len(messages))) + return h.responseAccepted(c, fmt.Sprintf("Added %d out of %d messages to the queue", count.Load(), len(messages))) +} + +func (h *BulkMessageHandler) generateRequestID(fileType string, alphabet string) string { + id, err := gonanoid.Generate(alphabet, 10) + if err != nil { + id = h.randomAlphaNum(10, alphabet) + } + return fmt.Sprintf("bulk-%s-%s", fileType, id) +} + +func (h *BulkMessageHandler) randomAlphaNum(length int, alphabet string) string { + b := make([]byte, length) + if _, err := rand.Read(b); err != nil { + return alphabet[:length] + } + for i := range b { + b[i] = alphabet[int(b[i])%len(alphabet)] + } + return string(b) } diff --git a/api/pkg/handlers/lemonsqueezy_handler.go b/api/pkg/handlers/lemonsqueezy_handler.go index a6bfbb85..ca9ea0eb 100644 --- a/api/pkg/handlers/lemonsqueezy_handler.go +++ b/api/pkg/handlers/lemonsqueezy_handler.go @@ -44,18 +44,7 @@ func (h *LemonsqueezyHandler) RegisterRoutes(app *fiber.App, middlewares ...fibe router.Post("/event", h.computeRoute(middlewares, h.Event)...) } -// Event consumes a lemonsqueezy event -// @Summary Consume a lemonsqueezy event -// @Description Publish a lemonsqueezy event to the registered listeners -// @Tags Lemonsqueezy -// @Accept json -// @Produce json -// @Success 204 {object} responses.NoContent -// @Failure 400 {object} responses.BadRequest -// @Failure 401 {object} responses.Unauthorized -// @Failure 422 {object} responses.UnprocessableEntity -// @Failure 500 {object} responses.InternalServerError -// @Router /lemonsqueezy/event [post] +// Event handles lemonsqueezy events func (h *LemonsqueezyHandler) Event(c *fiber.Ctx) error { ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) defer span.End() diff --git a/api/pkg/handlers/message_handler.go b/api/pkg/handlers/message_handler.go index 6280f118..9504d518 100644 --- a/api/pkg/handlers/message_handler.go +++ b/api/pkg/handlers/message_handler.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" "sync" + "sync/atomic" "time" "github.com/NdoleStudio/httpsms/pkg/entities" @@ -53,6 +54,7 @@ func (h *MessageHandler) RegisterRoutes(router fiber.Router, middlewares ...fibe router.Post("/v1/messages/bulk-send", h.computeRoute(middlewares, h.BulkSend)...) router.Get("/v1/messages", h.computeRoute(middlewares, h.Index)...) router.Get("/v1/messages/search", h.computeRoute(middlewares, h.Search)...) + router.Get("/v1/messages/:messageID", h.computeRoute(middlewares, h.Get)...) router.Delete("/v1/messages/:messageID", h.computeRoute(middlewares, h.Delete)...) } @@ -65,13 +67,13 @@ func (h *MessageHandler) RegisterPhoneAPIKeyRoutes(router fiber.Router, middlewa } // PostSend a new entities.Message -// @Summary Send a new SMS message -// @Description Add a new SMS message to be sent by the android phone +// @Summary Send an SMS message +// @Description Add a new SMS message to be sent by your Android phone // @Security ApiKeyAuth // @Tags Messages // @Accept json // @Produce json -// @Param payload body requests.MessageSend true "PostSend message request payload" +// @Param payload body requests.MessageSend true "Send message request payload" // @Success 200 {object} responses.MessageResponse // @Failure 400 {object} responses.BadRequest // @Failure 401 {object} responses.Unauthorized @@ -153,18 +155,16 @@ func (h *MessageHandler) BulkSend(c *fiber.Ctx) error { wg := sync.WaitGroup{} params := request.ToMessageSendParams(h.userIDFomContext(c), c.OriginalURL()) responses := make([]*entities.Message, len(params)) + count := atomic.Int64{} for index, message := range params { wg.Add(1) go func(message services.MessageSendParams, index int) { - if message.SendAt == nil { - sentAt := time.Now().UTC().Add(time.Duration(index) * time.Second) - message.SendAt = &sentAt - } - + count.Add(1) response, err := h.service.SendMessage(ctx, message) if err != nil { - msg := fmt.Sprintf("cannot send message with paylod [%s]", c.Body()) + count.Add(-1) + msg := fmt.Sprintf("cannot send message with paylod [%s] at index [%d]", spew.Sdump(message), index) ctxLogger.Error(stacktrace.Propagate(err, msg)) } responses[index] = response @@ -173,7 +173,7 @@ func (h *MessageHandler) BulkSend(c *fiber.Ctx) error { } wg.Wait() - return h.responseOK(c, fmt.Sprintf("[%d] messages processed successfully", len(responses)), responses) + return h.responseOK(c, fmt.Sprintf("%d out of %d messages processed successfully", count.Load(), len(responses)), responses) } // GetOutstanding returns an entities.Message which is still to be sent by the mobile phone @@ -439,6 +439,48 @@ func (h *MessageHandler) Delete(c *fiber.Ctx) error { return h.responseNoContent(c, "message deleted successfully") } +// Get a message +// @Summary Get a message from the database. +// @Description Get a message from the database by the message ID. +// @Security ApiKeyAuth +// @Tags Messages +// @Accept json +// @Produce json +// @Param messageID path string true "ID of the message" default(32343a19-da5e-4b1b-a767-3298a73703ca) +// @Success 204 {object} responses.MessageResponse +// @Failure 400 {object} responses.BadRequest +// @Failure 401 {object} responses.Unauthorized +// @Failure 404 {object} responses.NotFound +// @Failure 422 {object} responses.UnprocessableEntity +// @Failure 500 {object} responses.InternalServerError +// @Router /messages/{messageID} [get] +func (h *MessageHandler) Get(c *fiber.Ctx) error { + ctx, span := h.tracer.StartFromFiberCtx(c) + defer span.End() + + ctxLogger := h.tracer.CtxLogger(h.logger, span) + + messageID := c.Params("messageID") + if errors := h.validator.ValidateUUID(messageID, "messageID"); len(errors) != 0 { + msg := fmt.Sprintf("validation errors [%s], while deleting a message with ID [%s]", spew.Sdump(errors), messageID) + ctxLogger.Warn(stacktrace.NewError(msg)) + return h.responseUnprocessableEntity(c, errors, "validation errors while storing event") + } + + message, err := h.service.GetMessage(ctx, h.userIDFomContext(c), uuid.MustParse(messageID)) + if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { + return h.responseNotFound(c, fmt.Sprintf("cannot find message with ID [%s]", messageID)) + } + + if err != nil { + msg := fmt.Sprintf("cannot find message with id [%s]", messageID) + ctxLogger.Error(h.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))) + return h.responseInternalServerError(c) + } + + return h.responseOK(c, "message fetched successfully", message) +} + // PostCallMissed registers a missed phone call // @Summary Register a missed call event on the mobile phone // @Description This endpoint is called by the httpSMS android app to register a missed call event on the mobile phone. diff --git a/api/pkg/handlers/message_send_schedule_handler.go b/api/pkg/handlers/message_send_schedule_handler.go new file mode 100644 index 00000000..3218dceb --- /dev/null +++ b/api/pkg/handlers/message_send_schedule_handler.go @@ -0,0 +1,225 @@ +package handlers + +import ( + "fmt" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/repositories" + "github.com/NdoleStudio/httpsms/pkg/requests" + "github.com/NdoleStudio/httpsms/pkg/services" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/NdoleStudio/httpsms/pkg/validators" + "github.com/davecgh/go-spew/spew" + "github.com/gofiber/fiber/v2" + "github.com/google/uuid" + "github.com/palantir/stacktrace" +) + +// MessageSendScheduleHandler handles HTTP requests for message send schedules. +type MessageSendScheduleHandler struct { + handler + logger telemetry.Logger + tracer telemetry.Tracer + validator *validators.MessageSendScheduleHandlerValidator + service *services.MessageSendScheduleService + entitlementService *services.EntitlementService +} + +// NewMessageSendScheduleHandler creates a new MessageSendScheduleHandler. +func NewMessageSendScheduleHandler( + logger telemetry.Logger, + tracer telemetry.Tracer, + validator *validators.MessageSendScheduleHandlerValidator, + service *services.MessageSendScheduleService, + entitlementService *services.EntitlementService, +) *MessageSendScheduleHandler { + return &MessageSendScheduleHandler{ + logger: logger.WithService(fmt.Sprintf("%T", &MessageSendScheduleHandler{})), + tracer: tracer, + validator: validator, + service: service, + entitlementService: entitlementService, + } +} + +// RegisterRoutes registers send schedule routes. +func (h *MessageSendScheduleHandler) RegisterRoutes(router fiber.Router, middlewares ...fiber.Handler) { + router.Get("/v1/send-schedules", h.computeRoute(middlewares, h.Index)...) + router.Post("/v1/send-schedules", h.computeRoute(middlewares, h.Store)...) + router.Put("/v1/send-schedules/:scheduleID", h.computeRoute(middlewares, h.Update)...) + router.Delete("/v1/send-schedules/:scheduleID", h.computeRoute(middlewares, h.Delete)...) +} + +// Index lists all send schedules for the authenticated user. +// +// @Summary List send schedules +// @Description List all send schedules owned by the authenticated user. +// @Security ApiKeyAuth +// @Tags SendSchedules +// @Produce json +// @Success 200 {object} responses.MessageSendSchedulesResponse +// @Failure 401 {object} responses.Unauthorized +// @Failure 500 {object} responses.InternalServerError +// @Router /send-schedules [get] +func (h *MessageSendScheduleHandler) Index(c *fiber.Ctx) error { + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) + defer span.End() + + userID := h.userIDFomContext(c) + + schedules, err := h.service.Index(ctx, userID) + if err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot list send schedules for user [%s]", userID))) + return h.responseInternalServerError(c) + } + + return h.responseOK(c, "send schedules fetched successfully", schedules) +} + +// Store creates a new send schedule for the authenticated user. +// +// @Summary Create send schedule +// @Description Create a new send schedule for the authenticated user. +// @Security ApiKeyAuth +// @Tags SendSchedules +// @Accept json +// @Produce json +// @Param payload body requests.MessageSendScheduleStore true "Payload of new send schedule." +// @Success 201 {object} responses.MessageSendScheduleResponse +// @Failure 400 {object} responses.BadRequest +// @Failure 401 {object} responses.Unauthorized +// @Failure 402 {object} responses.PaymentRequired +// @Failure 422 {object} responses.UnprocessableEntity +// @Failure 500 {object} responses.InternalServerError +// @Router /send-schedules [post] +func (h *MessageSendScheduleHandler) Store(c *fiber.Ctx) error { + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) + defer span.End() + + userID := h.userIDFomContext(c) + + result, err := h.entitlementService.Check(ctx, userID, entities.EntityNameMessageSendSchedule, func() (int, error) { + return h.service.CountByUser(ctx, userID) + }) + if err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot check entitlement for send schedules for user [%s]", userID))) + return h.responseInternalServerError(c) + } + if !result.Allowed { + return h.responsePaymentRequired(c, result.Message) + } + + var request requests.MessageSendScheduleStore + if err = c.BodyParser(&request); err != nil { + return h.responseBadRequest(c, err) + } + + request = request.Sanitize() + if errors := h.validator.ValidateStore(ctx, request); len(errors) != 0 { + ctxLogger.Warn(stacktrace.NewError( + "validation errors [%s], while storing send schedule [%+#v]", + spew.Sdump(errors), + request, + )) + return h.responseUnprocessableEntity(c, errors, "validation errors while saving send schedule") + } + + schedule, err := h.service.Store(ctx, request.ToParams(h.userFromContext(c))) + if err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot create send schedule for user [%s]", userID))) + return h.responseInternalServerError(c) + } + + return h.responseCreated(c, "send schedule created successfully", schedule) +} + +// Update updates a send schedule owned by the authenticated user. +// +// @Summary Update send schedule +// @Description Update a send schedule owned by the authenticated user. +// @Security ApiKeyAuth +// @Tags SendSchedules +// @Accept json +// @Produce json +// @Param scheduleID path string true "Schedule ID" +// @Param payload body requests.MessageSendScheduleStore true "Payload of updated send schedule." +// @Success 200 {object} responses.MessageSendScheduleResponse +// @Failure 400 {object} responses.BadRequest +// @Failure 401 {object} responses.Unauthorized +// @Failure 404 {object} responses.NotFound +// @Failure 422 {object} responses.UnprocessableEntity +// @Failure 500 {object} responses.InternalServerError +// @Router /send-schedules/{scheduleID} [put] +func (h *MessageSendScheduleHandler) Update(c *fiber.Ctx) error { + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) + defer span.End() + + scheduleID, err := uuid.Parse(c.Params("scheduleID")) + if err != nil { + return h.responseBadRequest(c, err) + } + + var request requests.MessageSendScheduleStore + if err = c.BodyParser(&request); err != nil { + return h.responseBadRequest(c, err) + } + + request = request.Sanitize() + if errors := h.validator.ValidateStore(ctx, request); len(errors) != 0 { + return h.responseUnprocessableEntity(c, errors, "validation errors while updating send schedule") + } + + userID := h.userIDFomContext(c) + + schedule, err := h.service.Update(ctx, userID, scheduleID, request.ToParams(h.userFromContext(c))) + if err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot update send schedule for user [%s] and schedule [%s]", userID, scheduleID))) + if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { + return h.responseNotFound(c, err.Error()) + } + return h.responseInternalServerError(c) + } + + return h.responseOK(c, "send schedule updated successfully", schedule) +} + +// Delete removes a send schedule owned by the authenticated user. +// +// @Summary Delete send schedule +// @Description Delete a send schedule owned by the authenticated user. +// @Security ApiKeyAuth +// @Tags SendSchedules +// @Produce json +// @Param scheduleID path string true "Schedule ID" +// @Success 204 +// @Failure 400 {object} responses.BadRequest +// @Failure 401 {object} responses.Unauthorized +// @Failure 404 {object} responses.NotFound +// @Failure 500 {object} responses.InternalServerError +// @Router /send-schedules/{scheduleID} [delete] +func (h *MessageSendScheduleHandler) Delete(c *fiber.Ctx) error { + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) + defer span.End() + + scheduleID, err := uuid.Parse(c.Params("scheduleID")) + if err != nil { + return h.responseBadRequest(c, err) + } + + userID := h.userIDFomContext(c) + + if _, err = h.service.Load(ctx, userID, scheduleID); err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot load send schedule for deletion for user [%s] and schedule [%s]", userID, scheduleID))) + if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { + return h.responseNotFound(c, err.Error()) + } + return h.responseInternalServerError(c) + } + + if err = h.service.Delete(ctx, userID, scheduleID); err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot delete send schedule for user [%s] and schedule [%s]", userID, scheduleID))) + return h.responseInternalServerError(c) + } + + return h.responseNoContent(c, "send schedule deleted successfully") +} diff --git a/api/pkg/handlers/phone_api_key_handler.go b/api/pkg/handlers/phone_api_key_handler.go index c10df513..4cd7e1ab 100644 --- a/api/pkg/handlers/phone_api_key_handler.go +++ b/api/pkg/handlers/phone_api_key_handler.go @@ -3,6 +3,7 @@ package handlers import ( "fmt" + "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/repositories" "github.com/NdoleStudio/httpsms/pkg/requests" "github.com/NdoleStudio/httpsms/pkg/services" @@ -17,10 +18,11 @@ import ( // PhoneAPIKeyHandler handles phone API key http requests type PhoneAPIKeyHandler struct { handler - logger telemetry.Logger - tracer telemetry.Tracer - validator *validators.PhoneAPIKeyHandlerValidator - service *services.PhoneAPIKeyService + logger telemetry.Logger + tracer telemetry.Tracer + validator *validators.PhoneAPIKeyHandlerValidator + service *services.PhoneAPIKeyService + entitlementService *services.EntitlementService } // NewPhoneAPIKeyHandler creates a new PhoneAPIKeyHandler @@ -29,12 +31,14 @@ func NewPhoneAPIKeyHandler( tracer telemetry.Tracer, validator *validators.PhoneAPIKeyHandlerValidator, service *services.PhoneAPIKeyService, + entitlementService *services.EntitlementService, ) *PhoneAPIKeyHandler { return &PhoneAPIKeyHandler{ - logger: logger.WithService(fmt.Sprintf("%T", &PhoneAPIKeyHandler{})), - tracer: tracer, - validator: validator, - service: service, + logger: logger.WithService(fmt.Sprintf("%T", &PhoneAPIKeyHandler{})), + tracer: tracer, + validator: validator, + service: service, + entitlementService: entitlementService, } } @@ -99,6 +103,7 @@ func (h *PhoneAPIKeyHandler) index(c *fiber.Ctx) error { // @Success 200 {object} responses.PhoneAPIKeyResponse // @Failure 400 {object} responses.BadRequest // @Failure 401 {object} responses.Unauthorized +// @Failure 402 {object} responses.PaymentRequired // @Failure 422 {object} responses.UnprocessableEntity // @Failure 500 {object} responses.InternalServerError // @Router /phone-api-keys [post] @@ -106,6 +111,19 @@ func (h *PhoneAPIKeyHandler) store(c *fiber.Ctx) error { ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) defer span.End() + userID := h.userIDFomContext(c) + + result, err := h.entitlementService.Check(ctx, userID, entities.EntityNamePhoneAPIKey, func() (int, error) { + return h.service.CountByUser(ctx, userID) + }) + if err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot check entitlement for phone API keys for user [%s]", userID))) + return h.responseInternalServerError(c) + } + if !result.Allowed { + return h.responsePaymentRequired(c, result.Message) + } + var request requests.PhoneAPIKeyStoreRequest if err := c.BodyParser(&request); err != nil { msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request) diff --git a/api/pkg/handlers/phone_handler.go b/api/pkg/handlers/phone_handler.go index 9e5cbe1c..4c8efa09 100644 --- a/api/pkg/handlers/phone_handler.go +++ b/api/pkg/handlers/phone_handler.go @@ -3,6 +3,7 @@ package handlers import ( "fmt" + "github.com/NdoleStudio/httpsms/pkg/repositories" "github.com/NdoleStudio/httpsms/pkg/requests" "github.com/NdoleStudio/httpsms/pkg/validators" "github.com/davecgh/go-spew/spew" @@ -121,13 +122,13 @@ func (h *PhoneHandler) Upsert(c *fiber.Ctx) error { return h.responseBadRequest(c, err) } - if errors := h.validator.ValidateUpsert(ctx, request.Sanitize()); len(errors) != 0 { + if errors := h.validator.ValidateUpsert(ctx, h.userIDFomContext(c), request.Sanitize()); len(errors) != 0 { msg := fmt.Sprintf("validation errors [%s], while updating phones [%+#v]", spew.Sdump(errors), request) ctxLogger.Warn(stacktrace.NewError(msg)) return h.responseUnprocessableEntity(c, errors, "validation errors while updating phones") } - phone, err := h.service.Upsert(ctx, request.ToUpsertParams(h.userFromContext(c), c.OriginalURL())) + phone, err := h.service.Upsert(ctx, request.ToUpsertParams(h.userFromContext(c), c.OriginalURL(), c.Body())) if err != nil { msg := fmt.Sprintf("cannot update phones with params [%+#v]", request) ctxLogger.Error(stacktrace.Propagate(err, msg)) @@ -165,6 +166,9 @@ func (h *PhoneHandler) Delete(c *fiber.Ctx) error { } err := h.service.Delete(ctx, c.OriginalURL(), h.userIDFomContext(c), request.PhoneIDUuid()) + if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { + return h.responseNotFound(c, fmt.Sprintf("cannot find phone with ID [%s]", request.PhoneID)) + } if err != nil { msg := fmt.Sprintf("cannot delete phones with params [%+#v]", request) ctxLogger.Error(stacktrace.Propagate(err, msg)) diff --git a/api/pkg/handlers/user_handler.go b/api/pkg/handlers/user_handler.go index af77e718..d63046dc 100644 --- a/api/pkg/handlers/user_handler.go +++ b/api/pkg/handlers/user_handler.go @@ -46,6 +46,8 @@ func (h *UserHandler) RegisterRoutes(router fiber.Router, middlewares ...fiber.H router.Put("/v1/users/:userID/notifications", h.computeRoute(middlewares, h.UpdateNotifications)...) router.Get("/v1/users/subscription-update-url", h.computeRoute(middlewares, h.subscriptionUpdateURL)...) router.Delete("/v1/users/subscription", h.computeRoute(middlewares, h.cancelSubscription)...) + router.Get("/v1/users/subscription/payments", h.computeRoute(middlewares, h.subscriptionPayments)...) + router.Post("/v1/users/subscription/invoices/:subscriptionInvoiceID", h.computeRoute(middlewares, h.subscriptionInvoice)...) } // Show returns an entities.User @@ -62,14 +64,11 @@ func (h *UserHandler) RegisterRoutes(router fiber.Router, middlewares ...fiber.H // @Failure 500 {object} responses.InternalServerError // @Router /users/me [get] func (h *UserHandler) Show(c *fiber.Ctx) error { - ctx, span := h.tracer.StartFromFiberCtx(c) + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) defer span.End() - ctxLogger := h.tracer.CtxLogger(h.logger, span) - authUser := h.userFromContext(c) - - user, err := h.service.Get(ctx, authUser) + user, err := h.service.Get(ctx, c.OriginalURL(), authUser) if err != nil { msg := fmt.Sprintf("cannot get user with ID [%s]", authUser.ID) ctxLogger.Error(stacktrace.Propagate(err, msg)) @@ -112,7 +111,7 @@ func (h *UserHandler) Update(c *fiber.Ctx) error { return h.responseUnprocessableEntity(c, errors, "validation errors while updating user") } - user, err := h.service.Update(ctx, h.userFromContext(c), request.ToUpdateParams()) + user, err := h.service.Update(ctx, c.OriginalURL(), h.userFromContext(c), request.ToUpdateParams()) if err != nil { msg := fmt.Sprintf("cannot update user with params [%+#v]", request) ctxLogger.Error(stacktrace.Propagate(err, msg)) @@ -162,11 +161,9 @@ func (h *UserHandler) Delete(c *fiber.Ctx) error { // @Failure 500 {object} responses.InternalServerError // @Router /users/{userID}/notifications [put] func (h *UserHandler) UpdateNotifications(c *fiber.Ctx) error { - ctx, span := h.tracer.StartFromFiberCtx(c) + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) defer span.End() - ctxLogger := h.tracer.CtxLogger(h.logger, span) - var request requests.UserNotificationUpdate if err := c.BodyParser(&request); err != nil { msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request) @@ -275,3 +272,76 @@ func (h *UserHandler) DeleteAPIKey(c *fiber.Ctx) error { return h.responseOK(c, "API Key rotated successfully", user) } + +// subscriptionPayments returns the last 10 payments of the currently authenticated user +// @Summary Get the last 10 subscription payments. +// @Description Subscription payments are generated throughout the lifecycle of a subscription, typically there is one at the time of purchase and then one for each renewal. +// @Security ApiKeyAuth +// @Tags Users +// @Accept json +// @Produce json +// @Success 200 {object} responses.UserSubscriptionPaymentsResponse +// @Failure 400 {object} responses.BadRequest +// @Failure 401 {object} responses.Unauthorized +// @Failure 422 {object} responses.UnprocessableEntity +// @Failure 500 {object} responses.InternalServerError +// @Router /users/subscription/payments [get] +func (h *UserHandler) subscriptionPayments(c *fiber.Ctx) error { + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) + defer span.End() + + invoices, err := h.service.GetSubscriptionPayments(ctx, h.userIDFomContext(c)) + if err != nil { + msg := fmt.Sprintf("cannot get current subscription invoices for user [%s]", h.userFromContext(c)) + ctxLogger.Error(stacktrace.Propagate(err, msg)) + return h.responseInternalServerError(c) + } + + return h.responseOK(c, "fetched subscription invoices billing usage", invoices) +} + +// subscriptionInvoice generates an invoice for a given subscription invoice ID +// @Summary Generate a subscription payment invoice +// @Description Generates a new invoice PDF file for the given subscription payment with given parameters. +// @Security ApiKeyAuth +// @Tags Users +// @Accept json +// @Produce application/pdf +// @Param payload body requests.UserPaymentInvoice true "Generate subscription payment invoice parameters" +// @Param subscriptionInvoiceID path string true "ID of the subscription invoice to generate the PDF for" +// @Success 200 {file} file +// @Failure 400 {object} responses.BadRequest +// @Failure 401 {object} responses.Unauthorized +// @Failure 422 {object} responses.UnprocessableEntity +// @Failure 500 {object} responses.InternalServerError +// @Router /users/subscription/invoices/{subscriptionInvoiceID} [post] +func (h *UserHandler) subscriptionInvoice(c *fiber.Ctx) error { + ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) + defer span.End() + + var request requests.UserPaymentInvoice + if err := c.BodyParser(&request); err != nil { + msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.Body(), request) + ctxLogger.Warn(stacktrace.Propagate(err, msg)) + return h.responseBadRequest(c, err) + } + + request.SubscriptionInvoiceID = c.Params("subscriptionInvoiceID") + if errors := h.validator.ValidatePaymentInvoice(ctx, h.userIDFomContext(c), request.Sanitize()); len(errors) != 0 { + msg := fmt.Sprintf("validation errors [%s], while validating subscription payment invoice request [%s]", spew.Sdump(errors), c.Body()) + ctxLogger.Warn(stacktrace.NewError(msg)) + return h.responseUnprocessableEntity(c, errors, "validation errors while generating payment invoice") + } + + data, err := h.service.GenerateReceipt(ctx, request.UserInvoiceGenerateParams(h.userIDFomContext(c))) + if err != nil { + msg := fmt.Sprintf("cannot generate receipt for invoice ID [%s] and user [%s]", request.SubscriptionInvoiceID, h.userFromContext(c)) + ctxLogger.Error(stacktrace.Propagate(err, msg)) + return h.responseInternalServerError(c) + } + + c.Set(fiber.HeaderContentType, "application/pdf") + c.Set(fiber.HeaderContentDisposition, fmt.Sprintf("attachment; filename=\"httpsms.com - %s.pdf\"", request.SubscriptionInvoiceID)) + + return c.SendStream(data) +} diff --git a/api/pkg/listeners/marketing_listener.go b/api/pkg/listeners/marketing_listener.go index fbbb735f..62da4829 100644 --- a/api/pkg/listeners/marketing_listener.go +++ b/api/pkg/listeners/marketing_listener.go @@ -32,9 +32,28 @@ func NewMarketingListener( return l, map[string]events.EventListener{ events.UserAccountDeleted: l.onUserAccountDeleted, + events.UserAccountCreated: l.onUserAccountCreated, } } +func (listener *MarketingListener) onUserAccountCreated(ctx context.Context, event cloudevents.Event) error { + ctx, span := listener.tracer.Start(ctx) + defer span.End() + + var payload events.UserAccountCreatedPayload + if err := event.DataAs(&payload); err != nil { + msg := fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if err := listener.service.CreateContact(ctx, payload.UserID); err != nil { + msg := fmt.Sprintf("cannot create [contact] for user [%s] on [%s] event with ID [%s]", payload.UserID, event.Type(), event.ID()) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + func (listener *MarketingListener) onUserAccountDeleted(ctx context.Context, event cloudevents.Event) error { ctx, span := listener.tracer.Start(ctx) defer span.End() @@ -45,8 +64,8 @@ func (listener *MarketingListener) onUserAccountDeleted(ctx context.Context, eve return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } - if err := listener.service.DeleteUser(ctx, payload.UserID); err != nil { - msg := fmt.Sprintf("cannot delete [sendgrid contact] for user [%s] on [%s] event with ID [%s]", payload.UserID, event.Type(), event.ID()) + if err := listener.service.DeleteContact(ctx, payload.UserEmail); err != nil { + msg := fmt.Sprintf("cannot delete [contact] for user [%s] on [%s] event with ID [%s]", payload.UserID, event.Type(), event.ID()) return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } diff --git a/api/pkg/listeners/message_send_schedule_listener.go b/api/pkg/listeners/message_send_schedule_listener.go new file mode 100644 index 00000000..20d4955d --- /dev/null +++ b/api/pkg/listeners/message_send_schedule_listener.go @@ -0,0 +1,57 @@ +package listeners + +import ( + "context" + "fmt" + + "github.com/NdoleStudio/httpsms/pkg/events" + "github.com/NdoleStudio/httpsms/pkg/services" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + cloudevents "github.com/cloudevents/sdk-go/v2" + "github.com/palantir/stacktrace" +) + +// MessageSendScheduleListener handles cloud events related to message send schedules. +type MessageSendScheduleListener struct { + logger telemetry.Logger + tracer telemetry.Tracer + service *services.MessageSendScheduleService +} + +// NewMessageSendScheduleListener creates a new instance of MessageSendScheduleListener. +func NewMessageSendScheduleListener( + logger telemetry.Logger, + tracer telemetry.Tracer, + service *services.MessageSendScheduleService, +) (l *MessageSendScheduleListener, routes map[string]events.EventListener) { + l = &MessageSendScheduleListener{ + logger: logger.WithService(fmt.Sprintf("%T", &MessageSendScheduleListener{})), + tracer: tracer, + service: service, + } + + return l, map[string]events.EventListener{ + events.UserAccountDeleted: l.onUserAccountDeleted, + } +} + +// onUserAccountDeleted removes all message send schedules for a deleted user account. +func (listener *MessageSendScheduleListener) onUserAccountDeleted( + ctx context.Context, + event cloudevents.Event, +) error { + ctx, span := listener.tracer.Start(ctx) + defer span.End() + + var payload events.UserAccountDeletedPayload + if err := event.DataAs(&payload); err != nil { + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload))) + } + + if err := listener.service.DeleteAllForUser(ctx, payload.UserID); err != nil { + msg := fmt.Sprintf("cannot delete [entities.MessageSendSchedule] for user [%s] on [%s] event with ID [%s]", payload.UserID, event.Type(), event.ID()) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} diff --git a/api/pkg/listeners/phone_listener.go b/api/pkg/listeners/phone_listener.go new file mode 100644 index 00000000..541936d9 --- /dev/null +++ b/api/pkg/listeners/phone_listener.go @@ -0,0 +1,76 @@ +package listeners + +import ( + "context" + "fmt" + + cloudevents "github.com/cloudevents/sdk-go/v2" + "github.com/palantir/stacktrace" + + "github.com/NdoleStudio/httpsms/pkg/events" + "github.com/NdoleStudio/httpsms/pkg/services" + "github.com/NdoleStudio/httpsms/pkg/telemetry" +) + +// PhoneListener handles cloud events that alter the state of entities.Phone +type PhoneListener struct { + logger telemetry.Logger + tracer telemetry.Tracer + service *services.PhoneService +} + +// NewPhoneListener creates a new instance of PhoneListener +func NewPhoneListener( + logger telemetry.Logger, + tracer telemetry.Tracer, + service *services.PhoneService, +) (l *PhoneListener, routes map[string]events.EventListener) { + l = &PhoneListener{ + logger: logger.WithService(fmt.Sprintf("%T", l)), + tracer: tracer, + service: service, + } + + return l, map[string]events.EventListener{ + events.EventTypeMessageSendScheduleDeleted: l.onMessageSendScheduleDeleted, + events.UserAccountDeleted: l.onUserAccountDeleted, + } +} + +// onMessageSendScheduleDeleted handles the events.EventTypeMessageSendScheduleDeleted event +func (listener *PhoneListener) onMessageSendScheduleDeleted(ctx context.Context, event cloudevents.Event) error { + ctx, span := listener.tracer.Start(ctx) + defer span.End() + + var payload events.MessageSendScheduleDeletedPayload + if err := event.DataAs(&payload); err != nil { + msg := fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if err := listener.service.NullifyScheduleID(ctx, payload.UserID, payload.ScheduleID); err != nil { + msg := fmt.Sprintf("cannot nullify schedule ID [%s] for user [%s] on [%s] event with ID [%s]", payload.ScheduleID, payload.UserID, event.Type(), event.ID()) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + +// onUserAccountDeleted handles the events.UserAccountDeleted event +func (listener *PhoneListener) onUserAccountDeleted(ctx context.Context, event cloudevents.Event) error { + ctx, span := listener.tracer.Start(ctx) + defer span.End() + + var payload events.UserAccountDeletedPayload + if err := event.DataAs(&payload); err != nil { + msg := fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if err := listener.service.DeleteAllForUser(ctx, payload.UserID); err != nil { + msg := fmt.Sprintf("cannot delete all [entities.Phone] for user [%s] on [%s] event with ID [%s]", payload.UserID, event.Type(), event.ID()) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} diff --git a/api/pkg/listeners/phone_notification_listener.go b/api/pkg/listeners/phone_notification_listener.go index e1b3eef7..95333ef7 100644 --- a/api/pkg/listeners/phone_notification_listener.go +++ b/api/pkg/listeners/phone_notification_listener.go @@ -38,6 +38,7 @@ func NewNotificationListener( events.EventTypeMessageNotificationSend: l.onMessageNotificationSend, events.PhoneHeartbeatMissed: l.onPhoneHeartbeatMissed, events.UserAccountDeleted: l.onUserAccountDeleted, + events.MessageAPIDeleted: l.onMessageAPIDeleted, } } @@ -53,14 +54,16 @@ func (listener *PhoneNotificationListener) onMessageAPISent(ctx context.Context, } sendParams := &services.PhoneNotificationScheduleParams{ - UserID: payload.UserID, - Owner: payload.Owner, - Contact: payload.Contact, - Content: payload.Content, - SIM: payload.SIM, - Encrypted: payload.Encrypted, - Source: event.Source(), - MessageID: payload.MessageID, + UserID: payload.UserID, + Owner: payload.Owner, + Contact: payload.Contact, + Content: payload.Content, + SIM: payload.SIM, + Encrypted: payload.Encrypted, + Source: event.Source(), + MessageID: payload.MessageID, + ExactSendTime: payload.ExactSendTime, + ScheduledSendTime: payload.ScheduledSendTime, } if err := listener.service.Schedule(ctx, sendParams); err != nil { @@ -165,3 +168,22 @@ func (listener *PhoneNotificationListener) onUserAccountDeleted(ctx context.Cont return nil } + +// onMessageAPIDeleted handles the events.MessageAPIDeleted event +func (listener *PhoneNotificationListener) onMessageAPIDeleted(ctx context.Context, event cloudevents.Event) error { + ctx, span := listener.tracer.Start(ctx) + defer span.End() + + var payload events.MessageAPIDeletedPayload + if err := event.DataAs(&payload); err != nil { + msg := fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if err := listener.service.DeleteByMessageID(ctx, payload.UserID, payload.MessageID); err != nil { + msg := fmt.Sprintf("cannot delete [entities.PhoneNotification] for user [%s] and message [%s] on [%s] event with ID [%s]", payload.UserID, payload.MessageID, event.Type(), event.ID()) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} diff --git a/api/pkg/listeners/websocket_listener.go b/api/pkg/listeners/websocket_listener.go index 02e9a36a..2c0e2c17 100644 --- a/api/pkg/listeners/websocket_listener.go +++ b/api/pkg/listeners/websocket_listener.go @@ -32,9 +32,10 @@ func NewWebsocketListener( } return l, map[string]events.EventListener{ - events.EventTypePhoneUpdated: l.onPhoneUpdated, - events.EventTypeMessagePhoneSent: l.onMessagePhoneSent, - events.EventTypeMessageSendFailed: l.onMessagePhoneFailed, + events.EventTypePhoneUpdated: l.onPhoneUpdated, + events.EventTypeMessagePhoneSent: l.onMessagePhoneSent, + events.EventTypeMessageSendFailed: l.onMessagePhoneFailed, + events.EventTypeMessagePhoneReceived: l.onMessagePhoneReceived, } } @@ -57,6 +58,25 @@ func (listener *WebsocketListener) onMessagePhoneSent(ctx context.Context, event return nil } +// onMessagePhoneReceived handles the events.EventTypeMessagePhoneReceived event +func (listener *WebsocketListener) onMessagePhoneReceived(ctx context.Context, event cloudevents.Event) error { + ctx, span, _ := listener.tracer.StartWithLogger(ctx, listener.logger) + defer span.End() + + var payload events.MessagePhoneReceivedPayload + if err := event.DataAs(&payload); err != nil { + msg := fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if err := listener.client.Trigger(payload.UserID.String(), event.Type(), event.ID()); err != nil { + msg := fmt.Sprintf("cannot trigger websocket [%s] event with ID [%s] for user with ID [%s]", event.Type(), event.ID(), payload.UserID) + return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + // onMessagePhoneFailed handles the events.EventTypeMessageSendFailed event func (listener *WebsocketListener) onMessagePhoneFailed(ctx context.Context, event cloudevents.Event) error { ctx, span, _ := listener.tracer.StartWithLogger(ctx, listener.logger) diff --git a/api/pkg/middlewares/api_key_auth_middleware.go b/api/pkg/middlewares/api_key_auth_middleware.go index 17ac4335..d971c94a 100644 --- a/api/pkg/middlewares/api_key_auth_middleware.go +++ b/api/pkg/middlewares/api_key_auth_middleware.go @@ -33,7 +33,6 @@ func APIKeyAuth(logger telemetry.Logger, tracer telemetry.Tracer, userRepository } c.Locals(ContextKeyAuthUserID, authUser) - ctxLogger.Info(fmt.Sprintf("[%T] set successfully for user with ID [%s]", authUser, authUser.ID)) return c.Next() } } diff --git a/api/pkg/middlewares/bearer_api_key_auth_middleware.go b/api/pkg/middlewares/bearer_api_key_auth_middleware.go index 2b1dc1c2..16d9ac5e 100644 --- a/api/pkg/middlewares/bearer_api_key_auth_middleware.go +++ b/api/pkg/middlewares/bearer_api_key_auth_middleware.go @@ -15,11 +15,9 @@ func BearerAPIKeyAuth(logger telemetry.Logger, tracer telemetry.Tracer, userRepo logger = logger.WithService("middlewares.APIKeyAuth") return func(c *fiber.Ctx) error { - ctx, span := tracer.StartFromFiberCtx(c, "middlewares.APIKeyAuth") + ctx, span, ctxLogger := tracer.StartFromFiberCtxWithLogger(c, logger, "middlewares.APIKeyAuth") defer span.End() - ctxLogger := tracer.CtxLogger(logger, span) - apiKey := strings.TrimSpace(strings.Replace(c.Get(authHeaderBearer), bearerScheme, "", 1)) if len(apiKey) == 0 { span.AddEvent(fmt.Sprintf("the request header has no [%s] api key", authHeaderAPIKey)) @@ -33,9 +31,6 @@ func BearerAPIKeyAuth(logger telemetry.Logger, tracer telemetry.Tracer, userRepo } c.Locals(ContextKeyAuthUserID, authUser) - - ctxLogger.Info(fmt.Sprintf("[%T] set successfully for user with ID [%s]", authUser, authUser.ID)) - return c.Next() } } diff --git a/api/pkg/middlewares/bearer_auth_middleware.go b/api/pkg/middlewares/bearer_auth_middleware.go index 7df1ca3a..ffd29f0d 100644 --- a/api/pkg/middlewares/bearer_auth_middleware.go +++ b/api/pkg/middlewares/bearer_auth_middleware.go @@ -46,8 +46,6 @@ func BearerAuth(logger telemetry.Logger, tracer telemetry.Tracer, authClient *au } c.Locals(ContextKeyAuthUserID, authUser) - - ctxLogger.Info(fmt.Sprintf("[%T] set successfully for user with ID [%s]", authUser, authUser.ID)) return c.Next() } } diff --git a/api/pkg/middlewares/http_request_logger_middleware.go b/api/pkg/middlewares/http_request_logger_middleware.go index bc0146f0..75ddcae2 100644 --- a/api/pkg/middlewares/http_request_logger_middleware.go +++ b/api/pkg/middlewares/http_request_logger_middleware.go @@ -2,6 +2,7 @@ package middlewares import ( "fmt" + "slices" "github.com/NdoleStudio/httpsms/pkg/telemetry" "github.com/gofiber/fiber/v2" @@ -18,17 +19,12 @@ func HTTPRequestLogger(tracer telemetry.Tracer, logger telemetry.Logger) fiber.H _, span, ctxLogger := tracer.StartFromFiberCtxWithLogger(c, logger) defer span.End() - ctxLogger.WithString("http.method", c.Method()). - WithString("http.path", c.Path()). - WithString("client.version", c.Get(clientVersionHeader)). - Trace(fmt.Sprintf("%s %s", c.Method(), c.OriginalURL())) - response := c.Next() statusCode := c.Response().StatusCode() span.AddEvent(fmt.Sprintf("finished handling request with traceID: [%s], statusCode: [%d]", span.SpanContext().TraceID().String(), statusCode)) - if statusCode >= 300 && len(c.Request().Body()) > 0 { - ctxLogger.Warn(stacktrace.NewError(fmt.Sprintf("http.status [%d], body [%s]", statusCode, string(c.Request().Body())))) + if statusCode >= 300 && len(c.Request().Body()) > 0 && !slices.Contains([]int{401, 402}, statusCode) { + ctxLogger.WithString("client.version", c.Get(clientVersionHeader)).Warn(stacktrace.NewError(fmt.Sprintf("http.status [%d], body [%s]", statusCode, string(c.Request().Body())))) } return response diff --git a/api/pkg/middlewares/phone_api_key_auth_middleware.go b/api/pkg/middlewares/phone_api_key_auth_middleware.go index dc19c3b8..72bc75ae 100644 --- a/api/pkg/middlewares/phone_api_key_auth_middleware.go +++ b/api/pkg/middlewares/phone_api_key_auth_middleware.go @@ -31,7 +31,6 @@ func PhoneAPIKeyAuth(logger telemetry.Logger, tracer telemetry.Tracer, repositor } c.Locals(ContextKeyAuthUserID, authUser) - ctxLogger.Info(fmt.Sprintf("[%T] set successfully for user with ID [%s]", authUser, authUser.ID)) return c.Next() } } diff --git a/api/pkg/repositories/attachment_repository.go b/api/pkg/repositories/attachment_repository.go new file mode 100644 index 00000000..11d80e20 --- /dev/null +++ b/api/pkg/repositories/attachment_repository.go @@ -0,0 +1,99 @@ +package repositories + +import ( + "context" + "fmt" + "path/filepath" + "strings" +) + +// AttachmentRepository is the interface for storing and retrieving message attachments +type AttachmentRepository interface { + // Upload stores attachment data at the given path with the specified content type + Upload(ctx context.Context, path string, data []byte, contentType string) error + // Download retrieves attachment data from the given path + Download(ctx context.Context, path string) ([]byte, error) + // Delete removes an attachment at the given path + Delete(ctx context.Context, path string) error +} + +// contentTypeExtensions maps MIME types to file extensions +var contentTypeExtensions = map[string]string{ + "image/jpeg": ".jpg", + "image/png": ".png", + "image/gif": ".gif", + "image/webp": ".webp", + "image/bmp": ".bmp", + "video/mp4": ".mp4", + "video/3gpp": ".3gp", + "audio/mpeg": ".mp3", + "audio/ogg": ".ogg", + "audio/amr": ".amr", + "application/pdf": ".pdf", + "text/vcard": ".vcf", + "text/x-vcard": ".vcf", +} + +// extensionContentTypes is the reverse map from file extensions to canonical MIME types +var extensionContentTypes = map[string]string{ + ".jpg": "image/jpeg", + ".png": "image/png", + ".gif": "image/gif", + ".webp": "image/webp", + ".bmp": "image/bmp", + ".mp4": "video/mp4", + ".3gp": "video/3gpp", + ".mp3": "audio/mpeg", + ".ogg": "audio/ogg", + ".amr": "audio/amr", + ".pdf": "application/pdf", + ".vcf": "text/vcard", +} + +// AllowedContentTypes returns the set of allowed MIME types for attachments +func AllowedContentTypes() map[string]bool { + allowed := make(map[string]bool, len(contentTypeExtensions)) + for ct := range contentTypeExtensions { + allowed[ct] = true + } + return allowed +} + +// ExtensionFromContentType returns the file extension for a MIME content type. +// Returns ".bin" if the content type is not recognized. +func ExtensionFromContentType(contentType string) string { + if ext, ok := contentTypeExtensions[contentType]; ok { + return ext + } + return ".bin" +} + +// ContentTypeFromExtension returns the MIME content type for a file extension. +// Returns "application/octet-stream" if the extension is not recognized. +func ContentTypeFromExtension(ext string) string { + if ct, ok := extensionContentTypes[ext]; ok { + return ct + } + return "application/octet-stream" +} + +// SanitizeFilename removes path separators and traversal sequences from a filename. +// Returns "attachment-{index}" if the sanitized name is empty. +func SanitizeFilename(name string, index int) string { + name = strings.TrimSuffix(name, filepath.Ext(name)) + + var builder strings.Builder + for _, r := range name { + if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' || r == '-' { + builder.WriteRune(r) + } else if r == ' ' { + builder.WriteRune('-') + } + } + name = strings.Trim(builder.String(), "-") + + if name == "" { + return fmt.Sprintf("attachment-%d", index) + } + return name +} diff --git a/api/pkg/repositories/attachment_repository_test.go b/api/pkg/repositories/attachment_repository_test.go new file mode 100644 index 00000000..1b29fa68 --- /dev/null +++ b/api/pkg/repositories/attachment_repository_test.go @@ -0,0 +1,63 @@ +package repositories + +import "testing" + +func TestExtensionFromContentType(t *testing.T) { + tests := []struct { + contentType string + expected string + }{ + {"image/jpeg", ".jpg"}, + {"image/png", ".png"}, + {"image/gif", ".gif"}, + {"image/webp", ".webp"}, + {"image/bmp", ".bmp"}, + {"video/mp4", ".mp4"}, + {"video/3gpp", ".3gp"}, + {"audio/mpeg", ".mp3"}, + {"audio/ogg", ".ogg"}, + {"audio/amr", ".amr"}, + {"application/pdf", ".pdf"}, + {"text/vcard", ".vcf"}, + {"text/x-vcard", ".vcf"}, + {"application/octet-stream", ".bin"}, + {"unknown/type", ".bin"}, + {"", ".bin"}, + } + for _, tt := range tests { + t.Run(tt.contentType, func(t *testing.T) { + got := ExtensionFromContentType(tt.contentType) + if got != tt.expected { + t.Errorf("ExtensionFromContentType(%q) = %q, want %q", tt.contentType, got, tt.expected) + } + }) + } +} + +func TestSanitizeFilename(t *testing.T) { + tests := []struct { + name string + index int + expected string + }{ + {"photo.jpg", 0, "photo"}, + {"../../etc/passwd", 0, "etcpasswd"}, + {"hello/world\\test", 0, "helloworldtest"}, + {"normal_file", 0, "normal_file"}, + {"", 0, "attachment-0"}, + {" ", 0, "attachment-0"}, + {"...", 1, "attachment-1"}, + {"My Photo", 0, "My-Photo"}, + {"file name with spaces.png", 0, "file-name-with-spaces"}, + {"UPPER_CASE", 0, "UPPER_CASE"}, + {"special!@#chars", 0, "specialchars"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := SanitizeFilename(tt.name, tt.index) + if got != tt.expected { + t.Errorf("SanitizeFilename(%q, %d) = %q, want %q", tt.name, tt.index, got, tt.expected) + } + }) + } +} diff --git a/api/pkg/repositories/google_cloud_storage_attachment_repository.go b/api/pkg/repositories/google_cloud_storage_attachment_repository.go new file mode 100644 index 00000000..d1e0eb92 --- /dev/null +++ b/api/pkg/repositories/google_cloud_storage_attachment_repository.go @@ -0,0 +1,92 @@ +package repositories + +import ( + "context" + "errors" + "fmt" + "io" + + "cloud.google.com/go/storage" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/palantir/stacktrace" +) + +// GoogleCloudStorageAttachmentRepository stores attachments in Google Cloud Storage +type GoogleCloudStorageAttachmentRepository struct { + logger telemetry.Logger + tracer telemetry.Tracer + client *storage.Client + bucket string +} + +// NewGoogleCloudStorageAttachmentRepository creates a new GoogleCloudStorageAttachmentRepository +func NewGoogleCloudStorageAttachmentRepository( + logger telemetry.Logger, + tracer telemetry.Tracer, + client *storage.Client, + bucket string, +) *GoogleCloudStorageAttachmentRepository { + return &GoogleCloudStorageAttachmentRepository{ + logger: logger.WithService(fmt.Sprintf("%T", &GoogleCloudStorageAttachmentRepository{})), + tracer: tracer, + client: client, + bucket: bucket, + } +} + +// Upload stores attachment data at the given path in GCS +func (s *GoogleCloudStorageAttachmentRepository) Upload(ctx context.Context, path string, data []byte, contentType string) error { + ctx, span, ctxLogger := s.tracer.StartWithLogger(ctx, s.logger) + defer span.End() + + writer := s.client.Bucket(s.bucket).Object(path).NewWriter(ctx) + writer.ContentType = contentType + + if _, err := writer.Write(data); err != nil { + return s.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot write attachment to GCS path [%s]", path))) + } + + if err := writer.Close(); err != nil { + return s.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot close GCS writer for path [%s]", path))) + } + + ctxLogger.Info(fmt.Sprintf("uploaded attachment to GCS path [%s/%s] with size [%d]", s.bucket, path, len(data))) + return nil +} + +// Download retrieves attachment data from the given path in GCS +func (s *GoogleCloudStorageAttachmentRepository) Download(ctx context.Context, path string) ([]byte, error) { + ctx, span, ctxLogger := s.tracer.StartWithLogger(ctx, s.logger) + defer span.End() + + reader, err := s.client.Bucket(s.bucket).Object(path).NewReader(ctx) + if err != nil { + msg := fmt.Sprintf("cannot open GCS reader for path [%s]", path) + if errors.Is(err, storage.ErrObjectNotExist) { + return nil, s.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg)) + } + return nil, s.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + defer reader.Close() + + data, err := io.ReadAll(reader) + if err != nil { + return nil, s.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot read attachment from GCS path [%s]", path))) + } + + ctxLogger.Info(fmt.Sprintf("downloaded attachment from GCS path [%s/%s] with size [%d]", s.bucket, path, len(data))) + return data, nil +} + +// Delete removes an attachment at the given path in GCS +func (s *GoogleCloudStorageAttachmentRepository) Delete(ctx context.Context, path string) error { + ctx, span, ctxLogger := s.tracer.StartWithLogger(ctx, s.logger) + defer span.End() + + if err := s.client.Bucket(s.bucket).Object(path).Delete(ctx); err != nil { + return s.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot delete GCS object at path [%s]", path))) + } + + ctxLogger.Info(fmt.Sprintf("deleted attachment from GCS path [%s/%s]", s.bucket, path)) + return nil +} diff --git a/api/pkg/repositories/gorm_heartbeat_monitor_repository.go b/api/pkg/repositories/gorm_heartbeat_monitor_repository.go index b88c15e2..e6f5aee5 100644 --- a/api/pkg/repositories/gorm_heartbeat_monitor_repository.go +++ b/api/pkg/repositories/gorm_heartbeat_monitor_repository.go @@ -22,6 +22,19 @@ type gormHeartbeatMonitorRepository struct { db *gorm.DB } +// NewGormHeartbeatMonitorRepository creates the GORM version of the HeartbeatMonitorRepository +func NewGormHeartbeatMonitorRepository( + logger telemetry.Logger, + tracer telemetry.Tracer, + db *gorm.DB, +) HeartbeatMonitorRepository { + return &gormHeartbeatMonitorRepository{ + logger: logger.WithService(fmt.Sprintf("%T", &gormHeartbeatRepository{})), + tracer: tracer, + db: db, + } +} + func (repository *gormHeartbeatMonitorRepository) DeleteAllForUser(ctx context.Context, userID entities.UserID) error { ctx, span := repository.tracer.Start(ctx) defer span.End() @@ -30,7 +43,6 @@ func (repository *gormHeartbeatMonitorRepository) DeleteAllForUser(ctx context.C msg := fmt.Sprintf("cannot delete all [%T] for user with ID [%s]", &entities.HeartbeatMonitor{}, userID) return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } - return nil } @@ -98,19 +110,6 @@ func (repository *gormHeartbeatMonitorRepository) Delete(ctx context.Context, us return nil } -// NewGormHeartbeatMonitorRepository creates the GORM version of the HeartbeatMonitorRepository -func NewGormHeartbeatMonitorRepository( - logger telemetry.Logger, - tracer telemetry.Tracer, - db *gorm.DB, -) HeartbeatMonitorRepository { - return &gormHeartbeatMonitorRepository{ - logger: logger.WithService(fmt.Sprintf("%T", &gormHeartbeatRepository{})), - tracer: tracer, - db: db, - } -} - // Index entities.Message between 2 parties func (repository *gormHeartbeatMonitorRepository) Index(ctx context.Context, userID entities.UserID, owner string, params IndexParams) (*[]entities.Heartbeat, error) { ctx, span := repository.tracer.Start(ctx) @@ -158,7 +157,6 @@ func (repository *gormHeartbeatMonitorRepository) Load(ctx context.Context, user Where("user_id = ?", userID). Where("owner = ?", owner). First(&phone).Error - if errors.Is(err, gorm.ErrRecordNotFound) { msg := fmt.Sprintf("heartbeat monitor with userID [%s] and owner [%s] does not exist", userID, owner) return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg)) @@ -188,7 +186,7 @@ func (repository *gormHeartbeatMonitorRepository) Exists(ctx context.Context, us Where("id = ?", monitorID). Find(&exists).Error if err != nil { - msg := fmt.Sprintf("cannot check if heartbeat monitor exists with userID [%s] and montiorID [%s]", userID, monitorID) + msg := fmt.Sprintf("cannot check if heartbeat monitor exists with userID [%s] and montior ID [%s]", userID, monitorID) return exists, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } diff --git a/api/pkg/repositories/gorm_heartbeat_repository.go b/api/pkg/repositories/gorm_heartbeat_repository.go index 8e763f60..e9ddf7ce 100644 --- a/api/pkg/repositories/gorm_heartbeat_repository.go +++ b/api/pkg/repositories/gorm_heartbeat_repository.go @@ -36,7 +36,8 @@ func (repository *gormHeartbeatRepository) DeleteAllForUser(ctx context.Context, ctx, span := repository.tracer.Start(ctx) defer span.End() - if err := repository.db.WithContext(ctx).Where("user_id = ?", userID).Delete(&entities.Heartbeat{}).Error; err != nil { + err := repository.db.WithContext(ctx).Where("user_id = ?", userID).Delete(&entities.Heartbeat{}).Error + if err != nil { msg := fmt.Sprintf("cannot delete all [%T] for user with ID [%s]", &entities.Heartbeat{}, userID) return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } @@ -85,7 +86,8 @@ func (repository *gormHeartbeatRepository) Index(ctx context.Context, userID ent } heartbeats := new([]entities.Heartbeat) - if err := query.Order("timestamp DESC").Limit(params.Limit).Offset(params.Skip).Find(&heartbeats).Error; err != nil { + err := query.Order("timestamp DESC").Limit(params.Limit).Offset(params.Skip).Find(&heartbeats).Error + if err != nil { msg := fmt.Sprintf("cannot fetch heartbeats with owner [%s] and params [%+#v]", owner, params) return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } diff --git a/api/pkg/repositories/gorm_message_repository.go b/api/pkg/repositories/gorm_message_repository.go index 607af44e..03237566 100644 --- a/api/pkg/repositories/gorm_message_repository.go +++ b/api/pkg/repositories/gorm_message_repository.go @@ -176,6 +176,37 @@ func (repository *gormMessageRepository) Search(ctx context.Context, userID enti return messages, nil } +// GetBulkMessages fetches the last bulk message summaries for a user +func (repository *gormMessageRepository) GetBulkMessages(ctx context.Context, userID entities.UserID, limit int) ([]*entities.BulkMessage, error) { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + orders := make([]*entities.BulkMessage, 0) + err := repository.db.WithContext(ctx).Raw(` + SELECT + request_id, + COUNT(*) as total, + COUNT(*) FILTER (WHERE status = 'scheduled') as scheduled_count, + COUNT(*) FILTER (WHERE status = 'pending') as pending_count, + COUNT(*) FILTER (WHERE status = 'failed') as failed_count, + COUNT(*) FILTER (WHERE status = 'expired') as expired_count, + COUNT(*) FILTER (WHERE status = 'sent') as sent_count, + COUNT(*) FILTER (WHERE status = 'delivered') as delivered_count, + MIN(created_at) as created_at + FROM messages + WHERE user_id = ? AND request_id LIKE 'bulk-%' + GROUP BY request_id + ORDER BY MIN(created_at) DESC + LIMIT ? + `, userID, limit).Scan(&orders).Error + if err != nil { + msg := fmt.Sprintf("cannot fetch bulk message orders for user [%s]", userID) + return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return orders, nil +} + // Store a new entities.Message func (repository *gormMessageRepository) Store(ctx context.Context, message *entities.Message) error { ctx, span := repository.tracer.Start(ctx) diff --git a/api/pkg/repositories/gorm_message_send_schedule_repository.go b/api/pkg/repositories/gorm_message_send_schedule_repository.go new file mode 100644 index 00000000..54e58843 --- /dev/null +++ b/api/pkg/repositories/gorm_message_send_schedule_repository.go @@ -0,0 +1,168 @@ +package repositories + +import ( + "context" + "errors" + "fmt" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/google/uuid" + "github.com/palantir/stacktrace" + "gorm.io/gorm" +) + +// gormMessageSendScheduleRepository persists and loads entities.MessageSendSchedule using GORM. +type gormMessageSendScheduleRepository struct { + logger telemetry.Logger + tracer telemetry.Tracer + db *gorm.DB +} + +// NewGormMessageSendScheduleRepository creates a new GORM-backed MessageSendScheduleRepository. +func NewGormMessageSendScheduleRepository( + logger telemetry.Logger, + tracer telemetry.Tracer, + db *gorm.DB, +) MessageSendScheduleRepository { + return &gormMessageSendScheduleRepository{ + logger: logger.WithService(fmt.Sprintf("%T", &gormMessageSendScheduleRepository{})), + tracer: tracer, + db: db, + } +} + +// Store saves a new message send schedule. +func (r *gormMessageSendScheduleRepository) Store( + ctx context.Context, + schedule *entities.MessageSendSchedule, +) error { + ctx, span := r.tracer.Start(ctx) + defer span.End() + + if err := r.db.WithContext(ctx).Create(schedule).Error; err != nil { + return r.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot store send schedule [%s]", schedule.ID)) + } + + return nil +} + +// Update persists changes to an existing message send schedule. +func (r *gormMessageSendScheduleRepository) Update( + ctx context.Context, + schedule *entities.MessageSendSchedule, +) error { + ctx, span := r.tracer.Start(ctx) + defer span.End() + + if err := r.db.WithContext(ctx).Save(schedule).Error; err != nil { + return r.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot update send schedule [%s]", schedule.ID)) + } + + return nil +} + +// Load fetches a message send schedule by user ID and schedule ID. +func (r *gormMessageSendScheduleRepository) Load( + ctx context.Context, + userID entities.UserID, + scheduleID uuid.UUID, +) (*entities.MessageSendSchedule, error) { + ctx, span := r.tracer.Start(ctx) + defer span.End() + + item := new(entities.MessageSendSchedule) + err := r.db.WithContext(ctx). + Where("user_id = ?", userID). + Where("id = ?", scheduleID). + First(item).Error + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, r.tracer.WrapErrorSpan( + span, + stacktrace.PropagateWithCode(err, ErrCodeNotFound, "send schedule [%s] not found for user with ID [%s]", scheduleID, userID), + ) + } + if err != nil { + return nil, r.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot load send schedule [%s]", scheduleID)) + } + + return item, nil +} + +// Index lists all message send schedules owned by the given user. +func (r *gormMessageSendScheduleRepository) Index( + ctx context.Context, + userID entities.UserID, +) ([]entities.MessageSendSchedule, error) { + ctx, span := r.tracer.Start(ctx) + defer span.End() + + items := make([]entities.MessageSendSchedule, 0) + err := r.db.WithContext(ctx). + Where("user_id = ?", userID). + Order("created_at DESC"). + Find(&items).Error + if err != nil { + return nil, r.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot index send schedules for user [%s]", userID)) + } + + return items, nil +} + +// Delete removes a message send schedule owned by the given user. +func (r *gormMessageSendScheduleRepository) Delete( + ctx context.Context, + userID entities.UserID, + scheduleID uuid.UUID, +) error { + ctx, span := r.tracer.Start(ctx) + defer span.End() + + err := r.db.WithContext(ctx). + Where("user_id = ?", userID). + Where("id = ?", scheduleID). + Delete(&entities.MessageSendSchedule{}).Error + if err != nil { + return r.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot delete send schedule [%s]", scheduleID)) + } + + return nil +} + +// DeleteAllForUser removes all message send schedules owned by the given user. +func (r *gormMessageSendScheduleRepository) DeleteAllForUser( + ctx context.Context, + userID entities.UserID, +) error { + ctx, span := r.tracer.Start(ctx) + defer span.End() + + err := r.db.WithContext(ctx). + Where("user_id = ?", userID). + Delete(&entities.MessageSendSchedule{}).Error + if err != nil { + return r.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot delete send schedules for user [%s]", userID)) + } + + return nil +} + +// CountByUser returns the number of schedules owned by a user. +func (r *gormMessageSendScheduleRepository) CountByUser( + ctx context.Context, + userID entities.UserID, +) (int, error) { + ctx, span := r.tracer.Start(ctx) + defer span.End() + + var count int64 + err := r.db.WithContext(ctx). + Model(&entities.MessageSendSchedule{}). + Where("user_id = ?", userID). + Count(&count).Error + if err != nil { + return 0, r.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot count send schedules for user [%s]", userID)) + } + + return int(count), nil +} diff --git a/api/pkg/repositories/gorm_phone_api_key_repository.go b/api/pkg/repositories/gorm_phone_api_key_repository.go index 692616eb..68692a04 100644 --- a/api/pkg/repositories/gorm_phone_api_key_repository.go +++ b/api/pkg/repositories/gorm_phone_api_key_repository.go @@ -10,7 +10,7 @@ import ( "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/telemetry" - "github.com/dgraph-io/ristretto" + "github.com/dgraph-io/ristretto/v2" "github.com/google/uuid" "github.com/palantir/stacktrace" "gorm.io/gorm" @@ -61,6 +61,23 @@ WHERE user_id = ? AND array_position(phone_ids, ?) IS NOT NULL; return nil } +// CountByUser returns the number of phone API keys owned by a user. +func (repository *gormPhoneAPIKeyRepository) CountByUser(ctx context.Context, userID entities.UserID) (int, error) { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + var count int64 + err := repository.db.WithContext(ctx). + Model(&entities.PhoneAPIKey{}). + Where("user_id = ?", userID). + Count(&count).Error + if err != nil { + return 0, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot count phone API keys for user [%s]", userID)) + } + + return int(count), nil +} + // Load an entities.PhoneAPIKey based on the entities.UserID func (repository *gormPhoneAPIKeyRepository) Load(ctx context.Context, userID entities.UserID, phoneAPIKeyID uuid.UUID) (*entities.PhoneAPIKey, error) { ctx, span := repository.tracer.Start(ctx) @@ -98,7 +115,6 @@ func (repository *gormPhoneAPIKeyRepository) LoadAuthContext(ctx context.Context defer span.End() if authContext, found := repository.cache.Get(apiKey); found { - ctxLogger.Info(fmt.Sprintf("cache hit for user with ID [%s] and phone API Key ID [%s]", authContext.ID, *authContext.PhoneAPIKeyID)) return authContext, nil } diff --git a/api/pkg/repositories/gorm_phone_notification_repository.go b/api/pkg/repositories/gorm_phone_notification_repository.go index f491e4b3..e1136415 100644 --- a/api/pkg/repositories/gorm_phone_notification_repository.go +++ b/api/pkg/repositories/gorm_phone_notification_repository.go @@ -15,39 +15,70 @@ import ( "gorm.io/gorm" ) -// gormPhoneNotificationRepository is responsible for persisting entities.PhoneNotification +// gormPhoneNotificationRepository persists entities.PhoneNotification records. type gormPhoneNotificationRepository struct { logger telemetry.Logger tracer telemetry.Tracer db *gorm.DB } -// NewGormPhoneNotificationRepository creates the GORM version of the PhoneNotificationRepository +// NewGormPhoneNotificationRepository creates a GORM-backed PhoneNotificationRepository. func NewGormPhoneNotificationRepository( logger telemetry.Logger, tracer telemetry.Tracer, db *gorm.DB, ) PhoneNotificationRepository { return &gormPhoneNotificationRepository{ - logger: logger.WithService(fmt.Sprintf("%T", &gormHeartbeatRepository{})), + logger: logger.WithService(fmt.Sprintf("%T", &gormPhoneNotificationRepository{})), tracer: tracer, db: db, } } -func (repository *gormPhoneNotificationRepository) DeleteAllForUser(ctx context.Context, userID entities.UserID) error { +// DeleteAllForUser deletes all phone notifications that belong to a user. +func (repository *gormPhoneNotificationRepository) DeleteAllForUser( + ctx context.Context, + userID entities.UserID, +) error { ctx, span := repository.tracer.Start(ctx) defer span.End() - if err := repository.db.WithContext(ctx).Where("user_id = ?", userID).Delete(&entities.PhoneNotification{}).Error; err != nil { - msg := fmt.Sprintf("cannot delete all [%T] for user with ID [%s]", &entities.PhoneNotification{}, userID) - return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + if err := repository.db.WithContext(ctx). + Where("user_id = ?", userID). + Delete(&entities.PhoneNotification{}).Error; err != nil { + return repository.tracer.WrapErrorSpan( + span, + stacktrace.Propagate( + err, + "cannot delete all [%T] for user with ID [%s]", + &entities.PhoneNotification{}, + userID, + ), + ) } return nil } -// UpdateStatus of an entities.PhoneNotification +// DeleteByMessageID deletes all entities.PhoneNotification for a user and message ID. +func (repository *gormPhoneNotificationRepository) DeleteByMessageID(ctx context.Context, userID entities.UserID, messageID uuid.UUID) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + err := repository.db.WithContext(ctx). + Where("user_id = ? AND message_id = ?", userID, messageID). + Delete(&entities.PhoneNotification{}).Error + if err != nil { + msg := fmt.Sprintf("cannot delete [%T] for user [%s] and message with ID [%s]", &entities.PhoneNotification{}, userID, messageID) + return repository.tracer.WrapErrorSpan(span, + stacktrace.Propagate(err, msg), + ) + } + + return nil +} + +// UpdateStatus updates the status of a phone notification. func (repository *gormPhoneNotificationRepository) UpdateStatus(ctx context.Context, notificationID uuid.UUID, status entities.PhoneNotificationStatus) error { ctx, span := repository.tracer.Start(ctx) defer span.End() @@ -58,71 +89,166 @@ func (repository *gormPhoneNotificationRepository) UpdateStatus(ctx context.Cont Update("status", status). Error if err != nil { - msg := fmt.Sprintf("cannot update notification [%s] with status [%s]", notificationID, status) - return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + return repository.tracer.WrapErrorSpan( + span, + stacktrace.Propagate( + err, + "cannot update notification [%s] with status [%s]", + notificationID, + status, + ), + ) } return nil } -// Schedule a notification to be sent in the future -func (repository *gormPhoneNotificationRepository) Schedule(ctx context.Context, messagesPerMinute uint, notification *entities.PhoneNotification) error { - ctx, span := repository.tracer.Start(ctx) +// Schedule stores a phone notification and calculates its final scheduled time. +// The final time is determined by combining: +// 1. the next allowed time from the message send schedule +// 2. the phone send-rate limit derived from the latest scheduled notification +func (repository *gormPhoneNotificationRepository) Schedule( + ctx context.Context, + messagesPerMinute uint, + schedule *entities.MessageSendSchedule, + notification *entities.PhoneNotification, +) error { + ctx, span, _ := repository.tracer.StartWithLogger(ctx, repository.logger) defer span.End() + now := time.Now().UTC() + if messagesPerMinute == 0 { + notification.ScheduledAt = repository.resolveScheduledAt(schedule, now) return repository.insert(ctx, notification) } err := crdbgorm.ExecuteTx(ctx, repository.db, nil, func(tx *gorm.DB) error { lastNotification := new(entities.PhoneNotification) + err := tx.WithContext(ctx). Where("phone_id = ?", notification.PhoneID). Order("scheduled_at desc"). First(lastNotification). Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - msg := fmt.Sprintf("cannot fetch last notification with phone ID [%s]", notification.PhoneID) - return stacktrace.Propagate(err, msg) + return stacktrace.Propagate( + err, + "cannot fetch last notification with phone ID [%s]", + notification.PhoneID, + ) } - notification.ScheduledAt = time.Now().UTC() + notification.ScheduledAt = repository.resolveScheduledAt(schedule, now) + if err == nil { - notification.ScheduledAt = repository.maxTime( - time.Now().UTC(), - lastNotification.ScheduledAt.Add(time.Duration(60/messagesPerMinute)*time.Second), + rateLimitedAt := lastNotification.ScheduledAt.Add( + time.Duration(60/messagesPerMinute) * time.Second, ) + + nextCandidate := repository.maxTime(notification.ScheduledAt, rateLimitedAt) + notification.ScheduledAt = repository.resolveScheduledAt(schedule, nextCandidate) } if err = tx.WithContext(ctx).Create(notification).Error; err != nil { - msg := fmt.Sprintf("cannot create new notification with id [%s] and schedule [%s]", notification.ID, notification.ScheduledAt.String()) - return stacktrace.Propagate(err, msg) + return stacktrace.Propagate( + err, + "cannot create new notification with id [%s] and schedule [%s]", + notification.ID, + notification.ScheduledAt.String(), + ) } + return nil }) if err != nil { - msg := fmt.Sprintf("cannot schedule phone notification with ID [%s]", notification.ID) - return stacktrace.Propagate(err, msg) + return repository.tracer.WrapErrorSpan( + span, + stacktrace.Propagate( + err, + "cannot schedule phone notification with ID [%s]", + notification.ID, + ), + ) } return nil } +// resolveScheduledAt returns the next time the notification is allowed to be sent. +// If no schedule is attached, the provided time is returned unchanged in UTC. +func (repository *gormPhoneNotificationRepository) resolveScheduledAt( + schedule *entities.MessageSendSchedule, + current time.Time, +) time.Time { + if schedule == nil { + return current.UTC() + } + + return schedule.ResolveScheduledAt(current) +} + +// maxTime returns the greater of the two time.Time. func (repository *gormPhoneNotificationRepository) maxTime(a, b time.Time) time.Time { - if a.Unix() > b.Unix() { + if a.After(b) { return a } return b } -func (repository *gormPhoneNotificationRepository) insert(ctx context.Context, notification *entities.PhoneNotification) error { +// insert stores a single phone notification. +func (repository *gormPhoneNotificationRepository) insert( + ctx context.Context, + notification *entities.PhoneNotification, +) error { ctx, span := repository.tracer.Start(ctx) defer span.End() - err := repository.db.WithContext(ctx).Create(notification).Error - if err != nil { - msg := fmt.Sprintf("cannot store notification with id [%s]", notification.ID) - return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + if err := repository.db.WithContext(ctx).Create(notification).Error; err != nil { + return repository.tracer.WrapErrorSpan( + span, + stacktrace.Propagate( + err, + "cannot store notification with id [%s]", + notification.ID, + ), + ) + } + + return nil +} + +// ScheduleExact stores a phone notification with an exact ScheduledAt time. +// It performs a dedupe check — if a pending notification for the same message already exists, it's a no-op. +func (repository *gormPhoneNotificationRepository) ScheduleExact( + ctx context.Context, + notification *entities.PhoneNotification, +) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + // Dedupe: check if a pending notification for this message already exists + var count int64 + if err := repository.db.WithContext(ctx). + Model(&entities.PhoneNotification{}). + Where("message_id = ? AND status = ?", notification.MessageID, entities.PhoneNotificationStatusPending). + Count(&count).Error; err != nil { + return repository.tracer.WrapErrorSpan( + span, + stacktrace.Propagate(err, "cannot check for existing notification for message [%s]", notification.MessageID), + ) } + + if count > 0 { + return nil + } + + if err := repository.db.WithContext(ctx).Create(notification).Error; err != nil { + return repository.tracer.WrapErrorSpan( + span, + stacktrace.Propagate(err, "cannot create exact-time notification with id [%s]", notification.ID), + ) + } + return nil } diff --git a/api/pkg/repositories/gorm_phone_repository.go b/api/pkg/repositories/gorm_phone_repository.go index b45f7cff..a1f79ba8 100644 --- a/api/pkg/repositories/gorm_phone_repository.go +++ b/api/pkg/repositories/gorm_phone_repository.go @@ -4,9 +4,11 @@ import ( "context" "errors" "fmt" + "time" "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/dgraph-io/ristretto/v2" "github.com/google/uuid" "github.com/palantir/stacktrace" "gorm.io/gorm" @@ -16,6 +18,7 @@ import ( type gormPhoneRepository struct { logger telemetry.Logger tracer telemetry.Tracer + cache *ristretto.Cache[string, *entities.Phone] db *gorm.DB } @@ -24,11 +27,13 @@ func NewGormPhoneRepository( logger telemetry.Logger, tracer telemetry.Tracer, db *gorm.DB, + cache *ristretto.Cache[string, *entities.Phone], ) PhoneRepository { return &gormPhoneRepository{ logger: logger.WithService(fmt.Sprintf("%T", &gormPhoneRepository{})), tracer: tracer, db: db, + cache: cache, } } @@ -41,6 +46,26 @@ func (repository *gormPhoneRepository) DeleteAllForUser(ctx context.Context, use return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } + repository.cache.Clear() + return nil +} + +// NullifyScheduleID sets MessageSendScheduleID to NULL for all phones referencing the given schedule +func (repository *gormPhoneRepository) NullifyScheduleID(ctx context.Context, userID entities.UserID, scheduleID uuid.UUID) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + err := repository.db.WithContext(ctx). + Model(&entities.Phone{}). + Where("user_id = ?", userID). + Where("message_send_schedule_id = ?", scheduleID). + Update("message_send_schedule_id", nil).Error + if err != nil { + msg := fmt.Sprintf("cannot nullify message_send_schedule_id [%s] for user [%s]", scheduleID, userID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + repository.cache.Clear() return nil } @@ -81,6 +106,7 @@ func (repository *gormPhoneRepository) Delete(ctx context.Context, userID entiti return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } + repository.cache.Clear() return nil } @@ -106,14 +132,19 @@ func (repository *gormPhoneRepository) Save(ctx context.Context, phone *entities return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } + repository.cache.Del(repository.getCacheKey(phone.UserID, phone.PhoneNumber)) return nil } // Load a phone based on entities.UserID and phoneNumber func (repository *gormPhoneRepository) Load(ctx context.Context, userID entities.UserID, phoneNumber string) (*entities.Phone, error) { - ctx, span := repository.tracer.Start(ctx) + ctx, span, ctxLogger := repository.tracer.StartWithLogger(ctx, repository.logger) defer span.End() + if phone, found := repository.cache.Get(repository.getCacheKey(userID, phoneNumber)); found { + return phone, nil + } + phone := new(entities.Phone) err := repository.db.WithContext(ctx).Where("user_id = ?", userID).Where("phone_number = ?", phoneNumber).First(phone).Error if errors.Is(err, gorm.ErrRecordNotFound) { @@ -126,6 +157,11 @@ func (repository *gormPhoneRepository) Load(ctx context.Context, userID entities return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } + if result := repository.cache.SetWithTTL(repository.getCacheKey(userID, phoneNumber), phone, 1, 30*time.Minute); !result { + msg := fmt.Sprintf("cannot cache [%T] with ID [%s] and result [%t]", phone, phone.ID, result) + ctxLogger.Error(repository.tracer.WrapErrorSpan(span, stacktrace.NewError(msg))) + } + return phone, nil } @@ -147,3 +183,7 @@ func (repository *gormPhoneRepository) Index(ctx context.Context, userID entitie return phones, nil } + +func (repository *gormPhoneRepository) getCacheKey(userID entities.UserID, phoneNumber string) string { + return fmt.Sprintf("user:%s:phone:%s", userID, phoneNumber) +} diff --git a/api/pkg/repositories/gorm_user_repository.go b/api/pkg/repositories/gorm_user_repository.go index c8888399..a64e8ae0 100644 --- a/api/pkg/repositories/gorm_user_repository.go +++ b/api/pkg/repositories/gorm_user_repository.go @@ -11,7 +11,7 @@ import ( "gorm.io/gorm/clause" "github.com/cockroachdb/cockroach-go/v2/crdb/crdbgorm" - "github.com/dgraph-io/ristretto" + "github.com/dgraph-io/ristretto/v2" "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/telemetry" @@ -65,8 +65,13 @@ func (repository *gormUserRepository) RotateAPIKey(ctx context.Context, userID e } user := new(entities.User) + var oldAPIKey string err = crdbgorm.ExecuteTx(ctx, repository.db, nil, func(tx *gorm.DB) error { + if err := tx.WithContext(ctx).Where("id = ?", userID).First(user).Error; err != nil { + return err + } + oldAPIKey = user.APIKey return tx.WithContext(ctx).Model(user). Clauses(clause.Returning{}). Where("id = ?", userID). @@ -78,6 +83,13 @@ func (repository *gormUserRepository) RotateAPIKey(ctx context.Context, userID e return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg)) } + if err == nil && oldAPIKey != "" { + // Flush pending ristretto Set operations before Del to avoid a + // buffered Set re-adding the entry after removal. + repository.cache.Wait() + repository.cache.Del(oldAPIKey) + } + return user, nil } @@ -154,13 +166,16 @@ func (repository *gormUserRepository) LoadAuthContext(ctx context.Context, apiKe defer span.End() if authUser, found := repository.cache.Get(apiKey); found { - ctxLogger.Info(fmt.Sprintf("cache hit for user with ID [%s]", authUser.ID)) + if authUser.IsNoop() { + return authUser, repository.tracer.WrapErrorSpan(span, stacktrace.NewError(fmt.Sprintf("user with api key [%s] does not exist", apiKey))) + } return authUser, nil } user := new(entities.User) err := repository.db.WithContext(ctx).Where("api_key = ?", apiKey).First(user).Error if errors.Is(err, gorm.ErrRecordNotFound) { + repository.cache.SetWithTTL(apiKey, entities.AuthContext{}, 1, 2*time.Hour) msg := fmt.Sprintf("user with api key [%s] does not exist", apiKey) return entities.AuthContext{}, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg)) } diff --git a/api/pkg/repositories/memory_attachment_repository.go b/api/pkg/repositories/memory_attachment_repository.go new file mode 100644 index 00000000..65eadf2f --- /dev/null +++ b/api/pkg/repositories/memory_attachment_repository.go @@ -0,0 +1,60 @@ +package repositories + +import ( + "context" + "fmt" + "sync" + + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/palantir/stacktrace" +) + +// MemoryAttachmentRepository stores attachments in memory +type MemoryAttachmentRepository struct { + logger telemetry.Logger + tracer telemetry.Tracer + data sync.Map +} + +// NewMemoryAttachmentRepository creates a new MemoryAttachmentRepository +func NewMemoryAttachmentRepository( + logger telemetry.Logger, + tracer telemetry.Tracer, +) *MemoryAttachmentRepository { + return &MemoryAttachmentRepository{ + logger: logger.WithService(fmt.Sprintf("%T", &MemoryAttachmentRepository{})), + tracer: tracer, + } +} + +// Upload stores attachment data at the given path +func (s *MemoryAttachmentRepository) Upload(ctx context.Context, path string, data []byte, _ string) error { + _, span, ctxLogger := s.tracer.StartWithLogger(ctx, s.logger) + defer span.End() + + s.data.Store(path, data) + ctxLogger.Info(fmt.Sprintf("stored attachment at path [%s] with size [%d]", path, len(data))) + return nil +} + +// Download retrieves attachment data from the given path +func (s *MemoryAttachmentRepository) Download(ctx context.Context, path string) ([]byte, error) { + _, span, _ := s.tracer.StartWithLogger(ctx, s.logger) + defer span.End() + + value, ok := s.data.Load(path) + if !ok { + return nil, s.tracer.WrapErrorSpan(span, stacktrace.NewErrorWithCode(ErrCodeNotFound, fmt.Sprintf("attachment not found at path [%s]", path))) + } + return value.([]byte), nil +} + +// Delete removes an attachment at the given path +func (s *MemoryAttachmentRepository) Delete(ctx context.Context, path string) error { + _, span, ctxLogger := s.tracer.StartWithLogger(ctx, s.logger) + defer span.End() + + s.data.Delete(path) + ctxLogger.Info(fmt.Sprintf("deleted attachment at path [%s]", path)) + return nil +} diff --git a/api/pkg/repositories/message_repository.go b/api/pkg/repositories/message_repository.go index 3ad70015..c8f85fbb 100644 --- a/api/pkg/repositories/message_repository.go +++ b/api/pkg/repositories/message_repository.go @@ -27,6 +27,9 @@ type MessageRepository interface { // Search entities.Message for a user Search(ctx context.Context, userID entities.UserID, owners []string, types []entities.MessageType, statuses []entities.MessageStatus, params IndexParams) ([]*entities.Message, error) + // GetBulkMessages fetches the last bulk message summaries for a user + GetBulkMessages(ctx context.Context, userID entities.UserID, limit int) ([]*entities.BulkMessage, error) + // GetOutstanding fetches an entities.Message which is outstanding GetOutstanding(ctx context.Context, userID entities.UserID, messageID uuid.UUID, phoneNumbers []string) (*entities.Message, error) diff --git a/api/pkg/repositories/message_send_schedule_repository.go b/api/pkg/repositories/message_send_schedule_repository.go new file mode 100644 index 00000000..82ef4518 --- /dev/null +++ b/api/pkg/repositories/message_send_schedule_repository.go @@ -0,0 +1,32 @@ +package repositories + +import ( + "context" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/google/uuid" +) + +// MessageSendScheduleRepository loads and persists entities.MessageSendSchedule. +type MessageSendScheduleRepository interface { + // Store persists a new message send schedule. + Store(ctx context.Context, schedule *entities.MessageSendSchedule) error + + // Update persists changes to an existing message send schedule. + Update(ctx context.Context, schedule *entities.MessageSendSchedule) error + + // Load returns a message send schedule by user ID and schedule ID. + Load(ctx context.Context, userID entities.UserID, scheduleID uuid.UUID) (*entities.MessageSendSchedule, error) + + // Index returns all message send schedules owned by a user. + Index(ctx context.Context, userID entities.UserID) ([]entities.MessageSendSchedule, error) + + // Delete removes a message send schedule owned by a user. + Delete(ctx context.Context, userID entities.UserID, scheduleID uuid.UUID) error + + // DeleteAllForUser removes all message send schedules owned by a user. + DeleteAllForUser(ctx context.Context, userID entities.UserID) error + + // CountByUser returns the number of schedules owned by a user. + CountByUser(ctx context.Context, userID entities.UserID) (int, error) +} diff --git a/api/pkg/repositories/mongo_heartbeat_monitor_repository.go b/api/pkg/repositories/mongo_heartbeat_monitor_repository.go new file mode 100644 index 00000000..13200c07 --- /dev/null +++ b/api/pkg/repositories/mongo_heartbeat_monitor_repository.go @@ -0,0 +1,182 @@ +package repositories + +import ( + "context" + "fmt" + "time" + + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/palantir/stacktrace" +) + +// mongoHeartbeatMonitorRepository is responsible for persisting entities.HeartbeatMonitor in MongoDB +type mongoHeartbeatMonitorRepository struct { + logger telemetry.Logger + tracer telemetry.Tracer + collection *mongo.Collection +} + +// NewMongoHeartbeatMonitorRepository creates the MongoDB version of the HeartbeatMonitorRepository +func NewMongoHeartbeatMonitorRepository( + logger telemetry.Logger, + tracer telemetry.Tracer, + db *mongo.Database, +) HeartbeatMonitorRepository { + return &mongoHeartbeatMonitorRepository{ + logger: logger.WithService(fmt.Sprintf("%T", &mongoHeartbeatMonitorRepository{})), + tracer: tracer, + collection: db.Collection(collectionHeartbeatMonitors), + } +} + +func (repository *mongoHeartbeatMonitorRepository) Store(ctx context.Context, monitor *entities.HeartbeatMonitor) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + _, err := repository.collection.InsertOne(ctx, monitor) + if err != nil { + msg := fmt.Sprintf("cannot save heartbeat monitor with ID [%s]", monitor.ID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + +func (repository *mongoHeartbeatMonitorRepository) Load(ctx context.Context, userID entities.UserID, phoneNumber string) (*entities.HeartbeatMonitor, error) { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + filter := bson.D{ + {"user_id", string(userID)}, + {"owner", phoneNumber}, + } + + var monitor entities.HeartbeatMonitor + err := repository.collection.FindOne(ctx, filter).Decode(&monitor) + if err == mongo.ErrNoDocuments { + msg := fmt.Sprintf("heartbeat monitor with userID [%s] and owner [%s] does not exist", userID, phoneNumber) + return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg)) + } + if err != nil { + msg := fmt.Sprintf("cannot load heartbeat monitor with userID [%s] and owner [%s]", userID, phoneNumber) + return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return &monitor, nil +} + +func (repository *mongoHeartbeatMonitorRepository) Exists(ctx context.Context, userID entities.UserID, monitorID uuid.UUID) (bool, error) { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + filter := bson.D{ + {"user_id", string(userID)}, + {"_id", monitorID.String()}, + } + + count, err := repository.collection.CountDocuments(ctx, filter) + if err != nil { + msg := fmt.Sprintf("cannot check if heartbeat monitor exists with userID [%s] and monitor ID [%s]", userID, monitorID) + return false, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return count > 0, nil +} + +func (repository *mongoHeartbeatMonitorRepository) UpdateQueueID(ctx context.Context, monitorID uuid.UUID, queueID string) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + filter := bson.D{{"_id", monitorID.String()}} + update := bson.D{{"$set", bson.D{ + {"queue_id", queueID}, + {"updated_at", time.Now().UTC()}, + }}} + + _, err := repository.collection.UpdateOne(ctx, filter, update) + if err != nil { + msg := fmt.Sprintf("cannot update heartbeat monitor ID [%s]", monitorID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + +func (repository *mongoHeartbeatMonitorRepository) Delete(ctx context.Context, userID entities.UserID, phoneNumber string) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + filter := bson.D{ + {"user_id", string(userID)}, + {"owner", phoneNumber}, + } + + _, err := repository.collection.DeleteMany(ctx, filter) + if err != nil { + msg := fmt.Sprintf("cannot delete heartbeat monitor with owner [%s] and userID [%s]", phoneNumber, userID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + +func (repository *mongoHeartbeatMonitorRepository) UpdatePhoneOnline(ctx context.Context, userID entities.UserID, monitorID uuid.UUID, online bool) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + filter := bson.D{ + {"_id", monitorID.String()}, + {"user_id", string(userID)}, + } + update := bson.D{{"$set", bson.D{ + {"phone_online", online}, + {"updated_at", time.Now().UTC()}, + }}} + + _, err := repository.collection.UpdateOne(ctx, filter, update) + if err != nil { + msg := fmt.Sprintf("cannot update heartbeat monitor ID [%s] for user [%s]", monitorID, userID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + +func (repository *mongoHeartbeatMonitorRepository) DeleteAllForUser(ctx context.Context, userID entities.UserID) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + _, err := repository.collection.DeleteMany(ctx, bson.D{{"user_id", string(userID)}}) + if err != nil { + msg := fmt.Sprintf("cannot delete all [%T] for user with ID [%s]", &entities.HeartbeatMonitor{}, userID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} diff --git a/api/pkg/repositories/mongo_heartbeat_repository.go b/api/pkg/repositories/mongo_heartbeat_repository.go new file mode 100644 index 00000000..d8a7839c --- /dev/null +++ b/api/pkg/repositories/mongo_heartbeat_repository.go @@ -0,0 +1,135 @@ +package repositories + +import ( + "context" + "fmt" + + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/palantir/stacktrace" +) + +// mongoHeartbeatRepository is responsible for persisting entities.Heartbeat in MongoDB +type mongoHeartbeatRepository struct { + logger telemetry.Logger + tracer telemetry.Tracer + collection *mongo.Collection +} + +// NewMongoHeartbeatRepository creates the MongoDB version of the HeartbeatRepository +func NewMongoHeartbeatRepository( + logger telemetry.Logger, + tracer telemetry.Tracer, + db *mongo.Database, +) HeartbeatRepository { + return &mongoHeartbeatRepository{ + logger: logger.WithService(fmt.Sprintf("%T", &mongoHeartbeatRepository{})), + tracer: tracer, + collection: db.Collection(collectionHeartbeats), + } +} + +func (repository *mongoHeartbeatRepository) Store(ctx context.Context, heartbeat *entities.Heartbeat) error { + ctx, span, _ := repository.tracer.StartWithLogger(ctx, repository.logger) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + _, err := repository.collection.InsertOne(ctx, heartbeat) + if err != nil { + msg := fmt.Sprintf("cannot save heartbeat with ID [%s]", heartbeat.ID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + +func (repository *mongoHeartbeatRepository) Index(ctx context.Context, userID entities.UserID, owner string, params IndexParams) (*[]entities.Heartbeat, error) { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + filter := bson.D{ + {"user_id", string(userID)}, + {"owner", owner}, + } + + if len(params.Query) > 0 { + filter = append(filter, bson.E{"version", bson.D{{"$regex", params.Query}, {"$options", "i"}}}) + } + + opts := options.Find(). + SetSort(bson.D{{"timestamp", -1}}). + SetSkip(int64(params.Skip)). + SetLimit(int64(params.Limit)) + + cursor, err := repository.collection.Find(ctx, filter, opts) + if err != nil { + msg := fmt.Sprintf("cannot fetch heartbeats with owner [%s] and params [%+#v]", owner, params) + return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + defer cursor.Close(ctx) + + var heartbeats []entities.Heartbeat + if err = cursor.All(ctx, &heartbeats); err != nil { + msg := fmt.Sprintf("cannot decode heartbeats for owner [%s]", owner) + return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if heartbeats == nil { + heartbeats = make([]entities.Heartbeat, 0) + } + + return &heartbeats, nil +} + +func (repository *mongoHeartbeatRepository) Last(ctx context.Context, userID entities.UserID, owner string) (*entities.Heartbeat, error) { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + filter := bson.D{ + {"user_id", string(userID)}, + {"owner", owner}, + } + + opts := options.FindOne().SetSort(bson.D{{"timestamp", -1}}) + + var heartbeat entities.Heartbeat + err := repository.collection.FindOne(ctx, filter, opts).Decode(&heartbeat) + if err == mongo.ErrNoDocuments { + msg := fmt.Sprintf("heartbeat with userID [%s] and owner [%s] does not exist", userID, owner) + return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg)) + } + if err != nil { + msg := fmt.Sprintf("cannot load heartbeat with userID [%s] and owner [%s]", userID, owner) + return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return &heartbeat, nil +} + +func (repository *mongoHeartbeatRepository) DeleteAllForUser(ctx context.Context, userID entities.UserID) error { + ctx, span := repository.tracer.Start(ctx) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, dbOperationDuration) + defer cancel() + + _, err := repository.collection.DeleteMany(ctx, bson.D{{"user_id", string(userID)}}) + if err != nil { + msg := fmt.Sprintf("cannot delete all [%T] for user with ID [%s]", &entities.Heartbeat{}, userID) + return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} diff --git a/api/pkg/repositories/mongodb.go b/api/pkg/repositories/mongodb.go new file mode 100644 index 00000000..f76f97bc --- /dev/null +++ b/api/pkg/repositories/mongodb.go @@ -0,0 +1,127 @@ +package repositories + +import ( + "context" + "fmt" + "net/url" + "reflect" + "time" + + "github.com/google/uuid" + "github.com/palantir/stacktrace" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" + "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo" +) + +const ( + collectionHeartbeats = "heartbeats" + collectionHeartbeatMonitors = "heartbeat_monitors" +) + +// uuidEncodeValue encodes uuid.UUID as a BSON string +func uuidEncodeValue(_ bson.EncodeContext, vw bson.ValueWriter, val reflect.Value) error { + u := val.Interface().(uuid.UUID) + return vw.WriteString(u.String()) +} + +// uuidDecodeValue decodes a BSON string into uuid.UUID +func uuidDecodeValue(_ bson.DecodeContext, vr bson.ValueReader, val reflect.Value) error { + str, err := vr.ReadString() + if err != nil { + return err + } + parsed, err := uuid.Parse(str) + if err != nil { + return err + } + val.Set(reflect.ValueOf(parsed)) + return nil +} + +// newMongoRegistry creates a BSON registry that encodes uuid.UUID as strings +func newMongoRegistry() *bson.Registry { + rb := bson.NewRegistry() + rb.RegisterTypeEncoder(reflect.TypeOf(uuid.UUID{}), bson.ValueEncoderFunc(uuidEncodeValue)) + rb.RegisterTypeDecoder(reflect.TypeOf(uuid.UUID{}), bson.ValueDecoderFunc(uuidDecodeValue)) + return rb +} + +// NewMongoDB creates a new *mongo.Database connection to MongoDB Atlas and ensures indexes. +// The database name is derived from the appName query parameter in the URI. +func NewMongoDB(uri string) (*mongo.Database, error) { + dbName, err := parseMongoDBName(uri) + if err != nil { + return nil, stacktrace.Propagate(err, "cannot parse database name from MongoDB URI") + } + + pingCtx, pingCancel := context.WithTimeout(context.Background(), 10*time.Second) + defer pingCancel() + + serverAPI := options.ServerAPI(options.ServerAPIVersion1) + registry := newMongoRegistry() + opts := options.Client(). + ApplyURI(uri). + SetServerAPIOptions(serverAPI). + SetRegistry(registry). + SetMonitor(otelmongo.NewMonitor()) + + client, err := mongo.Connect(opts) + if err != nil { + return nil, stacktrace.Propagate(err, "cannot connect to MongoDB Atlas") + } + + if err = client.Ping(pingCtx, nil); err != nil { + return nil, stacktrace.Propagate(err, "cannot ping MongoDB Atlas") + } + + db := client.Database(dbName) + + indexCtx, indexCancel := context.WithTimeout(context.Background(), 30*time.Second) + defer indexCancel() + + if err = createMongoIndexes(indexCtx, db); err != nil { + return nil, stacktrace.Propagate(err, "cannot create MongoDB indexes") + } + + return db, nil +} + +// parseMongoDBName extracts the appName query parameter from the MongoDB URI to use as the database name +func parseMongoDBName(uri string) (string, error) { + parsed, err := url.Parse(uri) + if err != nil { + return "", stacktrace.Propagate(err, fmt.Sprintf("cannot parse MongoDB URI [%s]", uri)) + } + + appName := parsed.Query().Get("appName") + if appName == "" { + return "", stacktrace.NewError("MongoDB URI is missing the 'appName' query parameter which is used as the database name") + } + + return appName, nil +} + +func createMongoIndexes(ctx context.Context, db *mongo.Database) error { + // Heartbeats indexes + heartbeatsCol := db.Collection(collectionHeartbeats) + + _, err := heartbeatsCol.Indexes().CreateMany(ctx, []mongo.IndexModel{ + {Keys: bson.D{{"user_id", 1}, {"owner", 1}, {"timestamp", -1}}}, + }) + if err != nil { + return stacktrace.Propagate(err, "cannot create indexes on heartbeats collection") + } + + // Heartbeat monitors indexes + monitorsCol := db.Collection(collectionHeartbeatMonitors) + _, err = monitorsCol.Indexes().CreateMany(ctx, []mongo.IndexModel{ + {Keys: bson.D{{"user_id", 1}, {"owner", 1}}}, + }) + if err != nil { + return stacktrace.Propagate(err, "cannot create indexes on heartbeat_monitors collection") + } + + return nil +} diff --git a/api/pkg/repositories/phone_api_key_repository.go b/api/pkg/repositories/phone_api_key_repository.go index 8894e4ac..ceecda85 100644 --- a/api/pkg/repositories/phone_api_key_repository.go +++ b/api/pkg/repositories/phone_api_key_repository.go @@ -31,6 +31,9 @@ type PhoneAPIKeyRepository interface { // RemovePhone removes an entities.Phone to an entities.PhoneAPIKey RemovePhone(ctx context.Context, phoneAPIKey *entities.PhoneAPIKey, phone *entities.Phone) error + // CountByUser returns the number of phone API keys owned by a user + CountByUser(ctx context.Context, userID entities.UserID) (int, error) + // DeleteAllForUser deletes all entities.PhoneAPIKey for a user DeleteAllForUser(ctx context.Context, userID entities.UserID) error diff --git a/api/pkg/repositories/phone_notification_repository.go b/api/pkg/repositories/phone_notification_repository.go index 87f78490..2abc67f9 100644 --- a/api/pkg/repositories/phone_notification_repository.go +++ b/api/pkg/repositories/phone_notification_repository.go @@ -11,11 +11,18 @@ import ( // PhoneNotificationRepository loads and persists an entities.PhoneNotification type PhoneNotificationRepository interface { // Schedule a new entities.PhoneNotification - Schedule(ctx context.Context, messagesPerMinute uint, notification *entities.PhoneNotification) error + Schedule(ctx context.Context, messagesPerMinute uint, schedule *entities.MessageSendSchedule, notification *entities.PhoneNotification) error + + // ScheduleExact stores a phone notification with a fixed ScheduledAt time, + // bypassing rate-limit and schedule window logic. + ScheduleExact(ctx context.Context, notification *entities.PhoneNotification) error // UpdateStatus of a notification UpdateStatus(ctx context.Context, notificationID uuid.UUID, status entities.PhoneNotificationStatus) error // DeleteAllForUser deletes all entities.PhoneNotification for a user DeleteAllForUser(ctx context.Context, userID entities.UserID) error + + // DeleteByMessageID deletes entities.PhoneNotification for a message and user + DeleteByMessageID(ctx context.Context, userID entities.UserID, messageID uuid.UUID) error } diff --git a/api/pkg/repositories/phone_repository.go b/api/pkg/repositories/phone_repository.go index c9e82b98..2c184963 100644 --- a/api/pkg/repositories/phone_repository.go +++ b/api/pkg/repositories/phone_repository.go @@ -25,6 +25,9 @@ type PhoneRepository interface { // Delete an entities.Phone Delete(ctx context.Context, userID entities.UserID, phoneID uuid.UUID) error + // NullifyScheduleID sets MessageSendScheduleID to NULL for all phones referencing the given schedule + NullifyScheduleID(ctx context.Context, userID entities.UserID, scheduleID uuid.UUID) error + // DeleteAllForUser deletes all entities.Phone for a user DeleteAllForUser(ctx context.Context, userID entities.UserID) error } diff --git a/api/pkg/requests/bulk_message_request.go b/api/pkg/requests/bulk_message_request.go index ffb3f35c..345e24aa 100644 --- a/api/pkg/requests/bulk_message_request.go +++ b/api/pkg/requests/bulk_message_request.go @@ -1,23 +1,57 @@ package requests import ( - "fmt" "strings" "time" "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/services" - "github.com/google/uuid" "github.com/nyaruka/phonenumbers" ) // BulkMessage represents a single message in a bulk SMS request type BulkMessage struct { request - FromPhoneNumber string `csv:"FromPhoneNumber"` - ToPhoneNumber string `csv:"ToPhoneNumber"` - Content string `csv:"Content"` - SendTime *time.Time `csv:"SendTime(optional)"` + FileType string `json:"type"` + FromPhoneNumber string `csv:"FromPhoneNumber"` + ToPhoneNumber string `csv:"ToPhoneNumber"` + Content string `csv:"Content"` + SendTime string `csv:"SendTime(optional)"` + AttachmentURLs string `csv:"AttachmentURLs(optional)" validate:"optional"` // Comma separated list of URLs +} + +// GetSendTime parses the raw SendTime string into a *time.Time. +// For timezone-naive formats, the time is interpreted in the given location. +// For RFC3339 (which includes an offset), the embedded offset is used. +func (input *BulkMessage) GetSendTime(location *time.Location) *time.Time { + raw := strings.TrimSpace(input.SendTime) + if raw == "" { + return nil + } + + if location == nil { + location = time.UTC + } + + // RFC3339 already contains timezone offset, parse without location + if t, err := time.Parse(time.RFC3339, raw); err == nil { + utc := t.UTC() + return &utc + } + + // Naive formats: interpret in the user's location + naiveFormats := []string{ + "2006-01-02T15:04:05", + "2006-01-02 15:04:05", + } + + for _, format := range naiveFormats { + if t, err := time.ParseInLocation(format, raw, location); err == nil { + utc := t.UTC() + return &utc + } + } + return nil } // Sanitize sets defaults to BulkMessage @@ -25,20 +59,31 @@ func (input *BulkMessage) Sanitize() *BulkMessage { input.ToPhoneNumber = input.sanitizeAddress(input.ToPhoneNumber) input.Content = strings.TrimSpace(input.Content) input.FromPhoneNumber = input.sanitizeAddress(input.FromPhoneNumber) + + var attachments []string + for _, attachment := range strings.Split(input.AttachmentURLs, ",") { + if strings.TrimSpace(attachment) != "" { + attachments = append(attachments, strings.TrimSpace(attachment)) + } + } + input.AttachmentURLs = strings.Join(attachments, ",") return input } // ToMessageSendParams converts BulkMessage to services.MessageSendParams -func (input *BulkMessage) ToMessageSendParams(userID entities.UserID, requestID uuid.UUID, source string) services.MessageSendParams { +func (input *BulkMessage) ToMessageSendParams(userID entities.UserID, requestID string, source string, index int, location *time.Location) services.MessageSendParams { from, _ := phonenumbers.Parse(input.FromPhoneNumber, phonenumbers.UNKNOWN_REGION) + return services.MessageSendParams{ Source: source, Owner: from, - RequestID: input.sanitizeStringPointer(fmt.Sprintf("bulk-%s", requestID.String())), + RequestID: input.sanitizeStringPointer(requestID), UserID: userID, - SendAt: input.SendTime, + SendAt: input.GetSendTime(location), RequestReceivedAt: time.Now().UTC(), Contact: input.sanitizeAddress(input.ToPhoneNumber), Content: input.Content, + Attachments: input.removeEmptyStrings(strings.Split(input.AttachmentURLs, ",")), + Index: index, } } diff --git a/api/pkg/requests/message_bulk_send_request.go b/api/pkg/requests/message_bulk_send_request.go index a21570bb..8c7d8025 100644 --- a/api/pkg/requests/message_bulk_send_request.go +++ b/api/pkg/requests/message_bulk_send_request.go @@ -1,6 +1,7 @@ package requests import ( + "strings" "time" "github.com/NdoleStudio/httpsms/pkg/entities" @@ -17,8 +18,11 @@ type MessageBulkSend struct { To []string `json:"to" example:"+18005550100,+18005550100"` Content string `json:"content" example:"This is a sample text message"` + // Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS + Attachments []string `json:"attachments" validate:"optional"` + // Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app - Encrypted bool `json:"encrypted" example:"false"` + Encrypted bool `json:"encrypted" example:"false" validate:"optional"` // RequestID is an optional parameter used to track a request from the client's perspective RequestID string `json:"request_id" example:"153554b5-ae44-44a0-8f4f-7bbac5657ad4" validate:"optional"` @@ -30,6 +34,15 @@ func (input *MessageBulkSend) Sanitize() MessageBulkSend { for _, address := range input.To { to = append(to, input.sanitizeAddress(address)) } + + var attachments []string + for _, attachment := range input.Attachments { + if strings.TrimSpace(attachment) != "" { + attachments = append(attachments, strings.TrimSpace(attachment)) + } + } + + input.Attachments = attachments input.To = to input.From = input.sanitizeAddress(input.From) return *input @@ -41,7 +54,6 @@ func (input *MessageBulkSend) ToMessageSendParams(userID entities.UserID, source var result []services.MessageSendParams for index, to := range input.To { - sendAt := time.Now().UTC().Add(time.Duration(index) * time.Second) result = append(result, services.MessageSendParams{ Source: source, Owner: from, @@ -50,8 +62,9 @@ func (input *MessageBulkSend) ToMessageSendParams(userID entities.UserID, source UserID: userID, RequestReceivedAt: time.Now().UTC(), Contact: to, - SendAt: &sendAt, Content: input.Content, + Attachments: input.Attachments, + Index: index, }) } diff --git a/api/pkg/requests/message_receive_request.go b/api/pkg/requests/message_receive_request.go index f592761c..b89cddfa 100644 --- a/api/pkg/requests/message_receive_request.go +++ b/api/pkg/requests/message_receive_request.go @@ -11,6 +11,16 @@ import ( "github.com/NdoleStudio/httpsms/pkg/services" ) +// MessageAttachment represents a single MMS attachment in a receive request +type MessageAttachment struct { + // Name is the original filename of the attachment + Name string `json:"name" example:"photo.jpg"` + // ContentType is the MIME type of the attachment + ContentType string `json:"content_type" example:"image/jpeg"` + // Content is the base64-encoded attachment data + Content string `json:"content" example:"base64data..."` +} + // MessageReceive is the payload for sending and SMS message type MessageReceive struct { request @@ -23,6 +33,8 @@ type MessageReceive struct { SIM entities.SIM `json:"sim" example:"SIM1"` // Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"` + // Attachments is the list of MMS attachments received with the message + Attachments []MessageAttachment `json:"attachments" validate:"optional"` } // Sanitize sets defaults to MessageReceive @@ -38,14 +50,25 @@ func (input *MessageReceive) Sanitize() MessageReceive { // ToMessageReceiveParams converts MessageReceive to services.MessageReceiveParams func (input *MessageReceive) ToMessageReceiveParams(userID entities.UserID, source string) *services.MessageReceiveParams { phone, _ := phonenumbers.Parse(input.To, phonenumbers.UNKNOWN_REGION) + + attachments := make([]services.ServiceAttachment, len(input.Attachments)) + for i, a := range input.Attachments { + attachments[i] = services.ServiceAttachment{ + Name: a.Name, + ContentType: a.ContentType, + Content: a.Content, + } + } + return &services.MessageReceiveParams{ - Source: source, - Contact: input.From, - UserID: userID, - Timestamp: input.Timestamp, - Encrypted: input.Encrypted, - Owner: *phone, - Content: input.Content, - SIM: input.SIM, + Source: source, + Contact: input.From, + UserID: userID, + Timestamp: input.Timestamp, + Encrypted: input.Encrypted, + Owner: *phone, + Content: input.Content, + SIM: input.SIM, + Attachments: attachments, } } diff --git a/api/pkg/requests/message_send_request.go b/api/pkg/requests/message_send_request.go index 0285807d..727cc12e 100644 --- a/api/pkg/requests/message_send_request.go +++ b/api/pkg/requests/message_send_request.go @@ -18,12 +18,15 @@ type MessageSend struct { To string `json:"to" example:"+18005550100"` Content string `json:"content" example:"This is a sample text message"` + // Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS + Attachments []string `json:"attachments" validate:"optional" example:"https://example.com/image.jpg,https://example.com/video.mp4"` + // Encrypted is an optional parameter used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app Encrypted bool `json:"encrypted" example:"false" validate:"optional"` // RequestID is an optional parameter used to track a request from the client's perspective RequestID string `json:"request_id" example:"153554b5-ae44-44a0-8f4f-7bbac5657ad4" validate:"optional"` - // SendAt is an optional parameter used to schedule a message to be sent in the future. The time is considered to be in your profile's local timezone. - SendAt *time.Time `json:"send_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"` + // SendAt is an optional parameter used to schedule a message to be sent in the future. The time is considered to be in your profile's local timezone and you can queue messages for up to 20 days (480 hours) in the future. + SendAt *time.Time `json:"send_at" example:"2025-12-19T16:39:57-08:00" validate:"optional"` } // Sanitize sets defaults to MessageReceive @@ -31,6 +34,13 @@ func (input *MessageSend) Sanitize() MessageSend { input.To = input.sanitizeAddress(input.To) input.RequestID = strings.TrimSpace(input.RequestID) input.From = input.sanitizeAddress(input.From) + var attachments []string + for _, attachment := range input.Attachments { + if strings.TrimSpace(attachment) != "" { + attachments = append(attachments, strings.TrimSpace(attachment)) + } + } + input.Attachments = attachments return *input } @@ -47,5 +57,6 @@ func (input *MessageSend) ToMessageSendParams(userID entities.UserID, source str RequestReceivedAt: time.Now().UTC(), Contact: input.sanitizeAddress(input.To), Content: input.Content, + Attachments: input.Attachments, } } diff --git a/api/pkg/requests/message_send_schedule_store_request.go b/api/pkg/requests/message_send_schedule_store_request.go new file mode 100644 index 00000000..bd69fdc9 --- /dev/null +++ b/api/pkg/requests/message_send_schedule_store_request.go @@ -0,0 +1,51 @@ +package requests + +import ( + "sort" + "strings" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/services" +) + +// MessageSendScheduleWindow represents a single request window for a message send schedule. +type MessageSendScheduleWindow struct { + DayOfWeek int `json:"day_of_week"` + StartMinute int `json:"start_minute"` + EndMinute int `json:"end_minute"` +} + +// MessageSendScheduleStore contains the payload used to create or update a message send schedule. +type MessageSendScheduleStore struct { + request + Name string `json:"name"` + Timezone string `json:"timezone"` + Windows []MessageSendScheduleWindow `json:"windows"` +} + +// Sanitize trims and sorts the message send schedule payload before validation. +func (input *MessageSendScheduleStore) Sanitize() MessageSendScheduleStore { + input.Name = strings.TrimSpace(input.Name) + input.Timezone = strings.TrimSpace(input.Timezone) + windows := make([]MessageSendScheduleWindow, 0, len(input.Windows)) + for _, item := range input.Windows { + windows = append(windows, MessageSendScheduleWindow{DayOfWeek: item.DayOfWeek, StartMinute: item.StartMinute, EndMinute: item.EndMinute}) + } + sort.SliceStable(windows, func(i, j int) bool { + if windows[i].DayOfWeek == windows[j].DayOfWeek { + return windows[i].StartMinute < windows[j].StartMinute + } + return windows[i].DayOfWeek < windows[j].DayOfWeek + }) + input.Windows = windows + return *input +} + +// ToParams converts the request payload into message send schedule service params. +func (input *MessageSendScheduleStore) ToParams(user entities.AuthContext) *services.MessageSendScheduleUpsertParams { + windows := make([]entities.MessageSendScheduleWindow, 0, len(input.Windows)) + for _, item := range input.Windows { + windows = append(windows, entities.MessageSendScheduleWindow{DayOfWeek: item.DayOfWeek, StartMinute: item.StartMinute, EndMinute: item.EndMinute}) + } + return &services.MessageSendScheduleUpsertParams{UserID: user.ID, Name: input.Name, Timezone: input.Timezone, Windows: windows} +} diff --git a/api/pkg/requests/phone_update_request.go b/api/pkg/requests/phone_update_request.go index f920fad4..462d6428 100644 --- a/api/pkg/requests/phone_update_request.go +++ b/api/pkg/requests/phone_update_request.go @@ -1,9 +1,12 @@ package requests import ( + "encoding/json" "strings" "time" + "github.com/google/uuid" + "github.com/nyaruka/phonenumbers" "github.com/NdoleStudio/httpsms/pkg/entities" @@ -28,6 +31,8 @@ type PhoneUpsert struct { // SIM is the SIM slot of the phone in case the phone has more than 1 SIM slot SIM string `json:"sim" example:"SIM1"` + + MessageSendScheduleID string `json:"message_send_schedule_id,omitempty" example:"32343a19-da5e-4b1b-a767-3298a73703cb" validate:"optional"` } // Sanitize sets defaults to MessageOutstanding @@ -41,34 +46,42 @@ func (input *PhoneUpsert) Sanitize() PhoneUpsert { return *input } -// ToUpsertParams converts PhoneUpsert to services.PhoneUpsertParams -func (input *PhoneUpsert) ToUpsertParams(user entities.AuthContext, source string) *services.PhoneUpsertParams { +// ToUpsertParams converts PhoneUpsert to services.PhoneUpsertParams. +// The body parameter is the raw JSON request body used to detect which fields were explicitly sent. +func (input *PhoneUpsert) ToUpsertParams(user entities.AuthContext, source string, body []byte) *services.PhoneUpsertParams { phone, _ := phonenumbers.Parse(input.PhoneNumber, phonenumbers.UNKNOWN_REGION) - // ignore value if it's default + fields := make(map[string]json.RawMessage) + _ = json.Unmarshal(body, &fields) + var messagesPerMinute *uint - if input.MessagesPerMinute != 0 { + if _, exists := fields["messages_per_minute"]; exists { messagesPerMinute = &input.MessagesPerMinute } - // ignore default var fcmToken *string - if input.FcmToken != "" { + if _, exists := fields["fcm_token"]; exists { fcmToken = &input.FcmToken } - // ignore default var timeout *time.Duration - if input.MessageExpirationSeconds != 0 { + if _, exists := fields["message_expiration_seconds"]; exists { duration := time.Duration(input.MessageExpirationSeconds) * time.Second timeout = &duration } var maxSendAttempts *uint - if input.MaxSendAttempts != 0 { + if _, exists := fields["max_send_attempts"]; exists { maxSendAttempts = &input.MaxSendAttempts } + var scheduleID *uuid.UUID + if _, exists := fields["message_send_schedule_id"]; exists { + if parsed, err := uuid.Parse(strings.TrimSpace(input.MessageSendScheduleID)); err == nil { + scheduleID = &parsed + } + } + return &services.PhoneUpsertParams{ Source: source, PhoneNumber: phone, @@ -79,5 +92,6 @@ func (input *PhoneUpsert) ToUpsertParams(user entities.AuthContext, source strin FcmToken: fcmToken, UserID: user.ID, SIM: entities.SIM(input.SIM), + MessageSendScheduleID: scheduleID, } } diff --git a/api/pkg/requests/request.go b/api/pkg/requests/request.go index 851137d1..1db27861 100644 --- a/api/pkg/requests/request.go +++ b/api/pkg/requests/request.go @@ -108,6 +108,18 @@ func (input *request) removeStringDuplicates(values []string) []string { return result } +func (input *request) removeEmptyStrings(values []string) []string { + var result []string + for _, value := range values { + value = strings.TrimSpace(value) + if value != "" { + result = append(result, value) + } + } + + return result +} + func (input *request) sanitizeMessageID(value string) string { id := strings.Builder{} for _, char := range value { diff --git a/api/pkg/requests/user_payment_invoice_request.go b/api/pkg/requests/user_payment_invoice_request.go new file mode 100644 index 00000000..4d196f4a --- /dev/null +++ b/api/pkg/requests/user_payment_invoice_request.go @@ -0,0 +1,46 @@ +package requests + +import ( + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/services" +) + +// UserPaymentInvoice is the payload for generating a subscription payment invoice +type UserPaymentInvoice struct { + request + Name string `json:"name" example:"Acme Corp"` + Address string `json:"address" example:"221B Baker Street, London"` + City string `json:"city" example:"Los Angeles"` + State string `json:"state" example:"CA"` + Country string `json:"country" example:"US"` + ZipCode string `json:"zip_code" example:"9800"` + Notes string `json:"notes" example:"Thank you for your business!"` + SubscriptionInvoiceID string `json:"subscriptionInvoiceID" swaggerignore:"true"` // used internally for validation +} + +// Sanitize sets defaults to MessageReceive +func (input *UserPaymentInvoice) Sanitize() UserPaymentInvoice { + input.Name = input.sanitizeAddress(input.Name) + input.Address = input.sanitizeAddress(input.Address) + input.City = input.sanitizeAddress(input.City) + input.State = input.sanitizeAddress(input.State) + input.Country = input.sanitizeAddress(input.Country) + input.ZipCode = input.sanitizeAddress(input.ZipCode) + input.Notes = input.sanitizeAddress(input.Notes) + return *input +} + +// UserInvoiceGenerateParams converts UserPaymentInvoice to services.UserInvoiceGenerateParams +func (input *UserPaymentInvoice) UserInvoiceGenerateParams(userID entities.UserID) *services.UserInvoiceGenerateParams { + return &services.UserInvoiceGenerateParams{ + UserID: userID, + SubscriptionInvoiceID: input.SubscriptionInvoiceID, + Name: input.Name, + Address: input.Address, + City: input.City, + State: input.State, + Country: input.Country, + Notes: input.Notes, + ZipCode: input.ZipCode, + } +} diff --git a/api/pkg/responses/billing_responses.go b/api/pkg/responses/billing_responses.go index bb51d6ab..0ce46415 100644 --- a/api/pkg/responses/billing_responses.go +++ b/api/pkg/responses/billing_responses.go @@ -1,6 +1,8 @@ package responses -import "github.com/NdoleStudio/httpsms/pkg/entities" +import ( + "github.com/NdoleStudio/httpsms/pkg/entities" +) // BillingUsagesResponse is the payload containing []entities.BillingUsage type BillingUsagesResponse struct { diff --git a/api/pkg/responses/bulk_message_responses.go b/api/pkg/responses/bulk_message_responses.go new file mode 100644 index 00000000..eda242a6 --- /dev/null +++ b/api/pkg/responses/bulk_message_responses.go @@ -0,0 +1,9 @@ +package responses + +import "github.com/NdoleStudio/httpsms/pkg/entities" + +// BulkMessagesResponse is the payload containing []*entities.BulkMessage +type BulkMessagesResponse struct { + response + Data []*entities.BulkMessage `json:"data"` +} diff --git a/api/pkg/responses/message_send_schedule_responses.go b/api/pkg/responses/message_send_schedule_responses.go new file mode 100644 index 00000000..630dba13 --- /dev/null +++ b/api/pkg/responses/message_send_schedule_responses.go @@ -0,0 +1,15 @@ +package responses + +import "github.com/NdoleStudio/httpsms/pkg/entities" + +// MessageSendSchedulesResponse represents a collection of message send schedules. +type MessageSendSchedulesResponse struct { + response + Data []entities.MessageSendSchedule `json:"data"` +} + +// MessageSendScheduleResponse represents a single message send schedule. +type MessageSendScheduleResponse struct { + response + Data entities.MessageSendSchedule `json:"data"` +} diff --git a/api/pkg/responses/response.go b/api/pkg/responses/response.go index c61c919e..e23fea0f 100644 --- a/api/pkg/responses/response.go +++ b/api/pkg/responses/response.go @@ -38,6 +38,12 @@ type Unauthorized struct { Data string `json:"data" example:"Make sure your API key is set in the [X-API-Key] header in the request"` } +// PaymentRequired is the response with status code is 402 +type PaymentRequired struct { + Status string `json:"status" example:"error"` + Message string `json:"message" example:"You have reached the maximum number of allowed resources. Please upgrade your plan."` +} + // NoContent is the response when status code is 204 type NoContent struct { Status string `json:"status" example:"success"` diff --git a/api/pkg/responses/user_responses.go b/api/pkg/responses/user_responses.go index f2ee6c37..31f95341 100644 --- a/api/pkg/responses/user_responses.go +++ b/api/pkg/responses/user_responses.go @@ -1,9 +1,51 @@ package responses -import "github.com/NdoleStudio/httpsms/pkg/entities" +import ( + "time" + + "github.com/NdoleStudio/httpsms/pkg/entities" +) // UserResponse is the payload containing entities.User type UserResponse struct { response Data entities.User `json:"data"` } + +// UserSubscriptionPaymentsResponse is the payload containing lemonsqueezy.SubscriptionInvoicesAPIResponse +type UserSubscriptionPaymentsResponse struct { + response + Data []struct { + Type string `json:"type"` + ID string `json:"id"` + Attributes struct { + BillingReason string `json:"billing_reason"` + CardBrand string `json:"card_brand"` + CardLastFour string `json:"card_last_four"` + Currency string `json:"currency"` + CurrencyRate string `json:"currency_rate"` + Status string `json:"status"` + StatusFormatted string `json:"status_formatted"` + Refunded bool `json:"refunded"` + RefundedAt any `json:"refunded_at"` + Subtotal int `json:"subtotal"` + DiscountTotal int `json:"discount_total"` + Tax int `json:"tax"` + TaxInclusive bool `json:"tax_inclusive"` + Total int `json:"total"` + RefundedAmount int `json:"refunded_amount"` + SubtotalUsd int `json:"subtotal_usd"` + DiscountTotalUsd int `json:"discount_total_usd"` + TaxUsd int `json:"tax_usd"` + TotalUsd int `json:"total_usd"` + RefundedAmountUsd int `json:"refunded_amount_usd"` + SubtotalFormatted string `json:"subtotal_formatted"` + DiscountTotalFormatted string `json:"discount_total_formatted"` + TaxFormatted string `json:"tax_formatted"` + TotalFormatted string `json:"total_formatted"` + RefundedAmountFormatted string `json:"refunded_amount_formatted"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + } `json:"attributes"` + } `json:"data"` +} diff --git a/api/pkg/services/discord_service.go b/api/pkg/services/discord_service.go index 059231b9..8c608e9f 100644 --- a/api/pkg/services/discord_service.go +++ b/api/pkg/services/discord_service.go @@ -169,6 +169,12 @@ func (service *DiscordService) createSlashCommand(ctx context.Context, serverID Type: 3, Required: true, }, + { + Name: "attachment_urls", + Description: "Comma-separated list of media URLs to attach", + Type: 3, + Required: false, + }, }, }) if err != nil { diff --git a/api/pkg/services/emulator_fcm_client.go b/api/pkg/services/emulator_fcm_client.go new file mode 100644 index 00000000..85060bb4 --- /dev/null +++ b/api/pkg/services/emulator_fcm_client.go @@ -0,0 +1,100 @@ +package services + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + + "firebase.google.com/go/messaging" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/palantir/stacktrace" +) + +// EmulatorFCMClient sends FCM messages to the phone emulator via HTTP. +type EmulatorFCMClient struct { + httpClient *http.Client + endpoint string + logger telemetry.Logger +} + +// NewEmulatorFCMClient creates a new EmulatorFCMClient. +func NewEmulatorFCMClient(httpClient *http.Client, endpoint string, logger telemetry.Logger) *EmulatorFCMClient { + return &EmulatorFCMClient{ + httpClient: httpClient, + endpoint: endpoint, + logger: logger, + } +} + +// emulatorFCMRequest is the payload sent to the emulator's FCM endpoint. +type emulatorFCMRequest struct { + Message *emulatorFCMMessage `json:"message"` +} + +type emulatorFCMMessage struct { + Token string `json:"token"` + Data map[string]string `json:"data,omitempty"` + Android *emulatorAndroid `json:"android,omitempty"` +} + +type emulatorAndroid struct { + Priority string `json:"priority,omitempty"` +} + +// emulatorFCMResponse is the response from the emulator. +type emulatorFCMResponse struct { + Name string `json:"name"` +} + +// Send sends a message to the emulator's FCM endpoint. +func (c *EmulatorFCMClient) Send(ctx context.Context, message *messaging.Message) (string, error) { + payload := &emulatorFCMRequest{ + Message: &emulatorFCMMessage{ + Token: message.Token, + Data: message.Data, + }, + } + if message.Android != nil { + payload.Message.Android = &emulatorAndroid{ + Priority: message.Android.Priority, + } + } + + body, err := json.Marshal(payload) + if err != nil { + return "", stacktrace.Propagate(err, "cannot marshal FCM request for emulator") + } + + url := fmt.Sprintf("%s/v1/projects/httpsms-test/messages:send", c.endpoint) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body)) + if err != nil { + return "", stacktrace.Propagate(err, "cannot create HTTP request for emulator FCM") + } + req.Header.Set("Content-Type", "application/json") + + resp, err := c.httpClient.Do(req) + if err != nil { + return "", stacktrace.Propagate(err, fmt.Sprintf("cannot send FCM to emulator at [%s]", url)) + } + defer resp.Body.Close() + + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return "", stacktrace.Propagate(err, "cannot read emulator FCM response body") + } + + if resp.StatusCode != http.StatusOK { + return "", stacktrace.NewError("emulator FCM returned status %d: %s", resp.StatusCode, string(respBody)) + } + + var result emulatorFCMResponse + if err = json.Unmarshal(respBody, &result); err != nil { + return "", stacktrace.Propagate(err, "cannot decode emulator FCM response") + } + + c.logger.Info(fmt.Sprintf("emulator FCM sent successfully: %s", result.Name)) + return result.Name, nil +} diff --git a/api/pkg/services/entitlement_service.go b/api/pkg/services/entitlement_service.go new file mode 100644 index 00000000..1010c89c --- /dev/null +++ b/api/pkg/services/entitlement_service.go @@ -0,0 +1,149 @@ +package services + +import ( + "context" + "fmt" + "strings" + "unicode" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/repositories" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + pluralize "github.com/gertd/go-pluralize" + "github.com/palantir/stacktrace" +) + +// entityLimits maps entity name → subscription plan → max count. +// A limit of 0 means unlimited. If a plan is not listed, it defaults to unlimited (0). +var entityLimits = map[string]map[entities.SubscriptionName]int{ + entities.EntityNameMessageSendSchedule: { + entities.SubscriptionNameFree: 1, + }, + entities.EntityNamePhoneAPIKey: { + entities.SubscriptionNameFree: 1, + }, +} + +// EntitlementCheckResult holds the outcome of an entitlement check. +type EntitlementCheckResult struct { + Allowed bool + Message string +} + +// EntitlementService checks whether a user can create more of a given entity +// based on their subscription plan. +type EntitlementService struct { + service + logger telemetry.Logger + tracer telemetry.Tracer + enabled bool + userRepository repositories.UserRepository +} + +// NewEntitlementService creates a new EntitlementService. +// The enabled flag should come from the ENTITLEMENT_ENABLED environment variable. +func NewEntitlementService( + logger telemetry.Logger, + tracer telemetry.Tracer, + enabled bool, + userRepository repositories.UserRepository, +) *EntitlementService { + return &EntitlementService{ + logger: logger.WithService(fmt.Sprintf("%T", &EntitlementService{})), + tracer: tracer, + enabled: enabled, + userRepository: userRepository, + } +} + +// Check verifies if the user can create another instance of the given entity. +func (service *EntitlementService) Check( + ctx context.Context, + userID entities.UserID, + entityName string, + countFunc func() (int, error), +) (*EntitlementCheckResult, error) { + ctx, span := service.tracer.Start(ctx) + defer span.End() + + if !service.enabled { + return &EntitlementCheckResult{Allowed: true}, nil + } + + limits, exists := entityLimits[entityName] + if !exists { + return &EntitlementCheckResult{Allowed: true}, nil + } + + user, err := service.userRepository.Load(ctx, userID) + if err != nil { + return nil, service.tracer.WrapErrorSpan( + span, + stacktrace.Propagate(err, fmt.Sprintf("cannot load user [%s] for entitlement check", userID)), + ) + } + + limit, hasLimit := limits[user.SubscriptionName] + if !hasLimit || limit == 0 { + return &EntitlementCheckResult{Allowed: true}, nil + } + + currentCount, err := countFunc() + if err != nil { + return nil, service.tracer.WrapErrorSpan( + span, + stacktrace.Propagate(err, fmt.Sprintf("cannot count entities [%s] for user [%s]", entityName, userID)), + ) + } + + if currentCount >= limit { + return &EntitlementCheckResult{ + Allowed: false, + Message: fmt.Sprintf( + "Upgrade to a paid plan to create more than [%d] %s. Visit https://httpsms.com/pricing for details.", + limit, + formatEntityName(entityName, true), + ), + }, nil + } + + return &EntitlementCheckResult{Allowed: true}, nil +} + +// formatEntityName converts a PascalCase entity name to lowercase words and optionally pluralizes it. +// Consecutive uppercase letters (acronyms like API) are kept together as a single word. +// e.g. "MessageSendSchedule" → "message send schedules", "PhoneAPIKey" → "phone API keys" +func formatEntityName(name string, plural bool) string { + var words []string + runes := []rune(name) + start := 0 + for i := 1; i < len(runes); i++ { + if unicode.IsUpper(runes[i]) { + if !unicode.IsUpper(runes[i-1]) { + // transition from lowercase to uppercase: split before i + words = append(words, string(runes[start:i])) + start = i + } else if i+1 < len(runes) && unicode.IsLower(runes[i+1]) { + // transition from uppercase run to a new word (e.g., "API" followed by "Key") + words = append(words, string(runes[start:i])) + start = i + } + } + } + words = append(words, string(runes[start:])) + + for i, word := range words { + if word == strings.ToUpper(word) && len(word) > 1 { + // keep acronyms uppercase (e.g., "API") + continue + } + words[i] = strings.ToLower(word) + } + + if plural && len(words) > 0 { + client := pluralize.NewClient() + words[len(words)-1] = client.Plural(words[len(words)-1]) + } + + return strings.Join(words, " ") +} diff --git a/api/pkg/services/event_dispatcher_service.go b/api/pkg/services/event_dispatcher_service.go index dfb6dae6..f9ec6b33 100644 --- a/api/pkg/services/event_dispatcher_service.go +++ b/api/pkg/services/event_dispatcher_service.go @@ -148,7 +148,7 @@ func (dispatcher *EventDispatcher) Publish(ctx context.Context, event cloudevent dispatcher.meter.Record( ctx, - float64(time.Since(start).Microseconds())/1000, + float64(time.Since(start).Milliseconds()), metric.WithAttributes( semconv.CloudeventsEventType(event.Type()), semconv.CloudeventsEventSpecVersion(event.SpecVersion()), diff --git a/api/pkg/services/fcm_client.go b/api/pkg/services/fcm_client.go new file mode 100644 index 00000000..4e56f316 --- /dev/null +++ b/api/pkg/services/fcm_client.go @@ -0,0 +1,28 @@ +package services + +import ( + "context" + + "firebase.google.com/go/messaging" +) + +// FCMClient is the interface for sending Firebase Cloud Messaging notifications. +type FCMClient interface { + // Send sends a message via FCM and returns the message name on success. + Send(ctx context.Context, message *messaging.Message) (string, error) +} + +// FirebaseFCMClient wraps the real Firebase messaging.Client. +type FirebaseFCMClient struct { + client *messaging.Client +} + +// NewFirebaseFCMClient creates a new FirebaseFCMClient. +func NewFirebaseFCMClient(client *messaging.Client) *FirebaseFCMClient { + return &FirebaseFCMClient{client: client} +} + +// Send sends a message via the real Firebase SDK. +func (c *FirebaseFCMClient) Send(ctx context.Context, message *messaging.Message) (string, error) { + return c.client.Send(ctx, message) +} diff --git a/api/pkg/services/google_cloud_push_queue_service.go b/api/pkg/services/google_cloud_push_queue_service.go index 194ab296..d22dac83 100644 --- a/api/pkg/services/google_cloud_push_queue_service.go +++ b/api/pkg/services/google_cloud_push_queue_service.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/avast/retry-go" + "github.com/avast/retry-go/v5" cloudtasks "cloud.google.com/go/cloudtasks/apiv2" "cloud.google.com/go/cloudtasks/apiv2/cloudtaskspb" @@ -39,10 +39,10 @@ func NewGooglePushQueue( // Enqueue a task to the queue func (queue *googlePushQueue) Enqueue(ctx context.Context, task *PushQueueTask, timeout time.Duration) (queueID string, err error) { - err = retry.Do(func() error { + err = retry.New(retry.Attempts(3)).Do(func() error { queueID, err = queue.enqueueImpl(ctx, task, timeout) return err - }, retry.Attempts(3)) + }) return queueID, err } diff --git a/api/pkg/services/marketting_service.go b/api/pkg/services/marketting_service.go index bb7c0054..199eb81c 100644 --- a/api/pkg/services/marketting_service.go +++ b/api/pkg/services/marketting_service.go @@ -2,47 +2,25 @@ package services import ( "context" - "encoding/json" "fmt" - "log" - "net/http" "strings" - "github.com/sendgrid/sendgrid-go" + semconv "go.opentelemetry.io/otel/semconv/v1.10.0" "firebase.google.com/go/auth" "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/telemetry" - "github.com/davecgh/go-spew/spew" + plunk "github.com/NdoleStudio/plunk-go" + "github.com/gofiber/fiber/v2" "github.com/palantir/stacktrace" ) // MarketingService is handles marketing requests type MarketingService struct { - logger telemetry.Logger - tracer telemetry.Tracer - authClient *auth.Client - sendgridAPIKey string - sendgridHost string - sendgridListID string -} - -type sendgridContact struct { - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - ExternalID string `json:"external_id"` - Email string `json:"email"` - ID string `json:"id,omitempty"` -} - -type sendgridSearchResponse struct { - ContactCount int `json:"contact_count"` - Result []sendgridContact `json:"result"` -} - -type sendgridContactRequest struct { - ListIDs []string `json:"list_ids"` - Contacts []sendgridContact `json:"contacts"` + logger telemetry.Logger + tracer telemetry.Tracer + authClient *auth.Client + plunkClient *plunk.Client } // NewMarketingService creates a new instance of the MarketingService @@ -50,133 +28,85 @@ func NewMarketingService( logger telemetry.Logger, tracer telemetry.Tracer, authClient *auth.Client, - sendgridAPIKey string, - sendgridListID string, + plunkClient *plunk.Client, ) *MarketingService { return &MarketingService{ - logger: logger.WithService(fmt.Sprintf("%T", &MarketingService{})), - tracer: tracer, - authClient: authClient, - sendgridHost: "https://api.sendgrid.com", - sendgridAPIKey: sendgridAPIKey, - sendgridListID: sendgridListID, + logger: logger.WithService(fmt.Sprintf("%T", &MarketingService{})), + tracer: tracer, + authClient: authClient, + plunkClient: plunkClient, } } -// DeleteUser a user if exists in the sendgrid list -func (service *MarketingService) DeleteUser(ctx context.Context, userID entities.UserID) error { +// DeleteContact a user if exists as a contact +func (service *MarketingService) DeleteContact(ctx context.Context, email string) error { ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) defer span.End() - request := sendgrid.GetRequest(service.sendgridAPIKey, "/v3/marketing/contacts/search", service.sendgridHost) - request.Method = http.MethodPost - request.Body = []byte(fmt.Sprintf(`{"query": "external_id = '%s' AND CONTAINS(list_ids, '%s')"}`, userID, service.sendgridListID)) - response, err := sendgrid.API(request) + response, _, err := service.plunkClient.Contacts.List(ctx, map[string]string{"search": email}) if err != nil { - return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot search for user with id [%s] in sendgrid list [%s]", userID, service.sendgridListID))) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot search for contact with email [%s]", email))) } - data := new(sendgridSearchResponse) - if err = json.Unmarshal([]byte(response.Body), data); err != nil { - return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot [%s] into [%T]", response.Body, data))) + if len(response.Data) == 0 { + ctxLogger.Info(fmt.Sprintf("no contact found with email [%s], skipping deletion", email)) + return nil } - if data.ContactCount == 0 { - ctxLogger.Info(fmt.Sprintf("user with ID [%s] not found in sendgrid list [%s]", userID, service.sendgridListID)) - return nil + contact := response.Data[0] + if _, err = service.plunkClient.Contacts.Delete(ctx, contact.ID); err != nil { + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot delete user with ID [%s] from contacts", contact.Data[string(semconv.EnduserIDKey)]))) } - ctxLogger.Info(fmt.Sprintf("deleting sendgrid contact with ID [%s] for user with ID [%s]", data.Result[0].ID, userID)) - return service.DeleteContacts(context.Background(), []string{data.Result[0].ID}) + ctxLogger.Info(fmt.Sprintf("deleted user with ID [%s] from as marketting contact with ID [%s]", contact.Data[string(semconv.EnduserIDKey)], contact.ID)) + return nil } -// AddToList adds a new user on the onboarding automation. -func (service *MarketingService) AddToList(ctx context.Context, user *entities.User) { +// CreateContact adds a new user on the onboarding automation. +func (service *MarketingService) CreateContact(ctx context.Context, userID entities.UserID) error { ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) defer span.End() - userRecord, err := service.authClient.GetUser(ctx, string(user.ID)) + userRecord, err := service.authClient.GetUser(ctx, userID.String()) if err != nil { - msg := fmt.Sprintf("cannot get auth user with id [%s]", user.ID) - ctxLogger.Error(stacktrace.Propagate(err, msg)) - return + msg := fmt.Sprintf("cannot get auth user with id [%s]", userID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } - id, err := service.addContact(sendgridContactRequest{ - ListIDs: []string{service.sendgridListID}, - Contacts: []sendgridContact{service.toSendgridContact(userRecord)}, - }) - if err != nil { - msg := fmt.Sprintf("cannot add user with id [%s] to list [%s]", user.ID, service.sendgridListID) - ctxLogger.Error(stacktrace.Propagate(err, msg)) - return - } + data := service.attributes(userRecord) + data[string(semconv.ServiceNameKey)] = "httpsms.com" + data[string(semconv.EnduserIDKey)] = userRecord.UID - ctxLogger.Info(fmt.Sprintf("user [%s] added to list [%s] with job [%s]", user.ID, service.sendgridListID, id)) -} - -// DeleteContacts deletes contacts from sendgrid -func (service *MarketingService) DeleteContacts(ctx context.Context, contactIDs []string) error { - ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) - defer span.End() - - request := sendgrid.GetRequest(service.sendgridAPIKey, "/v3/marketing/contacts", service.sendgridHost) - request.Method = "DELETE" - request.QueryParams = map[string]string{ - "ids": strings.Join(contactIDs, ","), - } - - response, err := sendgrid.API(request) + event, _, err := service.plunkClient.Tracker.TrackEvent(ctx, &plunk.TrackEventRequest{ + Email: userRecord.Email, + Event: "contact.created", + Subscribed: true, + Data: data, + }) if err != nil { - return stacktrace.Propagate(err, fmt.Sprintf("cannot delete contacts in a sendgrid list [%s]", service.sendgridListID)) + msg := fmt.Sprintf("cannot create contact for user with id [%s]", userID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } - ctxLogger.Info(fmt.Sprintf("deleted contacts [%s] from sendgrid list [%s] with sendgrid response [%s]", strings.Join(contactIDs, ","), service.sendgridListID, response.Body)) + ctxLogger.Info(fmt.Sprintf("user [%s] added to marketting list with contact ID [%s] and event ID [%s]", userID, event.Data.Contact, event.Data.Event)) return nil } -func (service *MarketingService) toSendgridContact(user *auth.UserRecord) sendgridContact { +func (service *MarketingService) attributes(user *auth.UserRecord) map[string]any { name := strings.TrimSpace(user.DisplayName) if name == "" { - return sendgridContact{ - FirstName: "", - LastName: "", - ExternalID: user.UID, - Email: user.Email, - } + return fiber.Map{} } parts := strings.Split(name, " ") if len(parts) == 1 { - return sendgridContact{ - FirstName: name, - LastName: "", - ExternalID: user.UID, - Email: user.Email, + return fiber.Map{ + "firstName": name, } } - return sendgridContact{ - FirstName: strings.Join(parts[0:len(parts)-1], " "), - LastName: parts[len(parts)-1], - ExternalID: user.UID, - Email: user.Email, - } -} - -func (service *MarketingService) addContact(contactRequest sendgridContactRequest) (string, error) { - request := sendgrid.GetRequest(service.sendgridAPIKey, "/v3/marketing/contacts", "https://api.sendgrid.com") - request.Method = "PUT" - - body, err := json.Marshal(contactRequest) - if err != nil { - log.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot marshal [%s]", spew.Sdump(contactRequest)))) - } - - request.Body = body - response, err := sendgrid.API(request) - if err != nil { - return "", stacktrace.Propagate(err, fmt.Sprintf("cannot add contact to sendgrid list [%s]", spew.Sdump(contactRequest))) + return fiber.Map{ + "firstName": strings.Join(parts[0:len(parts)-1], " "), + "lastName": parts[len(parts)-1], } - return response.Body, nil } diff --git a/api/pkg/services/message_send_schedule_service.go b/api/pkg/services/message_send_schedule_service.go new file mode 100644 index 00000000..1a4d85ed --- /dev/null +++ b/api/pkg/services/message_send_schedule_service.go @@ -0,0 +1,213 @@ +package services + +import ( + "context" + "fmt" + "sort" + "time" + + "github.com/NdoleStudio/httpsms/pkg/entities" + "github.com/NdoleStudio/httpsms/pkg/events" + "github.com/NdoleStudio/httpsms/pkg/repositories" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/google/uuid" + "github.com/palantir/stacktrace" +) + +// MessageSendScheduleService manages message send schedules for a user. +type MessageSendScheduleService struct { + service + logger telemetry.Logger + tracer telemetry.Tracer + repository repositories.MessageSendScheduleRepository + dispatcher *EventDispatcher +} + +// NewMessageSendScheduleService creates a new MessageSendScheduleService. +func NewMessageSendScheduleService( + logger telemetry.Logger, + tracer telemetry.Tracer, + repository repositories.MessageSendScheduleRepository, + dispatcher *EventDispatcher, +) *MessageSendScheduleService { + return &MessageSendScheduleService{ + logger: logger.WithService(fmt.Sprintf("%T", &MessageSendScheduleService{})), + tracer: tracer, + repository: repository, + dispatcher: dispatcher, + } +} + +// MessageSendScheduleUpsertParams contains the fields required to create or update a message send schedule. +type MessageSendScheduleUpsertParams struct { + UserID entities.UserID + Name string + Timezone string + Windows []entities.MessageSendScheduleWindow +} + +// Index returns all message send schedules for a user. +func (service *MessageSendScheduleService) Index( + ctx context.Context, + userID entities.UserID, +) ([]entities.MessageSendSchedule, error) { + return service.repository.Index(ctx, userID) +} + +// CountByUser returns the number of schedules owned by a user. +func (service *MessageSendScheduleService) CountByUser( + ctx context.Context, + userID entities.UserID, +) (int, error) { + return service.repository.CountByUser(ctx, userID) +} + +// Load returns a single message send schedule for a user. +func (service *MessageSendScheduleService) Load( + ctx context.Context, + userID entities.UserID, + scheduleID uuid.UUID, +) (*entities.MessageSendSchedule, error) { + return service.repository.Load(ctx, userID, scheduleID) +} + +// Store creates a new message send schedule. +func (service *MessageSendScheduleService) Store( + ctx context.Context, + params *MessageSendScheduleUpsertParams, +) (*entities.MessageSendSchedule, error) { + ctx, span := service.tracer.Start(ctx) + defer span.End() + + schedule := &entities.MessageSendSchedule{ + ID: uuid.New(), + UserID: params.UserID, + Name: params.Name, + Timezone: params.Timezone, + Windows: sanitizeWindows(params.Windows), + CreatedAt: time.Now().UTC(), + UpdatedAt: time.Now().UTC(), + } + + if err := service.repository.Store(ctx, schedule); err != nil { + return nil, service.tracer.WrapErrorSpan( + span, + stacktrace.Propagate( + err, + fmt.Sprintf("cannot store message send schedule [%s]", schedule.ID), + ), + ) + } + + return schedule, nil +} + +// Update updates an existing message send schedule. +func (service *MessageSendScheduleService) Update( + ctx context.Context, + userID entities.UserID, + scheduleID uuid.UUID, + params *MessageSendScheduleUpsertParams, +) (*entities.MessageSendSchedule, error) { + ctx, span := service.tracer.Start(ctx) + defer span.End() + + schedule, err := service.repository.Load(ctx, userID, scheduleID) + if err != nil { + return nil, err + } + + schedule.Name = params.Name + schedule.Timezone = params.Timezone + schedule.Windows = sanitizeWindows(params.Windows) + schedule.UpdatedAt = time.Now().UTC() + + if err = service.repository.Update(ctx, schedule); err != nil { + return nil, service.tracer.WrapErrorSpan( + span, + stacktrace.Propagate( + err, + fmt.Sprintf("cannot update message send schedule [%s]", schedule.ID), + ), + ) + } + + return schedule, nil +} + +// Delete removes a message send schedule for a user. +func (service *MessageSendScheduleService) Delete( + ctx context.Context, + userID entities.UserID, + scheduleID uuid.UUID, +) error { + ctx, span := service.tracer.Start(ctx) + defer span.End() + + if err := service.repository.Delete(ctx, userID, scheduleID); err != nil { + msg := fmt.Sprintf("cannot delete message send schedule with ID [%s] for user [%s]", scheduleID, userID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + event, err := service.createEvent(events.EventTypeMessageSendScheduleDeleted, fmt.Sprintf("%T", service), events.MessageSendScheduleDeletedPayload{ + ScheduleID: scheduleID, + UserID: userID, + Timestamp: time.Now().UTC(), + }) + if err != nil { + msg := fmt.Sprintf("cannot create [%s] event for schedule [%s]", events.EventTypeMessageSendScheduleDeleted, scheduleID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if err = service.dispatcher.Dispatch(ctx, event); err != nil { + msg := fmt.Sprintf("cannot dispatch [%s] event for schedule [%s]", event.Type(), scheduleID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + return nil +} + +// sanitizeWindows normalizes and sorts schedule windows by day and start minute. +func sanitizeWindows( + windows []entities.MessageSendScheduleWindow, +) []entities.MessageSendScheduleWindow { + result := make([]entities.MessageSendScheduleWindow, 0, len(windows)) + + for _, item := range windows { + result = append(result, entities.MessageSendScheduleWindow{ + DayOfWeek: item.DayOfWeek, + StartMinute: item.StartMinute, + EndMinute: item.EndMinute, + }) + } + + sort.SliceStable(result, func(i, j int) bool { + if result[i].DayOfWeek == result[j].DayOfWeek { + return result[i].StartMinute < result[j].StartMinute + } + return result[i].DayOfWeek < result[j].DayOfWeek + }) + + return result +} + +// DeleteAllForUser removes all message send schedules owned by a user. +func (service *MessageSendScheduleService) DeleteAllForUser( + ctx context.Context, + userID entities.UserID, +) error { + ctx, span := service.tracer.Start(ctx) + defer span.End() + + if err := service.repository.DeleteAllForUser(ctx, userID); err != nil { + return service.tracer.WrapErrorSpan( + span, + stacktrace.Propagate( + err, + fmt.Sprintf("cannot delete message send schedules for user [%s]", userID), + ), + ) + } + + return nil +} diff --git a/api/pkg/services/message_service.go b/api/pkg/services/message_service.go index 5a95b265..56766c98 100644 --- a/api/pkg/services/message_service.go +++ b/api/pkg/services/message_service.go @@ -2,13 +2,14 @@ package services import ( "context" + "encoding/base64" "fmt" "strings" "time" "github.com/davecgh/go-spew/spew" - "github.com/nyaruka/phonenumbers" + "golang.org/x/sync/errgroup" "github.com/NdoleStudio/httpsms/pkg/events" "github.com/NdoleStudio/httpsms/pkg/repositories" @@ -20,14 +21,23 @@ import ( "github.com/NdoleStudio/httpsms/pkg/telemetry" ) +// ServiceAttachment represents attachment data passed to the service layer +type ServiceAttachment struct { + Name string + ContentType string + Content string // base64-encoded +} + // MessageService is handles message requests type MessageService struct { service - logger telemetry.Logger - tracer telemetry.Tracer - eventDispatcher *EventDispatcher - phoneService *PhoneService - repository repositories.MessageRepository + logger telemetry.Logger + tracer telemetry.Tracer + eventDispatcher *EventDispatcher + phoneService *PhoneService + repository repositories.MessageRepository + attachmentRepository repositories.AttachmentRepository + apiBaseURL string } // NewMessageService creates a new MessageService @@ -37,13 +47,17 @@ func NewMessageService( repository repositories.MessageRepository, eventDispatcher *EventDispatcher, phoneService *PhoneService, + attachmentRepository repositories.AttachmentRepository, + apiBaseURL string, ) (s *MessageService) { return &MessageService{ - logger: logger.WithService(fmt.Sprintf("%T", s)), - tracer: tracer, - repository: repository, - phoneService: phoneService, - eventDispatcher: eventDispatcher, + logger: logger.WithService(fmt.Sprintf("%T", s)), + tracer: tracer, + repository: repository, + phoneService: phoneService, + eventDispatcher: eventDispatcher, + attachmentRepository: attachmentRepository, + apiBaseURL: apiBaseURL, } } @@ -109,6 +123,21 @@ func (service *MessageService) DeleteAllForUser(ctx context.Context, userID enti return nil } +// GetBulkMessages fetches the last bulk message summaries for a user +func (service *MessageService) GetBulkMessages(ctx context.Context, userID entities.UserID) ([]*entities.BulkMessage, error) { + ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) + defer span.End() + + orders, err := service.repository.GetBulkMessages(ctx, userID, 10) + if err != nil { + msg := fmt.Sprintf("could not fetch bulk messages for user [%s]", userID) + return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + ctxLogger.Info(fmt.Sprintf("fetched [%d] bulk messages for user [%s]", len(orders), userID)) + return orders, nil +} + // DeleteMessage deletes a message from the database func (service *MessageService) DeleteMessage(ctx context.Context, source string, message *entities.Message) error { ctx, span := service.tracer.Start(ctx) @@ -290,14 +319,15 @@ func (service *MessageService) StoreEvent(ctx context.Context, message *entities // MessageReceiveParams parameters registering a message event type MessageReceiveParams struct { - Contact string - UserID entities.UserID - Owner phonenumbers.PhoneNumber - Content string - SIM entities.SIM - Timestamp time.Time - Encrypted bool - Source string + Contact string + UserID entities.UserID + Owner phonenumbers.PhoneNumber + Content string + SIM entities.SIM + Timestamp time.Time + Encrypted bool + Source string + Attachments []ServiceAttachment } // ReceiveMessage handles message received by a mobile phone @@ -307,15 +337,25 @@ func (service *MessageService) ReceiveMessage(ctx context.Context, params *Messa ctxLogger := service.tracer.CtxLogger(service.logger, span) + messageID := uuid.New() + + ctxLogger.Info(fmt.Sprintf("uploading [%d] attachments for user [%s] message [%s]", len(params.Attachments), params.UserID, messageID)) + attachmentURLs, err := service.uploadAttachments(ctx, params.UserID, messageID, params.Attachments) + if err != nil { + msg := fmt.Sprintf("cannot upload attachments for user [%s] message [%s]", params.UserID, messageID) + return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + eventPayload := events.MessagePhoneReceivedPayload{ - MessageID: uuid.New(), - UserID: params.UserID, - Encrypted: params.Encrypted, - Owner: phonenumbers.Format(¶ms.Owner, phonenumbers.E164), - Contact: params.Contact, - Timestamp: params.Timestamp, - Content: params.Content, - SIM: params.SIM, + MessageID: messageID, + UserID: params.UserID, + Encrypted: params.Encrypted, + Owner: phonenumbers.Format(¶ms.Owner, phonenumbers.E164), + Contact: params.Contact, + Timestamp: params.Timestamp, + Content: params.Content, + SIM: params.SIM, + Attachments: attachmentURLs, } ctxLogger.Info(fmt.Sprintf("creating cloud event for received with ID [%s]", eventPayload.MessageID)) @@ -332,7 +372,7 @@ func (service *MessageService) ReceiveMessage(ctx context.Context, params *Messa msg := fmt.Sprintf("cannot dispatch event type [%s] and id [%s]", event.Type(), event.ID()) return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } - ctxLogger.Info(fmt.Sprintf("event [%s] dispatched succesfully", event.ID())) + ctxLogger.Info(fmt.Sprintf("event [%s] dispatched successfully", event.ID())) return service.storeReceivedMessage(ctx, eventPayload) } @@ -430,11 +470,13 @@ type MessageSendParams struct { Contact string Encrypted bool Content string + Attachments []string Source string SendAt *time.Time RequestID *string UserID entities.UserID RequestReceivedAt time.Time + Index int } // SendMessage a new message @@ -444,7 +486,7 @@ func (service *MessageService) SendMessage(ctx context.Context, params MessageSe ctxLogger := service.tracer.CtxLogger(service.logger, span) - sendAttempts, sim := service.phoneSettings(ctx, params.UserID, phonenumbers.Format(params.Owner, phonenumbers.E164)) + sendAttempts, sim, messagesPerMinute := service.phoneSettings(ctx, params.UserID, phonenumbers.Format(params.Owner, phonenumbers.E164)) eventPayload := events.MessageAPISentPayload{ MessageID: uuid.New(), @@ -456,7 +498,9 @@ func (service *MessageService) SendMessage(ctx context.Context, params MessageSe Contact: params.Contact, RequestReceivedAt: params.RequestReceivedAt, Content: params.Content, + Attachments: params.Attachments, ScheduledSendTime: params.SendAt, + ExactSendTime: params.SendAt != nil, SIM: sim, } @@ -473,7 +517,7 @@ func (service *MessageService) SendMessage(ctx context.Context, params MessageSe return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } - timeout := service.getSendDelay(ctxLogger, eventPayload, params.SendAt) + timeout := service.getSendDelay(ctxLogger, eventPayload, params, messagesPerMinute) if _, err = service.eventDispatcher.DispatchWithTimeout(ctx, event, timeout); err != nil { msg := fmt.Sprintf("cannot dispatch event type [%s] and id [%s]", event.Type(), event.ID()) return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) @@ -532,18 +576,24 @@ func (service *MessageService) RegisterMissedCall(ctx context.Context, params *M return message, err } -func (service *MessageService) getSendDelay(ctxLogger telemetry.Logger, eventPayload events.MessageAPISentPayload, sendAt *time.Time) time.Duration { - if sendAt == nil { - return time.Duration(0) +func (service *MessageService) getSendDelay(ctxLogger telemetry.Logger, eventPayload events.MessageAPISentPayload, params MessageSendParams, messagesPerMinute uint) time.Duration { + if params.SendAt != nil { + delay := params.SendAt.Sub(time.Now().UTC()) + if delay < 0 { + ctxLogger.Info(fmt.Sprintf("message [%s] has send time [%s] in the past. sending immediately", eventPayload.MessageID, params.SendAt.String())) + return time.Duration(0) + } + return delay } - delay := sendAt.Sub(time.Now().UTC()) - if delay < 0 { - ctxLogger.Info(fmt.Sprintf("message [%s] has send time [%s] in the past. sending immediately", eventPayload.MessageID, sendAt.String())) - return time.Duration(0) + if params.Index > 0 && messagesPerMinute > 0 { + interval := time.Minute / time.Duration(messagesPerMinute) + delay := time.Duration(params.Index) * interval + ctxLogger.Info(fmt.Sprintf("message [%s] bulk index [%d] rate-based delay [%s]", eventPayload.MessageID, params.Index, delay)) + return delay } - return delay + return time.Duration(0) } // StoreReceivedMessage a new message @@ -559,6 +609,7 @@ func (service *MessageService) storeReceivedMessage(ctx context.Context, params UserID: params.UserID, Contact: params.Contact, Content: params.Content, + Attachments: params.Attachments, SIM: params.SIM, Encrypted: params.Encrypted, Type: entities.MessageTypeMobileOriginated, @@ -579,6 +630,55 @@ func (service *MessageService) storeReceivedMessage(ctx context.Context, params return message, nil } +func (service *MessageService) uploadAttachments(ctx context.Context, userID entities.UserID, messageID uuid.UUID, attachments []ServiceAttachment) ([]string, error) { + if len(attachments) == 0 { + return []string{}, nil + } + + ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) + defer span.End() + + g, gCtx := errgroup.WithContext(ctx) + urls := make([]string, len(attachments)) + paths := make([]string, len(attachments)) + + for i, attachment := range attachments { + i, attachment := i, attachment + g.Go(func() error { + decoded, err := base64.StdEncoding.DecodeString(attachment.Content) + if err != nil { + return stacktrace.Propagate(err, fmt.Sprintf("cannot decode base64 content for attachment [%d]", i)) + } + + sanitizedName := repositories.SanitizeFilename(attachment.Name, i) + ext := repositories.ExtensionFromContentType(attachment.ContentType) + filename := sanitizedName + ext + + path := fmt.Sprintf("attachments/%s/%s/%d/%s", userID, messageID, i, filename) + paths[i] = path + + if err = service.attachmentRepository.Upload(gCtx, path, decoded, attachment.ContentType); err != nil { + return stacktrace.Propagate(err, fmt.Sprintf("cannot upload attachment [%d] to path [%s]", i, path)) + } + + urls[i] = fmt.Sprintf("%s/v1/attachments/%s/%s/%d/%s", service.apiBaseURL, userID, messageID, i, filename) + ctxLogger.Info(fmt.Sprintf("uploaded attachment [%d] to [%s]", i, path)) + return nil + }) + } + + if err := g.Wait(); err != nil { + for _, path := range paths { + if path != "" { + _ = service.attachmentRepository.Delete(ctx, path) + } + } + return nil, stacktrace.Propagate(err, "cannot upload attachments") + } + + return urls, nil +} + // HandleMessageParams are parameters for handling a message event type HandleMessageParams struct { ID uuid.UUID @@ -934,7 +1034,7 @@ func (service *MessageService) SearchMessages(ctx context.Context, params *Messa return messages, nil } -func (service *MessageService) phoneSettings(ctx context.Context, userID entities.UserID, owner string) (uint, entities.SIM) { +func (service *MessageService) phoneSettings(ctx context.Context, userID entities.UserID, owner string) (uint, entities.SIM, uint) { ctx, span := service.tracer.Start(ctx) defer span.End() @@ -944,10 +1044,10 @@ func (service *MessageService) phoneSettings(ctx context.Context, userID entitie if err != nil { msg := fmt.Sprintf("cannot load phone for userID [%s] and owner [%s]. using default max send attempt of 2", userID, owner) ctxLogger.Error(stacktrace.Propagate(err, msg)) - return 2, entities.SIM1 + return 2, entities.SIM1, 0 } - return phone.MaxSendAttemptsSanitized(), phone.SIM + return phone.MaxSendAttemptsSanitized(), phone.SIM, phone.MessagesPerMinute } // storeSentMessage a new message @@ -968,6 +1068,7 @@ func (service *MessageService) storeSentMessage(ctx context.Context, payload eve Contact: payload.Contact, UserID: payload.UserID, Content: payload.Content, + Attachments: payload.Attachments, RequestID: payload.RequestID, SIM: payload.SIM, Encrypted: payload.Encrypted, diff --git a/api/pkg/services/message_service_test.go b/api/pkg/services/message_service_test.go new file mode 100644 index 00000000..263816f4 --- /dev/null +++ b/api/pkg/services/message_service_test.go @@ -0,0 +1,105 @@ +package services + +import ( + "testing" + "time" + + "github.com/NdoleStudio/httpsms/pkg/events" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/google/uuid" + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/trace" +) + +func TestGetSendDelay_WithSendAt_ReturnsTimeUntil(t *testing.T) { + service := &MessageService{} + logger := &noopLogger{} + + sendAt := time.Now().UTC().Add(5 * time.Minute) + params := MessageSendParams{SendAt: &sendAt} + payload := events.MessageAPISentPayload{MessageID: uuid.New()} + + delay := service.getSendDelay(logger, payload, params, 10) + + // Should be approximately 5 minutes (within 2 seconds tolerance) + assert.InDelta(t, float64(5*time.Minute), float64(delay), float64(2*time.Second)) +} + +func TestGetSendDelay_WithSendAtInPast_ReturnsZero(t *testing.T) { + service := &MessageService{} + logger := &noopLogger{} + + sendAt := time.Now().UTC().Add(-5 * time.Minute) + params := MessageSendParams{SendAt: &sendAt} + payload := events.MessageAPISentPayload{MessageID: uuid.New()} + + delay := service.getSendDelay(logger, payload, params, 10) + + assert.Equal(t, time.Duration(0), delay) +} + +func TestGetSendDelay_BulkIndex_RateBasedDelay(t *testing.T) { + service := &MessageService{} + logger := &noopLogger{} + + params := MessageSendParams{Index: 3} + payload := events.MessageAPISentPayload{MessageID: uuid.New()} + + // 10 messages per minute = 6 seconds interval + delay := service.getSendDelay(logger, payload, params, 10) + + expected := time.Duration(3) * (time.Minute / time.Duration(10)) + assert.Equal(t, expected, delay) +} + +func TestGetSendDelay_BulkIndex_ZeroRate_ReturnsZero(t *testing.T) { + service := &MessageService{} + logger := &noopLogger{} + + params := MessageSendParams{Index: 5} + payload := events.MessageAPISentPayload{MessageID: uuid.New()} + + delay := service.getSendDelay(logger, payload, params, 0) + + assert.Equal(t, time.Duration(0), delay) +} + +func TestGetSendDelay_IndexZero_ReturnsZero(t *testing.T) { + service := &MessageService{} + logger := &noopLogger{} + + params := MessageSendParams{Index: 0} + payload := events.MessageAPISentPayload{MessageID: uuid.New()} + + delay := service.getSendDelay(logger, payload, params, 10) + + assert.Equal(t, time.Duration(0), delay) +} + +func TestGetSendDelay_NoSendAtNoIndex_ReturnsZero(t *testing.T) { + service := &MessageService{} + logger := &noopLogger{} + + params := MessageSendParams{} + payload := events.MessageAPISentPayload{MessageID: uuid.New()} + + delay := service.getSendDelay(logger, payload, params, 10) + + assert.Equal(t, time.Duration(0), delay) +} + +// noopLogger implements telemetry.Logger for testing +type noopLogger struct{} + +var _ telemetry.Logger = (*noopLogger)(nil) + +func (l *noopLogger) Error(_ error) {} +func (l *noopLogger) WithService(_ string) telemetry.Logger { return l } +func (l *noopLogger) WithString(_, _ string) telemetry.Logger { return l } +func (l *noopLogger) WithSpan(_ trace.SpanContext) telemetry.Logger { return l } +func (l *noopLogger) Trace(_ string) {} +func (l *noopLogger) Info(_ string) {} +func (l *noopLogger) Warn(_ error) {} +func (l *noopLogger) Debug(_ string) {} +func (l *noopLogger) Fatal(_ error) {} +func (l *noopLogger) Printf(_ string, _ ...interface{}) {} diff --git a/api/pkg/services/phone_api_key_service.go b/api/pkg/services/phone_api_key_service.go index 5a148583..c9283fdd 100644 --- a/api/pkg/services/phone_api_key_service.go +++ b/api/pkg/services/phone_api_key_service.go @@ -40,6 +40,14 @@ func NewPhoneAPIKeyService( } } +// CountByUser returns the number of phone API keys owned by a user. +func (service *PhoneAPIKeyService) CountByUser(ctx context.Context, userID entities.UserID) (int, error) { + ctx, span := service.tracer.Start(ctx) + defer span.End() + + return service.repository.CountByUser(ctx, userID) +} + // Index fetches the entities.Webhook for an entities.UserID func (service *PhoneAPIKeyService) Index(ctx context.Context, userID entities.UserID, params repositories.IndexParams) ([]*entities.PhoneAPIKey, error) { ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) diff --git a/api/pkg/services/phone_notification_service.go b/api/pkg/services/phone_notification_service.go index 7907d6d6..79b43037 100644 --- a/api/pkg/services/phone_notification_service.go +++ b/api/pkg/services/phone_notification_service.go @@ -15,35 +15,39 @@ import ( "github.com/NdoleStudio/httpsms/pkg/telemetry" "github.com/google/uuid" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel/trace" ) // PhoneNotificationService sends out notifications to mobile phones type PhoneNotificationService struct { service - logger telemetry.Logger - tracer telemetry.Tracer - phoneNotificationRepository repositories.PhoneNotificationRepository - phoneRepository repositories.PhoneRepository - messagingClient *messaging.Client - eventDispatcher *EventDispatcher + logger telemetry.Logger + tracer telemetry.Tracer + phoneNotificationRepository repositories.PhoneNotificationRepository + phoneRepository repositories.PhoneRepository + messageSendScheduleRepository repositories.MessageSendScheduleRepository + messagingClient FCMClient + eventDispatcher *EventDispatcher } // NewNotificationService creates a new PhoneNotificationService func NewNotificationService( logger telemetry.Logger, tracer telemetry.Tracer, - messagingClient *messaging.Client, + messagingClient FCMClient, phoneRepository repositories.PhoneRepository, phoneNotificationRepository repositories.PhoneNotificationRepository, + messageSendScheduleRepository repositories.MessageSendScheduleRepository, dispatcher *EventDispatcher, ) (s *PhoneNotificationService) { return &PhoneNotificationService{ - logger: logger.WithService(fmt.Sprintf("%T", s)), - tracer: tracer, - messagingClient: messagingClient, - phoneNotificationRepository: phoneNotificationRepository, - phoneRepository: phoneRepository, - eventDispatcher: dispatcher, + logger: logger.WithService(fmt.Sprintf("%T", &PhoneNotificationService{})), + tracer: tracer, + messagingClient: messagingClient, + phoneNotificationRepository: phoneNotificationRepository, + phoneRepository: phoneRepository, + messageSendScheduleRepository: messageSendScheduleRepository, + eventDispatcher: dispatcher, } } @@ -61,6 +65,20 @@ func (service *PhoneNotificationService) DeleteAllForUser(ctx context.Context, u return nil } +// DeleteByMessageID deletes all entities.PhoneNotification for a user and message ID. +func (service *PhoneNotificationService) DeleteByMessageID(ctx context.Context, userID entities.UserID, messageID uuid.UUID) error { + ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) + defer span.End() + + if err := service.phoneNotificationRepository.DeleteByMessageID(ctx, userID, messageID); err != nil { + msg := fmt.Sprintf("could not delete [entities.PhoneNotification] for user [%s] and message with ID [%s]", userID, messageID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + ctxLogger.Info(fmt.Sprintf("deleted [entities.PhoneNotification] for user [%s] and message with ID [%s]", userID, messageID)) + return nil +} + // SendHeartbeatFCM sends a heartbeat message so the phone can request a heartbeat func (service *PhoneNotificationService) SendHeartbeatFCM(ctx context.Context, payload *events.PhoneHeartbeatMissedPayload) error { ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) @@ -92,7 +110,13 @@ func (service *PhoneNotificationService) SendHeartbeatFCM(ctx context.Context, p return nil } - ctxLogger.Info(fmt.Sprintf("successfully sent heartbeat FCM [%s] to phone with ID [%s] for user [%s] and monitor [%s]", result, payload.PhoneID, payload.UserID, payload.MonitorID)) + ctxLogger.Info(fmt.Sprintf( + "successfully sent heartbeat FCM [%s] to phone with ID [%s] for user [%s] and monitor [%s]", + result, + payload.PhoneID, + payload.UserID, + payload.MonitorID, + )) return nil } @@ -134,7 +158,15 @@ func (service *PhoneNotificationService) Send(ctx context.Context, params *Phone Token: *phone.FcmToken, }) if err != nil { - ctxLogger.Warn(stacktrace.Propagate(err, fmt.Sprintf("cannot send FCM to phone with ID [%s] for user with ID [%s] and message [%s]", phone.ID, phone.UserID, params.MessageID))) + ctxLogger.Warn(stacktrace.Propagate( + err, + fmt.Sprintf( + "cannot send FCM to phone with ID [%s] for user with ID [%s] and message [%s]", + phone.ID, + phone.UserID, + params.MessageID, + ), + )) msg := fmt.Sprintf("cannot send notification for to your phone [%s]. Reinstall the httpSMS app on your Android phone.", phone.PhoneNumber) return service.handleNotificationFailed(ctx, errors.New(msg), params) } @@ -144,14 +176,16 @@ func (service *PhoneNotificationService) Send(ctx context.Context, params *Phone // PhoneNotificationScheduleParams are parameters for sending a notification type PhoneNotificationScheduleParams struct { - UserID entities.UserID - Owner string - Source string - Encrypted bool - Contact string - Content string - SIM entities.SIM - MessageID uuid.UUID + UserID entities.UserID + Owner string + Source string + Encrypted bool + Contact string + Content string + SIM entities.SIM + MessageID uuid.UUID + ExactSendTime bool + ScheduledSendTime *time.Time } // Schedule a notification to be sent to a phone @@ -178,7 +212,24 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P UpdatedAt: time.Now().UTC(), } - if err = service.phoneNotificationRepository.Schedule(ctx, phone.MessagesPerMinute, notification); err != nil { + if params.ExactSendTime && params.ScheduledSendTime != nil { + return service.scheduleExact(ctx, span, ctxLogger, params, phone, notification) + } + + var schedule *entities.MessageSendSchedule + if phone.MessageSendScheduleID != nil { + schedule, err = service.messageSendScheduleRepository.Load(ctx, params.UserID, *phone.MessageSendScheduleID) + if err != nil && stacktrace.GetCode(err) != repositories.ErrCodeNotFound { + msg := fmt.Sprintf("cannot load send schedule [%s] for phone [%s]", *phone.MessageSendScheduleID, phone.ID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + } + + if schedule != nil { + ctxLogger.Info(fmt.Sprintf("loaded [%T] with ID [%s] for phone [%s]", schedule, schedule.ID, phone.ID)) + } + + if err = service.phoneNotificationRepository.Schedule(ctx, phone.MessagesPerMinute, schedule, notification); err != nil { msg := fmt.Sprintf("cannot schedule notification for message [%s] to phone [%s]", params.MessageID, phone.ID) return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) } @@ -191,11 +242,57 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P return service.tracer.WrapErrorSpan(span, err) } - ctxLogger.Info(fmt.Sprintf("message with id [%s] notification scheduled for [%s] with id [%s]", params.MessageID, notification.ScheduledAt, notification.ID)) + ctxLogger.Info(fmt.Sprintf( + "message with id [%s] notification scheduled for [%s] with id [%s] with phone schedule ID [%s]", + params.MessageID, + notification.ScheduledAt, + notification.ID, + phone.MessageSendScheduleID, + )) + return nil +} + +func (service *PhoneNotificationService) scheduleExact( + ctx context.Context, + span trace.Span, + ctxLogger telemetry.Logger, + params *PhoneNotificationScheduleParams, + phone *entities.Phone, + notification *entities.PhoneNotification, +) error { + scheduledAt := *params.ScheduledSendTime + if scheduledAt.Before(time.Now().UTC()) { + scheduledAt = time.Now().UTC() + } + notification.ScheduledAt = scheduledAt + + if err := service.phoneNotificationRepository.ScheduleExact(ctx, notification); err != nil { + msg := fmt.Sprintf("cannot schedule exact notification for message [%s] to phone [%s]", params.MessageID, phone.ID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if err := service.dispatchMessageNotificationScheduled(ctx, params, notification); err != nil { + ctxLogger.Error(err) + } + + if err := service.dispatchMessageNotificationSend(ctx, params.Source, notification); err != nil { + return service.tracer.WrapErrorSpan(span, err) + } + + ctxLogger.Info(fmt.Sprintf( + "message with id [%s] exact notification scheduled for [%s] with id [%s]", + params.MessageID, + notification.ScheduledAt, + notification.ID, + )) return nil } -func (service *PhoneNotificationService) dispatchMessageNotificationSend(ctx context.Context, source string, notification *entities.PhoneNotification) error { +func (service *PhoneNotificationService) dispatchMessageNotificationSend( + ctx context.Context, + source string, + notification *entities.PhoneNotification, +) error { event, err := service.createMessageNotificationSendEvent(source, &events.MessageNotificationSendPayload{ MessageID: notification.MessageID, UserID: notification.UserID, @@ -213,7 +310,11 @@ func (service *PhoneNotificationService) dispatchMessageNotificationSend(ctx con return nil } -func (service *PhoneNotificationService) dispatchMessageNotificationScheduled(ctx context.Context, params *PhoneNotificationScheduleParams, notification *entities.PhoneNotification) error { +func (service *PhoneNotificationService) dispatchMessageNotificationScheduled( + ctx context.Context, + params *PhoneNotificationScheduleParams, + notification *entities.PhoneNotification, +) error { event, err := service.createMessageNotificationScheduledEvent(params.Source, &events.MessageNotificationScheduledPayload{ MessageID: notification.MessageID, Owner: params.Owner, @@ -258,7 +359,12 @@ func (service *PhoneNotificationService) handleNotificationFailed(ctx context.Co return nil } -func (service *PhoneNotificationService) handleNotificationSent(ctx context.Context, phone *entities.Phone, result string, params *PhoneNotificationSendParams) error { +func (service *PhoneNotificationService) handleNotificationSent( + ctx context.Context, + phone *entities.Phone, + result string, + params *PhoneNotificationSendParams, +) error { ctx, span := service.tracer.Start(ctx) defer span.End() @@ -279,15 +385,26 @@ func (service *PhoneNotificationService) handleNotificationSent(ctx context.Cont return nil } -func (service *PhoneNotificationService) createMessageNotificationScheduledEvent(source string, payload *events.MessageNotificationScheduledPayload) (cloudevents.Event, error) { +func (service *PhoneNotificationService) createMessageNotificationScheduledEvent( + source string, + payload *events.MessageNotificationScheduledPayload, +) (cloudevents.Event, error) { return service.createEvent(events.EventTypeMessageNotificationScheduled, source, payload) } -func (service *PhoneNotificationService) createMessageNotificationSendEvent(source string, payload *events.MessageNotificationSendPayload) (cloudevents.Event, error) { +func (service *PhoneNotificationService) createMessageNotificationSendEvent( + source string, + payload *events.MessageNotificationSendPayload, +) (cloudevents.Event, error) { return service.createEvent(events.EventTypeMessageNotificationSend, source, payload) } -func (service *PhoneNotificationService) createMessageNotificationSentEvent(source string, phone *entities.Phone, fcmMessageID string, params *PhoneNotificationSendParams) (cloudevents.Event, error) { +func (service *PhoneNotificationService) createMessageNotificationSentEvent( + source string, + phone *entities.Phone, + fcmMessageID string, + params *PhoneNotificationSendParams, +) (cloudevents.Event, error) { event := cloudevents.NewEvent() event.SetSource(source) @@ -314,7 +431,11 @@ func (service *PhoneNotificationService) createMessageNotificationSentEvent(sour return event, nil } -func (service *PhoneNotificationService) createMessageNotificationFailedEvent(source string, errorMessage string, params *PhoneNotificationSendParams) (cloudevents.Event, error) { +func (service *PhoneNotificationService) createMessageNotificationFailedEvent( + source string, + errorMessage string, + params *PhoneNotificationSendParams, +) (cloudevents.Event, error) { event := cloudevents.NewEvent() event.SetSource(source) @@ -339,7 +460,11 @@ func (service *PhoneNotificationService) createMessageNotificationFailedEvent(so return event, nil } -func (service *PhoneNotificationService) updateStatus(ctx context.Context, notificationID uuid.UUID, status entities.PhoneNotificationStatus) { +func (service *PhoneNotificationService) updateStatus( + ctx context.Context, + notificationID uuid.UUID, + status entities.PhoneNotificationStatus, +) { ctx, span := service.tracer.Start(ctx) defer span.End() @@ -347,9 +472,9 @@ func (service *PhoneNotificationService) updateStatus(ctx context.Context, notif err := service.phoneNotificationRepository.UpdateStatus(ctx, notificationID, status) if err != nil { - msg := fmt.Sprintf("cannot update status of notificaiton with id [%s] to [%s]", notificationID, status) + msg := fmt.Sprintf("cannot update status of notification with id [%s] to [%s]", notificationID, status) ctxLogger.Error(stacktrace.Propagate(err, msg)) } - ctxLogger.Info(fmt.Sprintf("updated status of notificaiton with id [%s] to [%s]", notificationID, status)) + ctxLogger.Info(fmt.Sprintf("updated status of notification with id [%s] to [%s]", notificationID, status)) } diff --git a/api/pkg/services/phone_service.go b/api/pkg/services/phone_service.go index df8e2104..ae863d32 100644 --- a/api/pkg/services/phone_service.go +++ b/api/pkg/services/phone_service.go @@ -56,6 +56,20 @@ func (service *PhoneService) DeleteAllForUser(ctx context.Context, userID entiti return nil } +// NullifyScheduleID sets MessageSendScheduleID to NULL for all phones referencing the given schedule. +func (service *PhoneService) NullifyScheduleID(ctx context.Context, userID entities.UserID, scheduleID uuid.UUID) error { + ctx, span := service.tracer.Start(ctx) + defer span.End() + + if err := service.repository.NullifyScheduleID(ctx, userID, scheduleID); err != nil { + msg := fmt.Sprintf("cannot nullify schedule ID [%s] for user [%s]", scheduleID, userID) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + service.tracer.CtxLogger(service.logger, span).Info(fmt.Sprintf("nullified schedule ID [%s] on phones for user [%s]", scheduleID, userID)) + return nil +} + // Index fetches the heartbeats for a phone number func (service *PhoneService) Index(ctx context.Context, authUser entities.AuthContext, params repositories.IndexParams) (*[]entities.Phone, error) { ctx, span := service.tracer.Start(ctx) @@ -91,6 +105,7 @@ type PhoneUpsertParams struct { MessageExpirationDuration *time.Duration MissedCallAutoReply *string SIM entities.SIM + MessageSendScheduleID *uuid.UUID Source string UserID entities.UserID } @@ -105,12 +120,13 @@ func (service *PhoneService) Upsert(ctx context.Context, params *PhoneUpsertPara phone, err := service.repository.Load(ctx, params.UserID, phonenumbers.Format(params.PhoneNumber, phonenumbers.E164)) if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { return service.createPhone(ctx, &PhoneFCMTokenParams{ - Source: params.Source, - PhoneNumber: params.PhoneNumber, - PhoneAPIKeyID: nil, - UserID: params.UserID, - FcmToken: params.FcmToken, - SIM: params.SIM, + Source: params.Source, + PhoneNumber: params.PhoneNumber, + PhoneAPIKeyID: nil, + UserID: params.UserID, + FcmToken: params.FcmToken, + SIM: params.SIM, + MessageSendScheduleID: params.MessageSendScheduleID, }) } @@ -126,12 +142,13 @@ func (service *PhoneService) Upsert(ctx context.Context, params *PhoneUpsertPara ctxLogger.Info(fmt.Sprintf("phone updated with id [%s] in the phone repository for user [%s]", phone.ID, phone.UserID)) return phone, service.dispatchPhoneUpdatedEvent(ctx, phone, &PhoneFCMTokenParams{ - Source: params.Source, - PhoneNumber: params.PhoneNumber, - PhoneAPIKeyID: nil, - UserID: params.UserID, - FcmToken: params.FcmToken, - SIM: params.SIM, + Source: params.Source, + PhoneNumber: params.PhoneNumber, + PhoneAPIKeyID: nil, + UserID: params.UserID, + FcmToken: params.FcmToken, + SIM: params.SIM, + MessageSendScheduleID: params.MessageSendScheduleID, }) } @@ -201,12 +218,13 @@ func (service *PhoneService) Delete(ctx context.Context, source string, userID e // PhoneFCMTokenParams are parameters for upserting an entities.Phone type PhoneFCMTokenParams struct { - Source string - PhoneNumber *phonenumbers.PhoneNumber - PhoneAPIKeyID *uuid.UUID - UserID entities.UserID - FcmToken *string - SIM entities.SIM + Source string + PhoneNumber *phonenumbers.PhoneNumber + PhoneAPIKeyID *uuid.UUID + UserID entities.UserID + FcmToken *string + SIM entities.SIM + MessageSendScheduleID *uuid.UUID } // UpsertFCMToken the FCM token for an entities.Phone @@ -251,6 +269,7 @@ func (service *PhoneService) createPhone(ctx context.Context, params *PhoneFCMTo MaxSendAttempts: 2, SIM: params.SIM, MissedCallAutoReply: nil, + MessageSendScheduleID: params.MessageSendScheduleID, PhoneNumber: phonenumbers.Format(params.PhoneNumber, phonenumbers.E164), CreatedAt: time.Now().UTC(), UpdatedAt: time.Now().UTC(), @@ -294,6 +313,7 @@ func (service *PhoneService) update(phone *entities.Phone, params *PhoneUpsertPa } phone.SIM = params.SIM + phone.MessageSendScheduleID = params.MessageSendScheduleID return phone } diff --git a/api/pkg/services/user_service.go b/api/pkg/services/user_service.go index 731f50a9..20c924b4 100644 --- a/api/pkg/services/user_service.go +++ b/api/pkg/services/user_service.go @@ -3,13 +3,13 @@ package services import ( "context" "fmt" + "io" + "net/http" "time" "firebase.google.com/go/auth" - - "github.com/NdoleStudio/httpsms/pkg/events" - "github.com/NdoleStudio/httpsms/pkg/emails" + "github.com/NdoleStudio/httpsms/pkg/events" "github.com/NdoleStudio/lemonsqueezy-go" "github.com/NdoleStudio/httpsms/pkg/repositories" @@ -29,9 +29,9 @@ type UserService struct { mailer emails.Mailer repository repositories.UserRepository dispatcher *EventDispatcher - marketingService *MarketingService authClient *auth.Client lemonsqueezyClient *lemonsqueezy.Client + httpClient *http.Client } // NewUserService creates a new UserService @@ -41,26 +41,98 @@ func NewUserService( repository repositories.UserRepository, mailer emails.Mailer, emailFactory emails.UserEmailFactory, - marketingService *MarketingService, lemonsqueezyClient *lemonsqueezy.Client, dispatcher *EventDispatcher, authClient *auth.Client, + httpClient *http.Client, ) (s *UserService) { return &UserService{ logger: logger.WithService(fmt.Sprintf("%T", s)), tracer: tracer, mailer: mailer, - marketingService: marketingService, emailFactory: emailFactory, repository: repository, dispatcher: dispatcher, authClient: authClient, lemonsqueezyClient: lemonsqueezyClient, + httpClient: httpClient, + } +} + +// GetSubscriptionPayments fetches the subscription payments for an entities.User +func (service *UserService) GetSubscriptionPayments(ctx context.Context, userID entities.UserID) (invoices []lemonsqueezy.ApiResponseData[lemonsqueezy.SubscriptionInvoiceAttributes, lemonsqueezy.APIResponseRelationshipsSubscriptionInvoice], err error) { + ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) + defer span.End() + + user, err := service.repository.Load(ctx, userID) + if err != nil { + msg := fmt.Sprintf("could not get [%T] with with ID [%s]", user, userID) + return invoices, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + if user.SubscriptionID == nil { + ctxLogger.Info(fmt.Sprintf("no subscription ID found for [%T] with ID [%s], returning empty invoices", user, user.ID)) + return invoices, nil + } + + ctxLogger.Info(fmt.Sprintf("fetching subscription payments for [%T] with ID [%s] and subscription [%s]", user, user.ID, *user.SubscriptionID)) + invoicesResponse, _, err := service.lemonsqueezyClient.SubscriptionInvoices.List(ctx, map[string]string{"filter[subscription_id]": *user.SubscriptionID}) + if err != nil { + msg := fmt.Sprintf("could not get invoices for subscription [%s] for [%T] with with ID [%s]", *user.SubscriptionID, user, user.ID) + return invoices, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + ctxLogger.Info(fmt.Sprintf("fetched [%d] payments for [%T] with ID [%s] and subscription ID [%s]", len(invoicesResponse.Data), user, user.ID, *user.SubscriptionID)) + return invoicesResponse.Data, nil +} + +// UserInvoiceGenerateParams are parameters for generating a subscription payment invoice +type UserInvoiceGenerateParams struct { + UserID entities.UserID + SubscriptionInvoiceID string + Name string + Address string + City string + State string + Country string + ZipCode string + Notes string +} + +// GenerateReceipt generates a receipt for a subscription payment. +func (service *UserService) GenerateReceipt(ctx context.Context, params *UserInvoiceGenerateParams) (io.Reader, error) { + ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) + defer span.End() + + payload := map[string]string{ + "name": params.Name, + "address": params.Address, + "city": params.City, + "state": params.State, + "country": params.Country, + "zip_code": params.ZipCode, + "notes": params.Notes, + "locale": "en", } + + invoice, _, err := service.lemonsqueezyClient.SubscriptionInvoices.Generate(ctx, params.SubscriptionInvoiceID, payload) + if err != nil { + msg := fmt.Sprintf("could not generate subscription payment invoice user with ID [%s] and subscription invoice ID [%s]", params.UserID, params.SubscriptionInvoiceID) + return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + response, err := service.httpClient.Get(invoice.Meta.Urls.DownloadInvoice) + if err != nil { + msg := fmt.Sprintf("could not download subscription payment invoice for user with ID [%s] and subscription invoice ID [%s]", params.UserID, params.SubscriptionInvoiceID) + return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } + + ctxLogger.Info(fmt.Sprintf("generated subscription payment invoice for user with ID [%s] and subscription invoice ID [%s]", params.UserID, params.SubscriptionInvoiceID)) + return response.Body, nil } // Get fetches or creates an entities.User -func (service *UserService) Get(ctx context.Context, authUser entities.AuthContext) (*entities.User, error) { +func (service *UserService) Get(ctx context.Context, source string, authUser entities.AuthContext) (*entities.User, error) { ctx, span := service.tracer.Start(ctx) defer span.End() @@ -71,12 +143,33 @@ func (service *UserService) Get(ctx context.Context, authUser entities.AuthConte } if isNew { - service.marketingService.AddToList(ctx, user) + service.dispatchUserCreatedEvent(ctx, source, user) } return user, nil } +func (service *UserService) dispatchUserCreatedEvent(ctx context.Context, source string, user *entities.User) { + ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) + defer span.End() + + event, err := service.createEvent(events.UserAccountCreated, source, &events.UserAccountCreatedPayload{ + UserID: user.ID, + Timestamp: time.Now().UTC(), + }) + if err != nil { + msg := fmt.Sprintf("cannot create event [%s] for user [%s]", events.UserAccountCreated, user.ID) + ctxLogger.Error(stacktrace.Propagate(err, msg)) + return + } + + if err = service.dispatcher.Dispatch(ctx, event); err != nil { + msg := fmt.Sprintf("cannot dispatch [%s] event for user [%s]", event.Type(), user.ID) + ctxLogger.Error(stacktrace.Propagate(err, msg)) + return + } +} + // GetByID fetches an entities.User func (service *UserService) GetByID(ctx context.Context, userID entities.UserID) (*entities.User, error) { ctx, span, _ := service.tracer.StartWithLogger(ctx, service.logger) @@ -98,7 +191,7 @@ type UserUpdateParams struct { } // Update an entities.User -func (service *UserService) Update(ctx context.Context, authUser entities.AuthContext, params UserUpdateParams) (*entities.User, error) { +func (service *UserService) Update(ctx context.Context, source string, authUser entities.AuthContext, params UserUpdateParams) (*entities.User, error) { ctx, span := service.tracer.Start(ctx) defer span.End() @@ -111,7 +204,7 @@ func (service *UserService) Update(ctx context.Context, authUser entities.AuthCo } if isNew { - service.marketingService.AddToList(ctx, user) + service.dispatchUserCreatedEvent(ctx, source, user) } user.Timezone = params.Timezone.String() @@ -218,6 +311,7 @@ func (service *UserService) Delete(ctx context.Context, source string, userID en event, err := service.createEvent(events.UserAccountDeleted, source, &events.UserAccountDeletedPayload{ UserID: userID, + UserEmail: user.Email, Timestamp: time.Now().UTC(), }) if err != nil { diff --git a/api/pkg/services/webhook_service.go b/api/pkg/services/webhook_service.go index d75bf500..e4dd0a7b 100644 --- a/api/pkg/services/webhook_service.go +++ b/api/pkg/services/webhook_service.go @@ -11,6 +11,7 @@ import ( "sync" "time" + "github.com/avast/retry-go/v5" "github.com/pkg/errors" "github.com/gofiber/fiber/v2" @@ -21,7 +22,7 @@ import ( "github.com/NdoleStudio/httpsms/pkg/repositories" "github.com/NdoleStudio/httpsms/pkg/telemetry" cloudevents "github.com/cloudevents/sdk-go/v2" - "github.com/golang-jwt/jwt" + "github.com/golang-jwt/jwt/v5" "github.com/google/uuid" "github.com/lib/pq" "github.com/palantir/stacktrace" @@ -210,37 +211,52 @@ func (service *WebhookService) sendNotification(ctx context.Context, event cloud ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) defer span.End() - requestCtx, cancel := context.WithTimeout(ctx, 10*time.Second) - defer cancel() + attempts := 0 + err := retry.New(retry.Attempts(2)).Do(func() error { + attempts++ - request, err := service.createRequest(requestCtx, event, webhook) - if err != nil { - msg := fmt.Sprintf("cannot create [%s] event to webhook [%s] for user [%s]", event.Type(), webhook.URL, webhook.UserID) - ctxLogger.Error(service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))) - return - } + requestCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() - response, err := service.client.Do(request) - if err != nil { - ctxLogger.Warn(stacktrace.Propagate(err, fmt.Sprintf("cannot send [%s] event to webhook [%s] for user [%s]", event.Type(), webhook.URL, webhook.UserID))) - service.handleWebhookSendFailed(ctx, event, webhook, owner, err, nil) - return - } + request, err := service.createRequest(requestCtx, event, webhook) + if err != nil { + msg := fmt.Sprintf("cannot create [%s] event to webhook [%s] for user [%s] after [%d] attempts", event.Type(), webhook.URL, webhook.UserID, attempts) + return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) + } - defer func() { - err = response.Body.Close() + response, err := service.client.Do(request) if err != nil { - ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot close response body for [%s] event with ID [%s]", event.Type(), event.ID()))) + ctxLogger.Warn(stacktrace.Propagate(err, fmt.Sprintf("cannot send [%s] event to webhook [%s] for user [%s] after [%d] attempts", event.Type(), webhook.URL, webhook.UserID, attempts))) + if attempts == 1 { + return err + } + service.handleWebhookSendFailed(ctx, event, webhook, owner, err, response) + return nil } - }() - if response.StatusCode >= 400 { - ctxLogger.Info(fmt.Sprintf("cannot send [%s] event to webhook [%s] for user [%s] with response code [%d]", event.Type(), webhook.URL, webhook.UserID, response.StatusCode)) - service.handleWebhookSendFailed(ctx, event, webhook, owner, stacktrace.NewError(http.StatusText(response.StatusCode)), response) - return - } + defer func() { + err = response.Body.Close() + if err != nil { + ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot close response body for [%s] event with ID [%s] after [%d] attempts", event.Type(), event.ID(), attempts))) + } + }() + + if response.StatusCode >= 400 { + ctxLogger.Info(fmt.Sprintf("cannot send [%s] event to webhook [%s] for user [%s] with response code [%d] after [%d] attempts", event.Type(), webhook.URL, webhook.UserID, response.StatusCode, attempts)) + if attempts == 1 { + return stacktrace.NewError(http.StatusText(response.StatusCode)) + } + service.handleWebhookSendFailed(ctx, event, webhook, owner, stacktrace.NewError(http.StatusText(response.StatusCode)), response) + return nil + } - ctxLogger.Info(fmt.Sprintf("sent webhook to url [%s] for event [%s] with ID [%s] and response code [%d]", webhook.URL, event.Type(), event.ID(), response.StatusCode)) + ctxLogger.Info(fmt.Sprintf("sent webhook to url [%s] for event [%s] with ID [%s] and response code [%d]", webhook.URL, event.Type(), event.ID(), response.StatusCode)) + return nil + }) + if err != nil { + msg := fmt.Sprintf("cannot handle [%s] event to webhook [%s] for user [%s] after [%d] attempts", event.Type(), webhook.URL, webhook.UserID, attempts) + ctxLogger.Error(service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))) + } } func (service *WebhookService) createRequest(ctx context.Context, event cloudevents.Event, webhook *entities.Webhook) (*http.Request, error) { @@ -323,12 +339,12 @@ func (service *WebhookService) getPayload(ctxLogger telemetry.Logger, event clou } func (service *WebhookService) getAuthToken(webhook *entities.Webhook) (string, error) { - token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.StandardClaims{ - Audience: webhook.URL, - ExpiresAt: time.Now().UTC().Add(10 * time.Minute).Unix(), - IssuedAt: time.Now().UTC().Unix(), + token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.RegisteredClaims{ + Audience: []string{webhook.URL}, + ExpiresAt: jwt.NewNumericDate(time.Now().UTC().Add(10 * time.Minute)), + IssuedAt: jwt.NewNumericDate(time.Now().UTC()), Issuer: "api.httpsms.com", - NotBefore: time.Now().UTC().Add(-10 * time.Minute).Unix(), + NotBefore: jwt.NewNumericDate(time.Now().UTC().Add(-10 * time.Minute)), Subject: string(webhook.UserID), }) return token.SignedString([]byte(webhook.SigningKey)) diff --git a/api/pkg/validators/bulk_message_handler_validator.go b/api/pkg/validators/bulk_message_handler_validator.go index 4c31ea51..f17f6adb 100644 --- a/api/pkg/validators/bulk_message_handler_validator.go +++ b/api/pkg/validators/bulk_message_handler_validator.go @@ -12,6 +12,7 @@ import ( "github.com/xuri/excelize/v2" + "github.com/NdoleStudio/httpsms/pkg/cache" "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/repositories" "github.com/NdoleStudio/httpsms/pkg/requests" @@ -30,6 +31,7 @@ type BulkMessageHandlerValidator struct { userService *services.UserService logger telemetry.Logger tracer telemetry.Tracer + cache cache.Cache } // NewBulkMessageHandlerValidator creates a new handlers.BulkMessageHandlerValidator validator @@ -38,17 +40,19 @@ func NewBulkMessageHandlerValidator( tracer telemetry.Tracer, phoneService *services.PhoneService, userService *services.UserService, + appCache cache.Cache, ) (v *BulkMessageHandlerValidator) { return &BulkMessageHandlerValidator{ logger: logger.WithService(fmt.Sprintf("%T", v)), tracer: tracer, userService: userService, phoneService: phoneService, + cache: appCache, } } // ValidateStore validates the requests.BillingUsageHistory request -func (v *BulkMessageHandlerValidator) ValidateStore(ctx context.Context, userID entities.UserID, header *multipart.FileHeader) ([]*requests.BulkMessage, url.Values) { +func (v *BulkMessageHandlerValidator) ValidateStore(ctx context.Context, userID entities.UserID, header *multipart.FileHeader) ([]*requests.BulkMessage, string, *time.Location, url.Values) { ctx, span, ctxLogger := v.tracer.StartWithLogger(ctx, v.logger) defer span.End() @@ -57,54 +61,56 @@ func (v *BulkMessageHandlerValidator) ValidateStore(ctx context.Context, userID result := url.Values{} result.Add("document", "Cannot load your account. Please try again later or contact support.") ctxLogger.Error(v.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot load user [%s]", userID)))) - return nil, result + return nil, "", nil, result } - messages, result := v.parseFile(ctxLogger, user, header) + messages, fileType, result := v.parseFile(ctxLogger, user, header) if len(result) != 0 { - return messages, result + return messages, fileType, user.Location(), result } if len(messages) == 0 { result.Add("document", "The uploaded file doesn't contain any valid records. Make sure you are using the official httpSMS template.") - return messages, result + return messages, fileType, user.Location(), result } if len(messages) > 1000 { result.Add("document", "The uploaded file must contain less than 1000 records.") - return messages, result + return messages, fileType, user.Location(), result } for index, message := range messages { messages[index] = message.Sanitize() } - result = v.validateMessages(messages) + result = v.validateMessages(ctx, messages, user.Location()) if len(result) != 0 { - return messages, result + return messages, fileType, user.Location(), result } result = v.validateOwners(ctx, userID, messages) if len(result) != 0 { - return messages, result + return messages, fileType, user.Location(), result } - return messages, result + return messages, fileType, user.Location(), result } -func (v *BulkMessageHandlerValidator) parseFile(ctxLogger telemetry.Logger, user *entities.User, header *multipart.FileHeader) ([]*requests.BulkMessage, url.Values) { +func (v *BulkMessageHandlerValidator) parseFile(ctxLogger telemetry.Logger, user *entities.User, header *multipart.FileHeader) ([]*requests.BulkMessage, string, url.Values) { if header.Header.Get("Content-Type") == "text/csv" || strings.HasSuffix(header.Filename, ".csv") { - return v.parseCSV(ctxLogger, user, header) + messages, result := v.parseCSV(ctxLogger, user, header) + return messages, "csv", result } if header.Header.Get("Content-Type") == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || strings.HasSuffix(header.Filename, ".xlsx") { - return v.parseXlsx(ctxLogger, user, header) + messages, result := v.parseXlsx(ctxLogger, user, header) + return messages, "xls", result } ctxLogger.Error(stacktrace.NewError(fmt.Sprintf("cannot parse file [%s] for user [%s] with content type [%s]", header.Filename, user.ID, header.Header.Get("Content-Type")))) result := url.Values{} result.Add("document", fmt.Sprintf("The file [%s] is not a valid CSV or Excel file.", header.Filename)) - return nil, result + return nil, "", result } func (v *BulkMessageHandlerValidator) parseXlsx(ctxLogger telemetry.Logger, user *entities.User, header *multipart.FileHeader) ([]*requests.BulkMessage, url.Values) { @@ -119,6 +125,7 @@ func (v *BulkMessageHandlerValidator) parseXlsx(ctxLogger telemetry.Logger, user result.Add("document", fmt.Sprintf("Cannot parse the uploaded excel file with name [%s].", header.Filename)) return nil, result } + defer excel.Close() rows, err := excel.GetRows(excel.GetSheetName(0)) if err != nil { @@ -133,36 +140,35 @@ func (v *BulkMessageHandlerValidator) parseXlsx(ctxLogger telemetry.Logger, user continue } - var sendAt *time.Time + var sendTimeRaw string if len(row) > 3 && strings.TrimSpace(row[3]) != "" { ctxLogger.Info(fmt.Sprintf("excel time = [%s]", row[3])) - sendAt, err = v.convertExcelTime(user, row[3]) - if err != nil { + msg := &requests.BulkMessage{SendTime: strings.TrimSpace(row[3])} + sendAt := msg.GetSendTime(user.Location()) + if sendAt == nil { result.Add("document", fmt.Sprintf("Row [%d]: The SendTime [%s] is not in the correct format e.g [2006-01-02T15:04:05] where 2006 is the year, 01 is January, 02 is the second day of the month and the time is 15:04:05", index+1, row[3])) return nil, result } + sendTimeRaw = sendAt.Format(time.RFC3339) + } + + var attachmentURLs string + if len(row) > 4 && strings.TrimSpace(row[4]) != "" { + attachmentURLs = strings.TrimSpace(row[4]) } messages = append(messages, &requests.BulkMessage{ FromPhoneNumber: strings.TrimSpace(row[0]), ToPhoneNumber: strings.TrimSpace(row[1]), Content: row[2], - SendTime: sendAt, + SendTime: sendTimeRaw, + AttachmentURLs: attachmentURLs, }) } return messages, url.Values{} } -func (v *BulkMessageHandlerValidator) convertExcelTime(user *entities.User, value string) (*time.Time, error) { - t, err := time.ParseInLocation("2006-01-02T15:04:05", value, user.Location()) - if err != nil { - return nil, stacktrace.Propagate(err, fmt.Sprintf("cannot parse excel time [%s] as [%T]", value, t)) - } - - return &t, nil -} - func (v *BulkMessageHandlerValidator) parseBytes(ctxLogger telemetry.Logger, userID entities.UserID, header *multipart.FileHeader) ([]byte, url.Values) { result := url.Values{} @@ -202,16 +208,46 @@ func (v *BulkMessageHandlerValidator) parseCSV(ctxLogger telemetry.Logger, user var messages []*requests.BulkMessage if err := csvutil.Unmarshal(content, &messages); err != nil { ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot unmarshall contents [%s] into type [%T] for file [%s] and user [%s]", content, messages, header.Filename, user.ID))) - result.Add("document", fmt.Sprintf("Cannot read the conents of the uploaded file [%s].", header.Filename)) + result.Add("document", fmt.Sprintf("Cannot read the contents of the uploaded file [%s].", header.Filename)) return nil, result } return messages, url.Values{} } -func (v *BulkMessageHandlerValidator) validateMessages(messages []*requests.BulkMessage) url.Values { +func (v *BulkMessageHandlerValidator) validateMessages(_ context.Context, messages []*requests.BulkMessage, location *time.Location) url.Values { result := url.Values{} for index, message := range messages { + + if message.AttachmentURLs != "" { + urls := strings.Split(message.AttachmentURLs, ",") + + validAttachmentCount := 0 + for _, u := range urls { + if strings.TrimSpace(u) != "" { + validAttachmentCount++ + } + } + + if validAttachmentCount > 10 { + result.Add("document", fmt.Sprintf("Row [%d]: You cannot attach more than 10 files per message.", index+2)) + } + + for _, u := range urls { + cleanURL := strings.TrimSpace(u) + if cleanURL == "" { + continue + } + + parsedURL, err := url.ParseRequestURI(cleanURL) + if err != nil || parsedURL.Scheme == "" || parsedURL.Host == "" { + result.Add("document", fmt.Sprintf("Row [%d]: The attachment URL [%s] has an invalid url format.", index+2, cleanURL)) + } else if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" { + result.Add("document", fmt.Sprintf("Row [%d]: The attachment URL [%s] must use http or https.", index+2, cleanURL)) + } + } + } + if _, err := phonenumbers.Parse(message.FromPhoneNumber, phonenumbers.UNKNOWN_REGION); err != nil { result.Add("document", fmt.Sprintf("Row [%d]: The FromPhoneNumber [%s] is not a valid E.164 phone number", index+2, message.FromPhoneNumber)) } @@ -224,8 +260,13 @@ func (v *BulkMessageHandlerValidator) validateMessages(messages []*requests.Bulk result.Add("document", fmt.Sprintf("Row [%d]: The message content must be less than 1024 characters.", index+2)) } - if message.SendTime != nil && message.SendTime.After(time.Now().Add(24*time.Hour)) { - result.Add("document", fmt.Sprintf("Row [%d]: The SendTime [%s] cannot be more than 24 hours in the future.", index+2, message.SendTime.Format(time.RFC3339))) + if strings.TrimSpace(message.SendTime) != "" { + sendTime := message.GetSendTime(location) + if sendTime == nil { + result.Add("document", fmt.Sprintf("Row [%d]: The SendTime [%s] is not a valid date format. Use RFC3339 (e.g. 2023-11-11T02:10:01Z) or YYYY-MM-DDTHH:MM:SS.", index+2, message.SendTime)) + } else if sendTime.After(time.Now().Add(420 * time.Hour)) { + result.Add("document", fmt.Sprintf("Row [%d]: The SendTime [%s] cannot be more than 20 days (420 hours) in the future.", index+2, sendTime.Format(time.RFC3339))) + } } } return result diff --git a/api/pkg/validators/message_handler_validator.go b/api/pkg/validators/message_handler_validator.go index 78cfd024..da6a7a1d 100644 --- a/api/pkg/validators/message_handler_validator.go +++ b/api/pkg/validators/message_handler_validator.go @@ -2,10 +2,13 @@ package validators import ( "context" + "encoding/base64" "fmt" "net/url" "strings" + "time" + "github.com/NdoleStudio/httpsms/pkg/cache" "github.com/NdoleStudio/httpsms/pkg/repositories" "github.com/NdoleStudio/httpsms/pkg/services" "github.com/palantir/stacktrace" @@ -24,6 +27,7 @@ type MessageHandlerValidator struct { tracer telemetry.Tracer phoneService *services.PhoneService tokenValidator *TurnstileTokenValidator + cache cache.Cache } // NewMessageHandlerValidator creates a new handlers.MessageHandler validator @@ -32,15 +36,23 @@ func NewMessageHandlerValidator( tracer telemetry.Tracer, phoneService *services.PhoneService, tokenValidator *TurnstileTokenValidator, + appCache cache.Cache, ) (v *MessageHandlerValidator) { return &MessageHandlerValidator{ logger: logger.WithService(fmt.Sprintf("%T", v)), tracer: tracer, phoneService: phoneService, tokenValidator: tokenValidator, + cache: appCache, } } +const ( + maxAttachmentCount = 10 + maxAttachmentSize = (3 * 1024 * 1024) / 2 // 1.5 MB per attachment + maxTotalAttachmentSize = 3 * 1024 * 1024 // 3 MB total +) + // ValidateMessageReceive validates the requests.MessageReceive request func (validator MessageHandlerValidator) ValidateMessageReceive(_ context.Context, request requests.MessageReceive) url.Values { v := govalidator.New(govalidator.Options{ @@ -53,11 +65,12 @@ func (validator MessageHandlerValidator) ValidateMessageReceive(_ context.Contex "from": []string{ "required", }, - "content": []string{ - "required", - "min:1", - "max:2048", - }, + "content": func() []string { + if len(request.Attachments) > 0 { + return []string{"max:2048"} + } + return []string{"required", "min:1", "max:2048"} + }(), "sim": []string{ "required", "in:" + strings.Join([]string{ @@ -68,7 +81,54 @@ func (validator MessageHandlerValidator) ValidateMessageReceive(_ context.Contex }, }) - return v.ValidateStruct() + errors := v.ValidateStruct() + + if len(request.Attachments) > 0 { + attachmentErrors := validator.validateAttachments(request.Attachments) + for key, values := range attachmentErrors { + for _, value := range values { + errors.Add(key, value) + } + } + } + + return errors +} + +func (validator MessageHandlerValidator) validateAttachments(attachments []requests.MessageAttachment) url.Values { + errors := url.Values{} + allowedTypes := repositories.AllowedContentTypes() + + if len(attachments) > maxAttachmentCount { + errors.Add("attachments", fmt.Sprintf("attachment count [%d] exceeds maximum of [%d]", len(attachments), maxAttachmentCount)) + return errors + } + + totalSize := 0 + for i, attachment := range attachments { + if !allowedTypes[attachment.ContentType] { + errors.Add("attachments", fmt.Sprintf("attachment [%d] has unsupported content type [%s]", i, attachment.ContentType)) + continue + } + + decoded, err := base64.StdEncoding.DecodeString(attachment.Content) + if err != nil { + errors.Add("attachments", fmt.Sprintf("attachment [%d] has invalid base64 content", i)) + continue + } + + if len(decoded) > maxAttachmentSize { + errors.Add("attachments", fmt.Sprintf("attachment [%d] size [%d] exceeds maximum of [%d] bytes", i, len(decoded), maxAttachmentSize)) + } + + totalSize += len(decoded) + } + + if totalSize > maxTotalAttachmentSize { + errors.Add("attachments", fmt.Sprintf("total attachment size [%d] exceeds maximum of [%d] bytes", totalSize, maxTotalAttachmentSize)) + } + + return errors } // ValidateMessageSend validates the requests.MessageSend request @@ -92,6 +152,10 @@ func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context "required", phoneNumberRule, }, + "attachments": []string{ + "max:10", + multipleAttachmentURLRule, + }, "content": []string{ "required", "min:1", @@ -105,6 +169,10 @@ func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context return result } + if request.SendAt != nil && request.SendAt.After(time.Now().Add(480*time.Hour)) { + result.Add("send_at", "the scheduled time cannot be more than 20 days (480 hours) in the future") + } + _, err := validator.phoneService.Load(ctx, userID, request.From) if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { result.Add("from", fmt.Sprintf("no phone found with with 'from' number [%s]. install the android app on your phone to start sending messages", request.From)) @@ -138,6 +206,10 @@ func (validator MessageHandlerValidator) ValidateMessageBulkSend(ctx context.Con "required", phoneNumberRule, }, + "attachments": []string{ + "max:10", + multipleAttachmentURLRule, + }, "content": []string{ "required", "min:1", @@ -256,7 +328,7 @@ func (validator MessageHandlerValidator) ValidateMessageSearch(ctx context.Conte "min:0", }, "query": []string{ - "max:20", + "max:50", }, "token": []string{ "required", diff --git a/api/pkg/validators/message_send_schedule_handler_validator.go b/api/pkg/validators/message_send_schedule_handler_validator.go new file mode 100644 index 00000000..fa850de1 --- /dev/null +++ b/api/pkg/validators/message_send_schedule_handler_validator.go @@ -0,0 +1,165 @@ +package validators + +import ( + "context" + "fmt" + "net/url" + "sort" + "time" + + "github.com/NdoleStudio/httpsms/pkg/requests" + "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/thedevsaddam/govalidator" +) + +const maxWindowsPerDay = 6 + +// MessageSendScheduleHandlerValidator validates send schedule HTTP requests. +type MessageSendScheduleHandlerValidator struct { + validator + logger telemetry.Logger + tracer telemetry.Tracer +} + +// NewMessageSendScheduleHandlerValidator creates a new MessageSendScheduleHandlerValidator. +func NewMessageSendScheduleHandlerValidator( + logger telemetry.Logger, + tracer telemetry.Tracer, +) *MessageSendScheduleHandlerValidator { + return &MessageSendScheduleHandlerValidator{ + logger: logger.WithService(fmt.Sprintf("%T", &MessageSendScheduleHandlerValidator{})), + tracer: tracer, + } +} + +// ValidateStore validates a send schedule create or update request. +func (validator *MessageSendScheduleHandlerValidator) ValidateStore( + _ context.Context, + request requests.MessageSendScheduleStore, +) url.Values { + v := govalidator.New(govalidator.Options{ + Data: &request, + Rules: govalidator.MapData{ + "name": []string{"required", "min:2", "max:100"}, + "timezone": []string{"required", "min:2", "max:100"}, + }, + }) + + result := v.ValidateStruct() + validator.validateWindows(result, request.Windows) + + if request.Timezone != "" { + if _, err := time.LoadLocation(request.Timezone); err != nil { + result.Add("timezone", "The timezone must be a valid IANA timezone e.g Europe/London.") + } + } + + return result +} + +func (validator *MessageSendScheduleHandlerValidator) validateWindows( + result url.Values, + windows []requests.MessageSendScheduleWindow, +) { + if len(windows) == 0 { + result.Add("windows", "at least one active window is required") + return + } + + windowsPerDay := make(map[int]int) + + for index, item := range windows { + validator.validateDayOfWeek(result, index, item, windowsPerDay) + validator.validateStartMinute(result, index, item) + validator.validateEndMinute(result, index, item) + validator.validateWindowRange(result, index, item) + } + + validator.validateOverlappingWindows(result, windows) +} + +func (validator *MessageSendScheduleHandlerValidator) validateDayOfWeek( + result url.Values, + index int, + item requests.MessageSendScheduleWindow, + windowsPerDay map[int]int, +) { + if item.DayOfWeek < 0 || item.DayOfWeek > 6 { + result.Add("windows", fmt.Sprintf("windows[%d].day_of_week must be between 0 and 6", index)) + return + } + + windowsPerDay[item.DayOfWeek]++ + if windowsPerDay[item.DayOfWeek] > maxWindowsPerDay { + result.Add( + "windows", + fmt.Sprintf("day_of_week %d cannot have more than %d windows", item.DayOfWeek, maxWindowsPerDay), + ) + } +} + +func (validator *MessageSendScheduleHandlerValidator) validateStartMinute( + result url.Values, + index int, + item requests.MessageSendScheduleWindow, +) { + if item.StartMinute < 0 || item.StartMinute > 1439 { + result.Add("windows", fmt.Sprintf("windows[%d].start_minute must be between 0 and 1439", index)) + } +} + +func (validator *MessageSendScheduleHandlerValidator) validateEndMinute( + result url.Values, + index int, + item requests.MessageSendScheduleWindow, +) { + if item.EndMinute < 1 || item.EndMinute > 1440 { + result.Add("windows", fmt.Sprintf("windows[%d].end_minute must be between 1 and 1440", index)) + } +} + +func (validator *MessageSendScheduleHandlerValidator) validateWindowRange( + result url.Values, + index int, + item requests.MessageSendScheduleWindow, +) { + if item.EndMinute <= item.StartMinute { + result.Add("windows", fmt.Sprintf("windows[%d].end_minute must be greater than start_minute", index)) + } +} + +func (validator *MessageSendScheduleHandlerValidator) validateOverlappingWindows( + result url.Values, + windows []requests.MessageSendScheduleWindow, +) { + grouped := make(map[int][]requests.MessageSendScheduleWindow) + + for _, item := range windows { + if item.DayOfWeek < 0 || item.DayOfWeek > 6 { + continue + } + if item.EndMinute <= item.StartMinute { + continue + } + grouped[item.DayOfWeek] = append(grouped[item.DayOfWeek], item) + } + + for dayOfWeek, dayWindows := range grouped { + sort.Slice(dayWindows, func(i, j int) bool { + return dayWindows[i].StartMinute < dayWindows[j].StartMinute + }) + + for i := 1; i < len(dayWindows); i++ { + previous := dayWindows[i-1] + current := dayWindows[i] + + if current.StartMinute < previous.EndMinute { + result.Add( + "windows", + fmt.Sprintf("day_of_week %d contains overlapping windows", dayOfWeek), + ) + break + } + } + } +} diff --git a/api/pkg/validators/phone_handler_validator.go b/api/pkg/validators/phone_handler_validator.go index 2369214e..e9d4274e 100644 --- a/api/pkg/validators/phone_handler_validator.go +++ b/api/pkg/validators/phone_handler_validator.go @@ -7,27 +7,31 @@ import ( "strings" "github.com/NdoleStudio/httpsms/pkg/entities" - "github.com/NdoleStudio/httpsms/pkg/requests" + "github.com/NdoleStudio/httpsms/pkg/services" "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/google/uuid" "github.com/thedevsaddam/govalidator" ) // PhoneHandlerValidator validates models used in handlers.PhoneHandler type PhoneHandlerValidator struct { validator - logger telemetry.Logger - tracer telemetry.Tracer + logger telemetry.Logger + tracer telemetry.Tracer + scheduleService *services.MessageSendScheduleService } // NewPhoneHandlerValidator creates a new handlers.PhoneHandler validator func NewPhoneHandlerValidator( logger telemetry.Logger, tracer telemetry.Tracer, + scheduleService *services.MessageSendScheduleService, ) (v *PhoneHandlerValidator) { return &PhoneHandlerValidator{ - logger: logger.WithService(fmt.Sprintf("%T", v)), - tracer: tracer, + logger: logger.WithService(fmt.Sprintf("%T", v)), + tracer: tracer, + scheduleService: scheduleService, } } @@ -56,7 +60,7 @@ func (validator *PhoneHandlerValidator) ValidateIndex(_ context.Context, request } // ValidateUpsert validates requests.PhoneUpsert -func (validator *PhoneHandlerValidator) ValidateUpsert(_ context.Context, request requests.PhoneUpsert) url.Values { +func (validator *PhoneHandlerValidator) ValidateUpsert(ctx context.Context, userID entities.UserID, request requests.PhoneUpsert) url.Values { v := govalidator.New(govalidator.Options{ Data: &request, Rules: govalidator.MapData{ @@ -84,16 +88,26 @@ func (validator *PhoneHandlerValidator) ValidateUpsert(_ context.Context, reques "min:60", "max:3600", }, + "message_send_schedule_id": []string{ + "uuid", + }, }, }) result := v.ValidateStruct() + if request.MaxSendAttempts > 0 && request.MessageExpirationSeconds == 0 { + result.Add("message_expiration_seconds", "message_expiration_seconds cannot be 0 when max_send_attempts is greater than 0") + } + if len(result) > 0 { return result } - if request.MaxSendAttempts > 0 && request.MessageExpirationSeconds == 0 { - result.Add("message_expiration_seconds", "message_expiration_seconds cannot be 0 when max_send_attempts is greater than 0") + if strings.TrimSpace(request.MessageSendScheduleID) != "" { + scheduleID, _ := uuid.Parse(strings.TrimSpace(request.MessageSendScheduleID)) + if _, err := validator.scheduleService.Load(ctx, userID, scheduleID); err != nil { + result.Add("message_send_schedule_id", "The message_send_schedule_id does not belong to the authenticated user or does not exist") + } } return result diff --git a/api/pkg/validators/user_handler_validator.go b/api/pkg/validators/user_handler_validator.go index 553a1cd8..4c05bd1b 100644 --- a/api/pkg/validators/user_handler_validator.go +++ b/api/pkg/validators/user_handler_validator.go @@ -5,26 +5,32 @@ import ( "fmt" "net/url" + "github.com/NdoleStudio/httpsms/pkg/entities" "github.com/NdoleStudio/httpsms/pkg/requests" + "github.com/NdoleStudio/httpsms/pkg/services" "github.com/NdoleStudio/httpsms/pkg/telemetry" + "github.com/palantir/stacktrace" "github.com/thedevsaddam/govalidator" ) // UserHandlerValidator validates models used in handlers.UserHandler type UserHandlerValidator struct { validator - logger telemetry.Logger - tracer telemetry.Tracer + logger telemetry.Logger + tracer telemetry.Tracer + service *services.UserService } // NewUserHandlerValidator creates a new handlers.UserHandler validator func NewUserHandlerValidator( logger telemetry.Logger, tracer telemetry.Tracer, + service *services.UserService, ) (v *UserHandlerValidator) { return &UserHandlerValidator{ - logger: logger.WithService(fmt.Sprintf("%T", v)), - tracer: tracer, + service: service, + logger: logger.WithService(fmt.Sprintf("%T", v)), + tracer: tracer, } } @@ -41,3 +47,83 @@ func (validator *UserHandlerValidator) ValidateUpdate(_ context.Context, request return v.ValidateStruct() } + +// ValidatePaymentInvoice validates the requests.UserPaymentInvoice request +func (validator *UserHandlerValidator) ValidatePaymentInvoice(ctx context.Context, userID entities.UserID, request requests.UserPaymentInvoice) url.Values { + ctx, span, ctxLogger := validator.tracer.StartWithLogger(ctx, validator.logger) + defer span.End() + + rules := govalidator.MapData{ + "name": []string{ + "required", + "min:1", + "max:100", + }, + "address": []string{ + "required", + "min:1", + "max:200", + }, + "city": []string{ + "required", + "min:1", + "max:100", + }, + "state": []string{ + "min:1", + "max:100", + }, + "country": []string{ + "required", + "len:2", + }, + "zip_code": []string{ + "required", + "min:1", + "max:20", + }, + "notes": []string{ + "max:1000", + }, + } + if request.Country == "CA" { + rules["state"] = []string{ + "required", + "in:AB,BC,MB,NB,NL,NS,NT,NU,ON,PE,QC,SK,YT", + } + } + + if request.Country == "US" { + rules["state"] = []string{ + "required", + "in:AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY", + } + } + + v := govalidator.New(govalidator.Options{ + Data: &request, + Rules: rules, + }) + + validationErrors := v.ValidateStruct() + if len(validationErrors) > 0 { + return validationErrors + } + + payments, err := validator.service.GetSubscriptionPayments(ctx, userID) + if err != nil { + msg := fmt.Sprintf("cannot get subscription payments for user with ID [%s]", userID) + ctxLogger.Error(validator.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))) + validationErrors.Add("subscriptionInvoiceID", "failed to validate subscription payment invoice ID") + return validationErrors + } + + for _, payment := range payments { + if payment.ID == request.SubscriptionInvoiceID { + return validationErrors + } + } + + validationErrors.Add("subscriptionInvoiceID", "failed to validate the subscription payment invoice ID") + return validationErrors +} diff --git a/api/pkg/validators/validator.go b/api/pkg/validators/validator.go index bc7111e8..1fcb716a 100644 --- a/api/pkg/validators/validator.go +++ b/api/pkg/validators/validator.go @@ -1,11 +1,15 @@ package validators import ( + "context" "fmt" + "net/http" "net/url" "regexp" "strings" + "time" + "github.com/NdoleStudio/httpsms/pkg/cache" "github.com/NdoleStudio/httpsms/pkg/events" "github.com/nyaruka/phonenumbers" @@ -19,6 +23,7 @@ const ( multiplePhoneNumberRule = "multiplePhoneNumber" contactPhoneNumberRule = "contactPhoneNumber" multipleContactPhoneNumberRule = "multipleContactPhoneNumber" + multipleAttachmentURLRule = "multipleAttachmentURL" multipleInRule = "multipleIn" webhookEventsRule = "webhookEvents" ) @@ -86,6 +91,21 @@ func init() { return nil }) + govalidator.AddCustomRule(multipleAttachmentURLRule, func(field string, rule string, message string, value interface{}) error { + attachments, ok := value.([]string) + if !ok { + return fmt.Errorf("The %s field must be an array of valid attachment URLs", field) + } + + for index, attachment := range attachments { + u, err := url.ParseRequestURI(attachment) + if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" { + return fmt.Errorf("The attachment %d with URL [%s] must be a valid URL e.g https://placehold.co/600x400", index, attachment) + } + } + return nil + }) + govalidator.AddCustomRule(multipleInRule, func(field string, rule string, message string, value interface{}) error { values, ok := value.([]string) if !ok { @@ -104,7 +124,7 @@ func init() { for index, item := range values { if !contains(item) { - return fmt.Errorf("the %s field in contains an invalid value [%s] at index [%d] ", field, item, index) + return fmt.Errorf("the %s field in contains an invalid value [%s] at index [%d]", field, item, index) } } @@ -160,3 +180,54 @@ func (validator *validator) ValidateUUID(ID string, name string) url.Values { return v.ValidateStruct() } + +func validateAttachmentURL(ctx context.Context, c cache.Cache, attachmentURL string) error { + cacheKey := "mms-url-validation:" + attachmentURL + + if cachedVal, err := c.Get(ctx, cacheKey); err == nil { + if cachedVal == "valid" { + return nil + } + return fmt.Errorf(cachedVal) + } + + client := &http.Client{ + Timeout: 5 * time.Second, + } + + req, err := http.NewRequest(http.MethodHead, attachmentURL, nil) + if err != nil { + errMsg := fmt.Sprintf("invalid url format") + saveToCache(ctx, c, cacheKey, errMsg) + return fmt.Errorf(errMsg) + } + + resp, err := client.Do(req) + if err != nil { + errMsg := fmt.Sprintf("could not reach the url") + saveToCache(ctx, c, cacheKey, errMsg) + return fmt.Errorf(errMsg) + } + defer resp.Body.Close() + + if resp.StatusCode < 200 || resp.StatusCode >= 400 { + errMsg := fmt.Sprintf("url returned an error status code: %d", resp.StatusCode) + saveToCache(ctx, c, cacheKey, errMsg) + return fmt.Errorf(errMsg) + } + + const maxSizeBytes = 1.5 * 1024 * 1024 + + if resp.ContentLength > int64(maxSizeBytes) { + errMsg := fmt.Sprintf("file size (%.2f MB) exceeds the 1.5 MB carrier limit", float64(resp.ContentLength)/(1024*1024)) + saveToCache(ctx, c, cacheKey, errMsg) + return fmt.Errorf(errMsg) + } + + saveToCache(ctx, c, cacheKey, "valid") + return nil +} + +func saveToCache(ctx context.Context, c cache.Cache, key string, value string) { + _ = c.Set(ctx, key, value, 15*time.Minute) +} diff --git a/docker-compose.yml b/docker-compose.yml index 16e885e9..ef63287d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.8" - services: postgres: image: postgres:alpine @@ -13,7 +11,7 @@ services: - "5435:5432" restart: on-failure healthcheck: - test: ["CMD-SHELL", "pg_isready", "-U", "dbusername", "-d", "httpsms"] + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] interval: 30s timeout: 60s retries: 5 diff --git a/tests/.env.test b/tests/.env.test new file mode 100644 index 00000000..5692e7fe --- /dev/null +++ b/tests/.env.test @@ -0,0 +1,33 @@ +ENV=production +GCP_PROJECT_ID=httpsms-test +USE_HTTP_LOGGER=true +ENTITLEMENT_ENABLED=false +EVENTS_QUEUE_TYPE=emulator +EVENTS_QUEUE_NAME=events-local +EVENTS_QUEUE_ENDPOINT=http://localhost:8000/v1/events +EVENTS_QUEUE_USER_API_KEY=system-user-api-key +EVENTS_QUEUE_USER_ID=system-user-id +FCM_ENDPOINT=http://wiremock:8080 +DATABASE_URL=postgresql://root@cockroachdb:26257/httpsms?sslmode=disable +DATABASE_URL_DEDICATED=postgresql://root@cockroachdb:26257/httpsms?sslmode=disable +DATABASE_MIGRATION_CONSTRAINT_FIX=1 +REDIS_URL=redis://@redis:6379 +APP_PORT=8000 +APP_NAME=httpSMS +APP_URL=http://localhost:8000 +SWAGGER_HOST=localhost:8000 +SMTP_FROM_NAME=httpSMS +SMTP_FROM_EMAIL=test@httpsms.com +SMTP_USERNAME= +SMTP_PASSWORD= +SMTP_HOST=localhost +SMTP_PORT=2525 +PUSHER_APP_ID= +PUSHER_KEY= +PUSHER_SECRET= +PUSHER_CLUSTER= +GCS_BUCKET_NAME= +UPTRACE_DSN= +CLOUDFLARE_TURNSTILE_SECRET_KEY= +HEARTBEAT_DB_BACKEND=mongodb +MONGODB_URI=mongodb://httpsms:testpassword@mongodb:27017/?authSource=admin&appName=httpsms diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..a37653e5 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,214 @@ +# Integration Tests + +End-to-end integration tests for the httpSMS API. These tests validate the complete SMS lifecycle by running the full application stack in Docker alongside a phone emulator service. + +## Architecture + +``` +┌──────────────┐ HTTP ┌──────────────┐ +│ Test Runner │─────────────▶│ API (Go) │ +│ (Go test) │ │ Port 8000 │ +└──────────────┘ └──────┬───────┘ + │ + FCM Push │ Events + (HTTP) │ (HTTP) + ▼ + ┌──────────────┐ + │ Emulator │ + │ (Fiber v3) │ + │ Port 9090 │ + └──────────────┘ + │ + ┌──────┴───────┐ + │ CockroachDB │ │ Redis │ + │ Port 26257 │ │ Port 6379 │ + └──────────────┘ └─────────────┘ +``` + +### Components + +| Component | Description | +| --------------- | -------------------------------------------------------- | +| **API** | The httpSMS Go API server running in Docker | +| **Emulator** | A Fiber v3 Go service that simulates an Android phone | +| **CockroachDB** | Database for the API (single-node, insecure mode) | +| **Redis** | Cache and queue backend | +| **Seed** | One-shot container that seeds test data into CockroachDB | +| **Test Runner** | Go test binary that runs on the host machine | + +### How It Works + +1. **Send SMS flow**: Test sends `POST /v1/messages/send` → API pushes FCM notification to emulator → Emulator calls `GET /v1/messages/outstanding` → Emulator fires `SENT` and `DELIVERED` events → Test polls `GET /v1/messages/{id}` until status is `delivered` + +2. **Receive SMS flow**: Test sends `POST /v1/messages/receive` (as the phone) → API stores message → Test verifies via `GET /v1/messages/{id}` + +### FCM Redirect + +The API's Firebase SDK is configured (via `FCM_ENDPOINT` env var) to redirect all FCM HTTP requests to the emulator instead of Google's servers. The emulator serves: + +- `/token` — Fake OAuth2 token endpoint (Firebase SDK requests tokens before sending) +- `/v1/projects/:project/messages:send` — Fake FCM push endpoint + +## Test Coverage + +- [x] **Send SMS E2E** — Full send lifecycle: API → FCM push → emulator responds with SENT/DELIVERED events → message reaches `delivered` status +- [x] **Receive SMS E2E** — Phone submits received message to API → message is stored and retrievable via GET endpoint + +## Prerequisites + +- [Docker](https://docs.docker.com/get-docker/) with Docker Compose +- [Go 1.22+](https://go.dev/dl/) +- [jq](https://jqlang.github.io/jq/download/) (for Firebase credentials generation) +- [OpenSSL](https://www.openssl.org/) (for RSA key generation) + +## Running Locally + +### 1. Generate Firebase Credentials + +The integration tests use a fake Firebase service account. Generate it with: + +```bash +cd tests +bash generate-firebase-credentials.sh +``` + +This creates `firebase-credentials.json` with a throwaway RSA key (the emulator doesn't validate tokens). + +### 2. Set Environment Variable + +```bash +export FIREBASE_CREDENTIALS=$(jq -c . firebase-credentials.json) +``` + +### 3. Start the Stack + +```bash +docker compose up -d --build --wait +``` + +This starts CockroachDB, Redis, the API, and the emulator. The `--wait` flag blocks until all health checks pass. + +### 4. Wait for Seeding + +```bash +docker compose wait seed +sleep 2 +``` + +The seed container inserts test users, phones, and API keys into CockroachDB after the API has run its GORM migrations. + +### 5. Run Tests + +```bash +go test -v -timeout 120s ./... +``` + +### 6. Tear Down + +```bash +docker compose down -v +``` + +The `-v` flag removes volumes (database data) for a clean slate next run. + +### One-Liner + +```bash +cd tests && \ + bash generate-firebase-credentials.sh && \ + export FIREBASE_CREDENTIALS=$(jq -c . firebase-credentials.json) && \ + docker compose up -d --build --wait && \ + docker compose wait seed && \ + sleep 2 && \ + go test -v -timeout 120s ./... ; \ + docker compose down -v +``` + +## CI/CD + +Integration tests run automatically via GitHub Actions (`.github/workflows/integration-test.yml`): + +- **Trigger**: Push to `main` or pull request targeting `main` +- **Flow**: Generates credentials → Starts Docker stack → Seeds DB → Runs tests → Collects logs on failure → Tears down +- **Gate**: Deployment should only proceed if integration tests pass + +## Test Data + +| Entity | Value | +| -------------- | -------------------------------------- | +| User API Key | `test-user-api-key` | +| Phone API Key | `pk_test-phone-api-key` | +| Phone Number | `+18005550199` | +| Contact Number | `+18005550100` | +| User ID | `test-user-id` | +| Phone ID | `a1b2c3d4-e5f6-7890-abcd-ef1234567890` | + +See [`seed.sql`](./seed.sql) for the complete seed data. + +## Project Structure + +``` +tests/ +├── docker-compose.yml # Full stack orchestration +├── seed.sql # Database seed data +├── .env.test # API environment variables +├── generate-firebase-credentials.sh # Generates fake Firebase credentials +├── go.mod # Test runner Go module +├── go.sum +├── helpers_test.go # Test utilities (HTTP client, polling) +├── integration_test.go # E2E test cases +└── emulator/ # Phone emulator service + ├── Dockerfile + ├── go.mod + ├── go.sum + ├── main.go # Fiber v3 entry point + ├── emulator.go # Emulator struct and config + ├── token_handler.go # Fake OAuth2 token endpoint + ├── fcm_handler.go # Fake FCM push receiver + └── events.go # Event firing logic (SENT/DELIVERED) +``` + +## Troubleshooting + +### API fails to start + +Check the API logs: + +```bash +docker compose logs api +``` + +Common issues: + +- `FIREBASE_CREDENTIALS` env var not set or malformed +- CockroachDB not ready (increase `start_period` in healthcheck) + +### Tests timeout waiting for `delivered` status + +Check the emulator logs: + +```bash +docker compose logs emulator +``` + +The emulator should show: + +1. `[FCM]` — Receiving the push notification +2. `[EVENTS]` — Fetching outstanding messages and firing events + +If no `[FCM]` entries appear, the API isn't reaching the emulator (check `FCM_ENDPOINT` in `.env.test`). + +### Seed container fails + +```bash +docker compose logs seed +``` + +If you see "relation does not exist" errors, the API hasn't finished GORM migrations yet. Increase the API's `start_period` in `docker-compose.yml`. + +## Adding New Tests + +1. Add test functions to `integration_test.go` (or create new `*_test.go` files) +2. Use `doRequest()` helper for authenticated HTTP calls +3. Use `pollMessageStatus()` to wait for async state changes +4. Update the test coverage checklist in this README diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 00000000..3d82d47c --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,120 @@ +services: + cockroachdb: + image: cockroachdb/cockroach:latest + command: start-single-node --insecure --store=type=mem,size=640MiB + ports: + - "26257:26257" + - "8081:8080" + healthcheck: + test: + [ + "CMD", + "cockroach", + "sql", + "--insecure", + "--host=localhost", + "--execute=SELECT 1;", + ] + interval: 5s + timeout: 5s + retries: 10 + start_period: 10s + + cockroachdb-init: + image: cockroachdb/cockroach:latest + depends_on: + cockroachdb: + condition: service_healthy + entrypoint: + [ + "cockroach", + "sql", + "--insecure", + "--host=cockroachdb", + "--execute=CREATE DATABASE IF NOT EXISTS httpsms;", + ] + restart: "no" + + redis: + image: redis:latest + command: redis-server + ports: + - "6379:6379" + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 5s + retries: 10 + + mongodb: + image: mongo:7 + ports: + - "27017:27017" + environment: + MONGO_INITDB_ROOT_USERNAME: httpsms + MONGO_INITDB_ROOT_PASSWORD: testpassword + healthcheck: + test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] + interval: 5s + timeout: 5s + retries: 10 + start_period: 5s + + wiremock: + image: wiremock/wiremock:3x + ports: + - "8080:8080" + volumes: + - ./wiremock/mappings:/home/wiremock/mappings:ro + networks: + default: + aliases: + - wiremock.local + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/__admin/health"] + interval: 5s + timeout: 5s + retries: 10 + + api: + build: + context: ../api + ports: + - "8000:8000" + depends_on: + cockroachdb-init: + condition: service_completed_successfully + redis: + condition: service_healthy + wiremock: + condition: service_healthy + mongodb: + condition: service_healthy + env_file: + - .env.test + environment: + FIREBASE_CREDENTIALS: "${FIREBASE_CREDENTIALS}" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] + interval: 5s + timeout: 10s + retries: 20 + start_period: 30s + + seed: + image: cockroachdb/cockroach:latest + depends_on: + api: + condition: service_healthy + volumes: + - ./seed.sql:/seed.sql:ro + entrypoint: + [ + "cockroach", + "sql", + "--insecure", + "--host=cockroachdb", + "--database=httpsms", + "--file=/seed.sql", + ] + restart: "no" diff --git a/tests/generate-firebase-credentials.sh b/tests/generate-firebase-credentials.sh new file mode 100644 index 00000000..70f47cd8 --- /dev/null +++ b/tests/generate-firebase-credentials.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Generates a fake Firebase service account JSON for integration tests. +# The RSA key is throwaway — it only needs to be valid so the Firebase SDK can sign JWTs. +# WireMock does not validate these tokens. + +set -e + +OUTFILE="${1:-firebase-credentials.json}" + +# Generate a 2048-bit RSA key +PRIVATE_KEY=$(openssl genrsa 2048 2>/dev/null) + +# Escape newlines for JSON embedding +PRIVATE_KEY_ESCAPED=$(echo "$PRIVATE_KEY" | awk '{printf "%s\\n", $0}') + +cat > "$OUTFILE" <= expectedCount { + return requests + } + time.Sleep(500 * time.Millisecond) + } + + requests := findWebhookRequests(t, webhookPath) + require.GreaterOrEqual(t, len(requests), expectedCount, "expected at least %d webhook events on %s, got %d", expectedCount, webhookPath, len(requests)) + return requests +} + +func waitForFCMPush(t *testing.T, messageID string, timeout time.Duration) []wmJournal.GetRequestResponse { + t.Helper() + deadline := time.Now().Add(timeout) + + for time.Now().Before(deadline) { + requests := findFCMRequests(t, messageID) + if len(requests) >= 1 { + return requests + } + time.Sleep(500 * time.Millisecond) + } + + t.Fatalf("FCM push for message %s not found within %v", messageID, timeout) + return nil +} + +type BulkMessageEntry struct { + RequestID string `json:"request_id"` + Total int `json:"total"` + ScheduledCount int `json:"scheduled_count"` + PendingCount int `json:"pending_count"` + FailedCount int `json:"failed_count"` + ExpiredCount int `json:"expired_count"` + SentCount int `json:"sent_count"` + DeliveredCount int `json:"delivered_count"` + CreatedAt string `json:"created_at"` +} + +func uploadBulkFile(ctx context.Context, t *testing.T, filename string, fileBytes []byte) (int, []byte) { + t.Helper() + + var buf bytes.Buffer + writer := multipart.NewWriter(&buf) + + part, err := writer.CreateFormFile("document", filename) + require.NoError(t, err) + + _, err = part.Write(fileBytes) + require.NoError(t, err) + require.NoError(t, writer.Close()) + + url := apiBaseURL + "/v1/bulk-messages" + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &buf) + require.NoError(t, err) + req.Header.Set("Content-Type", writer.FormDataContentType()) + req.Header.Set("x-api-key", userAPIKey) + + resp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + + return resp.StatusCode, body +} + +func fetchBulkMessages(ctx context.Context, t *testing.T) []BulkMessageEntry { + t.Helper() + + url := apiBaseURL + "/v1/bulk-messages" + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + require.NoError(t, err) + req.Header.Set("x-api-key", userAPIKey) + + resp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.StatusCode, "fetch bulk messages failed: %s", string(body)) + + var result struct { + Data []BulkMessageEntry `json:"data"` + } + require.NoError(t, json.Unmarshal(body, &result)) + return result.Data +} + +func searchMessages(ctx context.Context, t *testing.T, contact string, owner string) []httpsms.Message { + t.Helper() + + url := fmt.Sprintf("%s/v1/messages?contact=%s&owner=%s&limit=20&skip=0", apiBaseURL, contact, owner) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + require.NoError(t, err) + req.Header.Set("x-api-key", userAPIKey) + + resp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.StatusCode, "search messages failed: %s", string(body)) + + var result struct { + Data []httpsms.Message `json:"data"` + } + require.NoError(t, json.Unmarshal(body, &result)) + return result.Data +} + +func findBulkEntry(entries []BulkMessageEntry, requestID string) *BulkMessageEntry { + for i := range entries { + if entries[i].RequestID == requestID { + return &entries[i] + } + } + return nil +} diff --git a/tests/integration_test.go b/tests/integration_test.go new file mode 100644 index 00000000..29d4ced8 --- /dev/null +++ b/tests/integration_test.go @@ -0,0 +1,560 @@ +package tests + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "strings" + "testing" + "time" + + httpsms "github.com/NdoleStudio/httpsms-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/xuri/excelize/v2" +) + +func TestSendSMS_Encrypted(t *testing.T) { + ctx := context.Background() + phone := setupPhone(ctx, t, 60) + + encryptionKey := randomEncryptionKey() + signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{ + "message.phone.sent", + "message.phone.delivered", + }) + + client := newAPIClient() + plaintext := "Hello encrypted world " + randomEncryptionKey() + ciphertext, err := client.Cipher.Encrypt(encryptionKey, plaintext) + require.NoError(t, err) + require.NotEqual(t, plaintext, ciphertext) + + contactNumber := randomPhoneNumber() + sendResp, resp, err := client.Messages.Send(ctx, &httpsms.MessageSendParams{ + From: phone.PhoneNumber, + To: contactNumber, + Content: ciphertext, + Encrypted: true, + }) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode) + + messageID := sendResp.Data.ID.String() + require.NotEmpty(t, messageID) + t.Logf("sent encrypted message: %s", messageID) + + fcmRequests := waitForFCMPush(t, messageID, 30*time.Second) + require.Len(t, fcmRequests, 1) + + outstanding := fetchOutstandingMessage(ctx, t, phone.PhoneAPIKey, messageID) + assert.Equal(t, true, outstanding["encrypted"]) + assert.Equal(t, ciphertext, outstanding["content"]) + assert.NotEqual(t, plaintext, outstanding["content"]) + + fireEvent(ctx, t, phone.PhoneAPIKey, messageID, "SENT") + time.Sleep(200 * time.Millisecond) + fireEvent(ctx, t, phone.PhoneAPIKey, messageID, "DELIVERED") + + msg := pollMessageStatus(ctx, t, messageID, "delivered", 30*time.Second) + assert.Equal(t, "delivered", msg.Status) + assert.True(t, msg.Encrypted) + assert.Equal(t, ciphertext, msg.Content) + + decrypted, err := client.Cipher.Decrypt(encryptionKey, msg.Content) + require.NoError(t, err) + assert.Equal(t, plaintext, decrypted) + + webhookReqs := waitForWebhookEvents(t, webhookPath, 2, 30*time.Second) + for _, req := range webhookReqs { + assertWebhookJWT(t, req.Request, signingKey) + } + + var eventTypes []string + for _, req := range webhookReqs { + if et, ok := req.Request.Headers["X-Event-Type"]; ok { + eventTypes = append(eventTypes, et) + } else if et, ok := req.Request.Headers["x-event-type"]; ok { + eventTypes = append(eventTypes, et) + } + } + assert.Contains(t, eventTypes, "message.phone.sent") + assert.Contains(t, eventTypes, "message.phone.delivered") +} + +func TestReceiveSMS_Encrypted(t *testing.T) { + ctx := context.Background() + phone := setupPhone(ctx, t, 60) + + encryptionKey := randomEncryptionKey() + signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{ + "message.phone.received", + }) + + client := newAPIClient() + plaintext := "Incoming secret message " + randomEncryptionKey() + ciphertext, err := client.Cipher.Encrypt(encryptionKey, plaintext) + require.NoError(t, err) + + contactNumber := randomPhoneNumber() + receivePayload := map[string]interface{}{ + "from": contactNumber, + "to": phone.PhoneNumber, + "content": ciphertext, + "encrypted": true, + "sim": "SIM1", + "timestamp": time.Now().UTC().Format(time.RFC3339), + } + body, err := json.Marshal(receivePayload) + require.NoError(t, err) + + url := apiBaseURL + "/v1/messages/receive" + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body)) + require.NoError(t, err) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("x-api-key", phone.PhoneAPIKey) + + httpResp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + defer httpResp.Body.Close() + + respBody, err := io.ReadAll(httpResp.Body) + require.NoError(t, err) + require.Equal(t, http.StatusOK, httpResp.StatusCode, "receive response: %s", string(respBody)) + + var receiveResult httpsms.MessageResponse + require.NoError(t, json.Unmarshal(respBody, &receiveResult)) + messageID := receiveResult.Data.ID.String() + require.NotEmpty(t, messageID) + t.Logf("received encrypted message: %s", messageID) + + msg := pollMessageStatus(ctx, t, messageID, "received", 15*time.Second) + assert.Equal(t, "received", msg.Status) + assert.True(t, msg.Encrypted) + assert.Equal(t, ciphertext, msg.Content) + assert.NotEqual(t, plaintext, msg.Content) + + decrypted, err := client.Cipher.Decrypt(encryptionKey, msg.Content) + require.NoError(t, err) + assert.Equal(t, plaintext, decrypted) + + webhookReqs := waitForWebhookEvents(t, webhookPath, 1, 30*time.Second) + require.GreaterOrEqual(t, len(webhookReqs), 1) + assertWebhookJWT(t, webhookReqs[0].Request, signingKey) + + eventType := webhookReqs[0].Request.Headers["X-Event-Type"] + if eventType == "" { + eventType = webhookReqs[0].Request.Headers["x-event-type"] + } + assert.Equal(t, "message.phone.received", eventType) +} + +func TestSendSMS_RateLimit(t *testing.T) { + ctx := context.Background() + phone := setupPhone(ctx, t, 10) + + signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{ + "message.phone.sent", + "message.phone.delivered", + }) + + client := newAPIClient() + contactNumber := randomPhoneNumber() + + sendResp1, resp1, err := client.Messages.Send(ctx, &httpsms.MessageSendParams{ + From: phone.PhoneNumber, + To: contactNumber, + Content: "Rate limit test message 1", + }) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp1.HTTPResponse.StatusCode) + msgID1 := sendResp1.Data.ID.String() + + sendResp2, resp2, err := client.Messages.Send(ctx, &httpsms.MessageSendParams{ + From: phone.PhoneNumber, + To: contactNumber, + Content: "Rate limit test message 2", + }) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp2.HTTPResponse.StatusCode) + msgID2 := sendResp2.Data.ID.String() + + t.Logf("sent messages: %s, %s", msgID1, msgID2) + + fcm1 := waitForFCMPush(t, msgID1, 30*time.Second) + require.Len(t, fcm1, 1) + + fcm2 := waitForFCMPush(t, msgID2, 30*time.Second) + require.Len(t, fcm2, 1) + + time1 := fcm1[0].Request.LoggedDate + time2 := fcm2[0].Request.LoggedDate + gapMs := time2 - time1 + if gapMs < 0 { + gapMs = time1 - time2 + } + t.Logf("FCM push gap: %dms", gapMs) + assert.GreaterOrEqual(t, gapMs, int64(5500), "rate limit gap should be >= 5500ms (6s minus timing tolerance), got %dms", gapMs) + + fireEvent(ctx, t, phone.PhoneAPIKey, msgID1, "SENT") + fireEvent(ctx, t, phone.PhoneAPIKey, msgID1, "DELIVERED") + fireEvent(ctx, t, phone.PhoneAPIKey, msgID2, "SENT") + fireEvent(ctx, t, phone.PhoneAPIKey, msgID2, "DELIVERED") + + msg1 := pollMessageStatus(ctx, t, msgID1, "delivered", 15*time.Second) + msg2 := pollMessageStatus(ctx, t, msgID2, "delivered", 15*time.Second) + assert.Equal(t, "delivered", msg1.Status) + assert.Equal(t, "delivered", msg2.Status) + + webhookReqs := waitForWebhookEvents(t, webhookPath, 4, 30*time.Second) + for _, req := range webhookReqs { + assertWebhookJWT(t, req.Request, signingKey) + } +} + +func TestRotateAPIKey_InvalidatesCache(t *testing.T) { + ctx := context.Background() + + // Use a dedicated test user so we don't mutate the shared userAPIKey + rotateUserAPIKey := "rotate-test-api-key" + rotateUserID := "rotate-test-user-id" + + // 1) Confirm the dedicated user's API key works and warm the cache + meURL := apiBaseURL + "/v1/users/me" + req, err := http.NewRequestWithContext(ctx, http.MethodGet, meURL, nil) + require.NoError(t, err) + req.Header.Set("x-api-key", rotateUserAPIKey) + + resp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.StatusCode, "initial auth failed: %s", string(body)) + + // Parse the current API key from the response + var meResp struct { + Data struct { + ID string `json:"id"` + APIKey string `json:"api_key"` + } `json:"data"` + } + require.NoError(t, json.Unmarshal(body, &meResp)) + require.Equal(t, rotateUserID, meResp.Data.ID) + oldAPIKey := meResp.Data.APIKey + require.NotEmpty(t, oldAPIKey) + t.Logf("user ID: %s, old API key prefix: %s...", rotateUserID, oldAPIKey[:10]) + + // 2) Rotate the API key + rotateURL := fmt.Sprintf("%s/v1/users/%s/api-keys", apiBaseURL, rotateUserID) + req, err = http.NewRequestWithContext(ctx, http.MethodDelete, rotateURL, nil) + require.NoError(t, err) + req.Header.Set("x-api-key", rotateUserAPIKey) + + resp, err = http.DefaultClient.Do(req) + require.NoError(t, err) + defer resp.Body.Close() + + body, err = io.ReadAll(resp.Body) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.StatusCode, "rotate failed: %s", string(body)) + + // Parse new API key from rotate response + var rotateResp struct { + Data struct { + APIKey string `json:"api_key"` + } `json:"data"` + } + require.NoError(t, json.Unmarshal(body, &rotateResp)) + newAPIKey := rotateResp.Data.APIKey + require.NotEmpty(t, newAPIKey) + require.NotEqual(t, oldAPIKey, newAPIKey, "API key should have changed after rotation") + t.Logf("new API key prefix: %s...", newAPIKey[:10]) + + // 3) Old API key should immediately fail (401) — this is the bug regression check + req, err = http.NewRequestWithContext(ctx, http.MethodGet, meURL, nil) + require.NoError(t, err) + req.Header.Set("x-api-key", oldAPIKey) + + resp, err = http.DefaultClient.Do(req) + require.NoError(t, err) + defer resp.Body.Close() + assert.Equal(t, http.StatusUnauthorized, resp.StatusCode, "old API key should return 401 after rotation") + + // 4) New API key should work + req, err = http.NewRequestWithContext(ctx, http.MethodGet, meURL, nil) + require.NoError(t, err) + req.Header.Set("x-api-key", newAPIKey) + + resp, err = http.DefaultClient.Do(req) + require.NoError(t, err) + defer resp.Body.Close() + + body, err = io.ReadAll(resp.Body) + require.NoError(t, err) + assert.Equal(t, http.StatusOK, resp.StatusCode, "new API key should work: %s", string(body)) +} + +func TestSendSMS_OutstandingFlow(t *testing.T) { + ctx := context.Background() + phone := setupPhone(ctx, t, 60) + + signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{ + "message.phone.sent", + "message.phone.delivered", + }) + + client := newAPIClient() + contactNumber := randomPhoneNumber() + content := "Outstanding flow test " + randomEncryptionKey() + + sendResp, resp, err := client.Messages.Send(ctx, &httpsms.MessageSendParams{ + From: phone.PhoneNumber, + To: contactNumber, + Content: content, + }) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode) + + messageID := sendResp.Data.ID.String() + t.Logf("sent message: %s", messageID) + + fcmReqs := waitForFCMPush(t, messageID, 30*time.Second) + require.Len(t, fcmReqs, 1) + assert.Contains(t, fcmReqs[0].Request.Body, messageID) + assert.True(t, strings.Contains(fcmReqs[0].Request.URL, "/messages:send") || strings.Contains(fcmReqs[0].Request.AbsoluteURL, "/messages:send")) + + outstanding := fetchOutstandingMessage(ctx, t, phone.PhoneAPIKey, messageID) + assert.Equal(t, messageID, outstanding["id"]) + assert.Equal(t, content, outstanding["content"]) + assert.Equal(t, phone.PhoneNumber, outstanding["owner"]) + assert.Equal(t, contactNumber, outstanding["contact"]) + + fireEvent(ctx, t, phone.PhoneAPIKey, messageID, "SENT") + time.Sleep(200 * time.Millisecond) + fireEvent(ctx, t, phone.PhoneAPIKey, messageID, "DELIVERED") + + msg := pollMessageStatus(ctx, t, messageID, "delivered", 30*time.Second) + assert.Equal(t, "delivered", msg.Status) + assert.Equal(t, content, msg.Content) + + webhookReqs := waitForWebhookEvents(t, webhookPath, 2, 30*time.Second) + for _, req := range webhookReqs { + assertWebhookJWT(t, req.Request, signingKey) + } +} + +func TestHeartbeat_StoreAndIndex(t *testing.T) { + ctx := context.Background() + phone := setupPhone(ctx, t, 60) + + // Store a heartbeat via phone API key (retry to allow async phone-API-key association) + storePayload := map[string]interface{}{ + "phone_numbers": []string{phone.PhoneNumber}, + "charging": true, + } + + url := apiBaseURL + "/v1/heartbeats" + var respBody []byte + var statusCode int + deadline := time.Now().Add(15 * time.Second) + for time.Now().Before(deadline) { + body, err := json.Marshal(storePayload) + require.NoError(t, err) + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body)) + require.NoError(t, err) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("x-api-key", phone.PhoneAPIKey) + + resp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + + respBody, err = io.ReadAll(resp.Body) + resp.Body.Close() + require.NoError(t, err) + + statusCode = resp.StatusCode + if statusCode == http.StatusCreated { + break + } + time.Sleep(500 * time.Millisecond) + } + require.Equal(t, http.StatusCreated, statusCode, "store heartbeat failed: %s", string(respBody)) + + // Read heartbeats back via user API key + client := newAPIClient() + heartbeats, indexResp, err := client.Heartbeats.Index(ctx, &httpsms.HeartbeatIndexParams{ + Owner: phone.PhoneNumber, + Limit: 1, + }) + require.NoError(t, err) + require.Equal(t, http.StatusOK, indexResp.HTTPResponse.StatusCode) + + require.NotNil(t, heartbeats) + require.GreaterOrEqual(t, len(heartbeats.Data), 1, "expected at least 1 heartbeat") + + hb := heartbeats.Data[0] + assert.Equal(t, phone.PhoneNumber, hb.Owner) + assert.True(t, hb.Charging) + assert.False(t, hb.Timestamp.IsZero(), "timestamp should not be zero") +} + +func TestBulkSMS_CSV(t *testing.T) { + ctx := context.Background() + phone := setupPhone(ctx, t, 60) + + // Build CSV content with 1 message + contact := randomPhoneNumber() + csvContent := fmt.Sprintf("FromPhoneNumber,ToPhoneNumber,Content,SendTime(optional)\n%s,%s,CSV bulk test message,\n", + phone.PhoneNumber, contact) + + // Upload CSV + statusCode, respBody := uploadBulkFile(ctx, t, "test.csv", []byte(csvContent)) + require.Equal(t, http.StatusAccepted, statusCode, "upload failed: %s", string(respBody)) + t.Logf("upload response: %s", string(respBody)) + + // Parse the response to verify message count + var uploadResp struct { + Message string `json:"message"` + } + require.NoError(t, json.Unmarshal(respBody, &uploadResp)) + assert.Contains(t, uploadResp.Message, "1 out of 1") + + // Wait a moment for messages to be persisted + time.Sleep(2 * time.Second) + + // Search for the bulk message by owner to get message IDs + messages := searchMessages(ctx, t, contact, phone.PhoneNumber) + require.GreaterOrEqual(t, len(messages), 1, "expected at least 1 message for phone %s", phone.PhoneNumber) + + // Find the message with bulk- request_id prefix + var bulkMsg *httpsms.Message + for i := range messages { + if messages[i].RequestID != nil && strings.HasPrefix(*messages[i].RequestID, "bulk-") { + bulkMsg = &messages[i] + break + } + } + require.NotNil(t, bulkMsg, "no message with bulk- request_id found") + messageID := bulkMsg.ID.String() + requestID := *bulkMsg.RequestID + t.Logf("found bulk message: id=%s, request_id=%s", messageID, requestID) + + // Wait for FCM push + waitForFCMPush(t, messageID, 30*time.Second) + + // Fire SENT event + fireEvent(ctx, t, phone.PhoneAPIKey, messageID, "SENT") + + // Poll until message reaches "sent" status + msg := pollMessageStatus(ctx, t, messageID, "sent", 15*time.Second) + assert.Equal(t, "sent", msg.Status) + + // Verify bulk-messages history endpoint + entries := fetchBulkMessages(ctx, t) + entry := findBulkEntry(entries, requestID) + require.NotNil(t, entry, "bulk entry with request_id %s not found in history", requestID) + + assert.Equal(t, 1, entry.Total) + assert.Equal(t, 1, entry.SentCount) + assert.Equal(t, 0, entry.PendingCount) + assert.Equal(t, 0, entry.FailedCount) + assert.Equal(t, 0, entry.ExpiredCount) + assert.Equal(t, 0, entry.DeliveredCount) + assert.Equal(t, 0, entry.ScheduledCount) +} + +func TestBulkSMS_Excel(t *testing.T) { + ctx := context.Background() + phone := setupPhone(ctx, t, 60) + + contact1 := randomPhoneNumber() + contact2 := randomPhoneNumber() + + // Build Excel file with 2 messages + f := excelize.NewFile() + sheet := f.GetSheetName(0) + f.SetCellValue(sheet, "A1", "FromPhoneNumber") + f.SetCellValue(sheet, "B1", "ToPhoneNumber") + f.SetCellValue(sheet, "C1", "Content") + f.SetCellValue(sheet, "D1", "SendTime(optional)") + + f.SetCellValue(sheet, "A2", phone.PhoneNumber) + f.SetCellValue(sheet, "B2", contact1) + f.SetCellValue(sheet, "C2", "Excel bulk test message 1") + f.SetCellValue(sheet, "D2", "") + + f.SetCellValue(sheet, "A3", phone.PhoneNumber) + f.SetCellValue(sheet, "B3", contact2) + f.SetCellValue(sheet, "C3", "Excel bulk test message 2") + f.SetCellValue(sheet, "D3", "") + + var excelBuf bytes.Buffer + require.NoError(t, f.Write(&excelBuf)) + + // Upload Excel + statusCode, respBody := uploadBulkFile(ctx, t, "test.xlsx", excelBuf.Bytes()) + require.Equal(t, http.StatusAccepted, statusCode, "upload failed: %s", string(respBody)) + t.Logf("upload response: %s", string(respBody)) + + var uploadResp struct { + Message string `json:"message"` + } + require.NoError(t, json.Unmarshal(respBody, &uploadResp)) + assert.Contains(t, uploadResp.Message, "2 out of 2") + + // Wait for messages to be persisted + time.Sleep(2 * time.Second) + + // Search for bulk messages by owner and each contact + messages1 := searchMessages(ctx, t, contact1, phone.PhoneNumber) + messages2 := searchMessages(ctx, t, contact2, phone.PhoneNumber) + messages := append(messages1, messages2...) + require.GreaterOrEqual(t, len(messages), 2, "expected at least 2 messages for phone %s", phone.PhoneNumber) + + // Find messages with bulk- request_id prefix + var bulkMessages []httpsms.Message + var requestID string + for i := range messages { + if messages[i].RequestID != nil && strings.HasPrefix(*messages[i].RequestID, "bulk-") { + bulkMessages = append(bulkMessages, messages[i]) + requestID = *messages[i].RequestID + } + } + require.Len(t, bulkMessages, 2, "expected 2 messages with bulk- request_id") + require.NotEmpty(t, requestID) + t.Logf("found %d bulk messages with request_id=%s", len(bulkMessages), requestID) + + // Wait for FCM pushes for both messages + msgID1 := bulkMessages[0].ID.String() + msgID2 := bulkMessages[1].ID.String() + waitForFCMPush(t, msgID1, 30*time.Second) + waitForFCMPush(t, msgID2, 30*time.Second) + + // Fire SENT then DELIVERED on message 1, leave message 2 pending + fireEvent(ctx, t, phone.PhoneAPIKey, msgID1, "SENT") + time.Sleep(200 * time.Millisecond) + fireEvent(ctx, t, phone.PhoneAPIKey, msgID1, "DELIVERED") + + // Poll until message 1 reaches "delivered" + msg1 := pollMessageStatus(ctx, t, msgID1, "delivered", 15*time.Second) + assert.Equal(t, "delivered", msg1.Status) + + // Verify bulk-messages history endpoint + entries := fetchBulkMessages(ctx, t) + entry := findBulkEntry(entries, requestID) + require.NotNil(t, entry, "bulk entry with request_id %s not found in history", requestID) + + assert.Equal(t, 2, entry.Total) + assert.Equal(t, 1, entry.DeliveredCount) + assert.Equal(t, 0, entry.PendingCount) + assert.Equal(t, 0, entry.SentCount) + assert.Equal(t, 0, entry.FailedCount) + assert.Equal(t, 0, entry.ExpiredCount) + assert.Equal(t, 1, entry.ScheduledCount) +} diff --git a/tests/seed.sql b/tests/seed.sql new file mode 100644 index 00000000..36d714d9 --- /dev/null +++ b/tests/seed.sql @@ -0,0 +1,38 @@ +-- Seed test data for integration tests +-- Run AFTER GORM has migrated the schema (i.e., after API starts) + +-- Test user +INSERT INTO users (id, email, api_key, timezone, subscription_name, created_at, updated_at) +VALUES ( + 'test-user-id', + 'test@httpsms.com', + 'test-user-api-key', + 'UTC', + 'pro-monthly', + NOW(), + NOW() +) ON CONFLICT (id) DO NOTHING; + +-- Test user for API key rotation tests (isolated to avoid mutating the shared test user) +INSERT INTO users (id, email, api_key, timezone, subscription_name, created_at, updated_at) +VALUES ( + 'rotate-test-user-id', + 'rotate-test@httpsms.com', + 'rotate-test-api-key', + 'UTC', + 'pro-monthly', + NOW(), + NOW() +) ON CONFLICT (id) DO NOTHING; + +-- System user (for event queue auth) +INSERT INTO users (id, email, api_key, timezone, subscription_name, created_at, updated_at) +VALUES ( + 'system-user-id', + 'system@httpsms.com', + 'system-user-api-key', + 'UTC', + 'pro-monthly', + NOW(), + NOW() +) ON CONFLICT (id) DO NOTHING; diff --git a/tests/wiremock/mappings/fcm-send.json b/tests/wiremock/mappings/fcm-send.json new file mode 100644 index 00000000..7640fb7c --- /dev/null +++ b/tests/wiremock/mappings/fcm-send.json @@ -0,0 +1,15 @@ +{ + "request": { + "urlPathPattern": "/v1/projects/.*/messages:send", + "method": "POST" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "jsonBody": { + "name": "projects/httpsms-test/messages/fake-message-id" + } + } +} diff --git a/tests/wiremock/mappings/oauth-token.json b/tests/wiremock/mappings/oauth-token.json new file mode 100644 index 00000000..9518f4fe --- /dev/null +++ b/tests/wiremock/mappings/oauth-token.json @@ -0,0 +1,17 @@ +{ + "request": { + "urlPathPattern": "/token", + "method": "POST" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "jsonBody": { + "access_token": "fake-access-token", + "token_type": "Bearer", + "expires_in": 3600 + } + } +} diff --git a/tests/wiremock/mappings/webhook-receiver.json b/tests/wiremock/mappings/webhook-receiver.json new file mode 100644 index 00000000..79966b64 --- /dev/null +++ b/tests/wiremock/mappings/webhook-receiver.json @@ -0,0 +1,15 @@ +{ + "request": { + "urlPathPattern": "/webhooks/.*", + "method": "POST" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "jsonBody": { + "status": "received" + } + } +} diff --git a/web/.env.docker b/web/.env.docker index d48c328f..b1751dfb 100644 --- a/web/.env.docker +++ b/web/.env.docker @@ -15,3 +15,7 @@ FIREBASE_STORAGE_BUCKET=httpsms-docker.appspot.com FIREBASE_MESSAGING_SENDER_ID=668063041624 FIREBASE_APP_ID=668063041624:web:29b9e3b7027965ba08a22d FIREBASE_MEASUREMENT_ID=G-18VRYL22PZ + +# Cloudflare Turnstile site key for captcha on the search messages page +# Get your site key at https://developers.cloudflare.com/turnstile/get-started/ +CLOUDFLARE_TURNSTILE_SITE_KEY= diff --git a/web/Dockerfile b/web/Dockerfile index 169f78cc..813399ea 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,5 +1,5 @@ # build stage -FROM node:lts-alpine as build +FROM node:lts-alpine AS build WORKDIR /app diff --git a/web/assets/img/schedule-messages.svg b/web/assets/img/schedule-messages.svg new file mode 100644 index 00000000..5906b27e --- /dev/null +++ b/web/assets/img/schedule-messages.svg @@ -0,0 +1 @@ + diff --git a/web/components/MessageThread.vue b/web/components/MessageThread.vue index 0f0f222b..51676b85 100644 --- a/web/components/MessageThread.vue +++ b/web/components/MessageThread.vue @@ -95,8 +95,10 @@ {{ thread.contact | phoneNumber }} - - {{ thread.last_message_content }} + + + {{ thread.last_message_content }} + @@ -150,6 +152,7 @@ import { mdiCheck, mdiAlert, mdiAccount, + mdiPaperclip, } from '@mdi/js' @Component @@ -160,6 +163,7 @@ export default class MessageThread extends Vue { mdiAlert = mdiAlert mdiCheck = mdiCheck mdiCheckAll = mdiCheckAll + mdiPaperclip = mdiPaperclip get threads(): Array { return this.$store.getters.getThreads diff --git a/web/layouts/default.vue b/web/layouts/default.vue index 1c2049e5..cff2bd34 100644 --- a/web/layouts/default.vue +++ b/web/layouts/default.vue @@ -73,7 +73,7 @@ export default class DefaultLayout extends Vue { if (this.$store.getters.getAuthUser && this.$store.getters.getOwner) { setAuthHeader((await this.$fire.auth.currentUser?.getIdToken()) ?? '') promises.push( - promises.push(this.$store.dispatch('loadPhones', true)), + this.$store.dispatch('loadPhones', true), this.$store.dispatch('loadThreads'), this.$store.dispatch('getHeartbeat'), ) diff --git a/web/models/api.ts b/web/models/api.ts index 7b2d542f..c4d7b8dc 100644 --- a/web/models/api.ts +++ b/web/models/api.ts @@ -10,6 +10,25 @@ * --------------------------------------------------------------- */ +export enum EntitiesSubscriptionName { + SubscriptionNameFree = 'free', + SubscriptionNameProMonthly = 'pro-monthly', + SubscriptionNameProYearly = 'pro-yearly', + SubscriptionNameUltraMonthly = 'ultra-monthly', + SubscriptionNameUltraYearly = 'ultra-yearly', + SubscriptionNameProLifetime = 'pro-lifetime', + SubscriptionName20KMonthly = '20k-monthly', + SubscriptionName100KMonthly = '100k-monthly', + SubscriptionName50KMonthly = '50k-monthly', + SubscriptionName200KMonthly = '200k-monthly', + SubscriptionName20KYearly = '20k-yearly', +} + +export enum EntitiesSIM { + SIM1 = 'SIM1', + SIM2 = 'SIM2', +} + export interface EntitiesBillingUsage { /** @example "2022-06-05T14:26:02.302718+03:00" */ created_at: string @@ -31,6 +50,25 @@ export interface EntitiesBillingUsage { user_id: string } +export interface EntitiesBulkMessage { + /** @example "2022-06-05T14:26:02.302718+03:00" */ + created_at: string + /** @example 25 */ + delivered_count: number + /** @example 5 */ + failed_count: number + /** @example 30 */ + pending_count: number + /** @example "bulk-32343a19-da5e-4b1b-a767-3298a73703cb" */ + request_id: string + /** @example 50 */ + scheduled_count: number + /** @example 40 */ + sent_count: number + /** @example 150 */ + total: number +} + export interface EntitiesDiscord { /** @example "2022-06-05T14:26:02.302718+03:00" */ created_at: string @@ -64,8 +102,8 @@ export interface EntitiesHeartbeat { } export interface EntitiesMessage { - /** @example false */ - can_be_polled: boolean + /** @example ["https://example.com/image.jpg","https://example.com/video.mp4"] */ + attachments: string[] /** @example "+18005550100" */ contact: string /** @example "This is a sample text message" */ @@ -73,19 +111,19 @@ export interface EntitiesMessage { /** @example "2022-06-05T14:26:02.302718+03:00" */ created_at: string /** @example "2022-06-05T14:26:09.527976+03:00" */ - delivered_at: string + delivered_at?: string /** @example false */ encrypted: boolean /** @example "2022-06-05T14:26:09.527976+03:00" */ - expired_at: string + expired_at?: string /** @example "2022-06-05T14:26:09.527976+03:00" */ - failed_at: string + failed_at?: string /** @example "UNKNOWN" */ - failure_reason: string + failure_reason?: string /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ id: string /** @example "2022-06-05T14:26:09.527976+03:00" */ - last_attempted_at: string + last_attempted_at?: string /** @example 1 */ max_send_attempts: number /** @example "2022-06-05T14:26:09.527976+03:00" */ @@ -93,24 +131,24 @@ export interface EntitiesMessage { /** @example "+18005550199" */ owner: string /** @example "2022-06-05T14:26:09.527976+03:00" */ - received_at: string + received_at?: string /** @example "153554b5-ae44-44a0-8f4f-7bbac5657ad4" */ - request_id: string + request_id?: string /** @example "2022-06-05T14:26:01.520828+03:00" */ request_received_at: string /** @example "2022-06-05T14:26:09.527976+03:00" */ - scheduled_at: string + scheduled_at?: string /** @example "2022-06-05T14:26:09.527976+03:00" */ - scheduled_send_time: string + scheduled_send_time?: string /** @example 0 */ send_attempt_count: number /** * SendDuration is the number of nanoseconds from when the request was received until when the mobile phone send the message * @example 133414 */ - send_time: number + send_time?: number /** @example "2022-06-05T14:26:09.527976+03:00" */ - sent_at: string + sent_at?: string /** * SIM is the SIM card to use to send the message * * SMS1: use the SIM card in slot 1 @@ -118,7 +156,7 @@ export interface EntitiesMessage { * * DEFAULT: used the default communication SIM card * @example "DEFAULT" */ - sim: string + sim: EntitiesSIM /** @example "pending" */ status: string /** @example "mobile-terminated" */ @@ -129,6 +167,31 @@ export interface EntitiesMessage { user_id: string } +export interface EntitiesMessageSendSchedule { + /** @example "2022-06-05T14:26:02.302718+03:00" */ + created_at: string + /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ + id: string + /** @example "Business Hours" */ + name: string + /** @example "Europe/Tallinn" */ + timezone: string + /** @example "2022-06-05T14:26:10.303278+03:00" */ + updated_at: string + /** @example "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" */ + user_id: string + windows: EntitiesMessageSendScheduleWindow[] +} + +export interface EntitiesMessageSendScheduleWindow { + /** @example 1 */ + day_of_week: number + /** @example 1020 */ + end_minute: number + /** @example 540 */ + start_minute: number +} + export interface EntitiesMessageThread { /** @example "indigo" */ color: string @@ -160,7 +223,7 @@ export interface EntitiesPhone { /** @example "2022-06-05T14:26:02.302718+03:00" */ created_at: string /** @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....." */ - fcm_token: string + fcm_token?: string /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ id: string /** @@ -170,14 +233,15 @@ export interface EntitiesPhone { max_send_attempts: number /** MessageExpirationSeconds is the duration in seconds after sending a message when it is considered to be expired. */ message_expiration_seconds: number + /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ + message_send_schedule_id?: string /** @example 1 */ messages_per_minute: number /** @example "This phone cannot receive calls. Please send an SMS instead." */ - missed_call_auto_reply: string + missed_call_auto_reply?: string /** @example "+18005550199" */ phone_number: string - /** SIM card that received the message */ - sim: string + sim: EntitiesSIM /** @example "2022-06-05T14:26:10.303278+03:00" */ updated_at: string /** @example "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" */ @@ -185,7 +249,7 @@ export interface EntitiesPhone { } export interface EntitiesPhoneAPIKey { - /** @example "pk_DGW8NwQp7mxKaSZ72Xq9v67SLqSbWQvckzzmK8D6rvd7NywSEkdMJtuxKyEkYnCY" */ + /** @example "pk_DGW8NwQp7mxKaSZ72Xq9v6xxxxx" */ api_key: string /** @example "2022-06-05T14:26:02.302718+03:00" */ created_at: string @@ -193,9 +257,9 @@ export interface EntitiesPhoneAPIKey { id: string /** @example "Business Phone Key" */ name: string - /** @example ["[32343a19-da5e-4b1b-a767-3298a73703cb","32343a19-da5e-4b1b-a767-3298a73703cc]"] */ + /** @example ["32343a19-da5e-4b1b-a767-3298a73703cb","32343a19-da5e-4b1b-a767-3298a73703cc"] */ phone_ids: string[] - /** @example ["[+18005550199","+18005550100]"] */ + /** @example ["+18005550199","+18005550100"] */ phone_numbers: string[] /** @example "2022-06-05T14:26:02.302718+03:00" */ updated_at: string @@ -207,7 +271,7 @@ export interface EntitiesPhoneAPIKey { export interface EntitiesUser { /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ - active_phone_id: string + active_phone_id?: string /** @example "x-api-key" */ api_key: string /** @example "2022-06-05T14:26:02.302718+03:00" */ @@ -225,15 +289,15 @@ export interface EntitiesUser { /** @example true */ notification_webhook_enabled: boolean /** @example "2022-06-05T14:26:02.302718+03:00" */ - subscription_ends_at: string + subscription_ends_at?: string /** @example "8f9c71b8-b84e-4417-8408-a62274f65a08" */ subscription_id: string /** @example "free" */ - subscription_name: string + subscription_name: EntitiesSubscriptionName /** @example "2022-06-05T14:26:02.302718+03:00" */ - subscription_renews_at: string + subscription_renews_at?: string /** @example "on_trial" */ - subscription_status: string + subscription_status?: string /** @example "Europe/Helsinki" */ timezone: string /** @example "2022-06-05T14:26:10.303278+03:00" */ @@ -243,11 +307,11 @@ export interface EntitiesUser { export interface EntitiesWebhook { /** @example "2022-06-05T14:26:02.302718+03:00" */ created_at: string - /** @example ["[message.phone.received]"] */ + /** @example ["message.phone.received"] */ events: string[] /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ id: string - /** @example ["[+18005550199","+18005550100]"] */ + /** @example ["+18005550199","+18005550100"] */ phone_numbers: string[] /** @example "DGW8NwQp7mxKaSZ72Xq9v67SLqSbWQvckzzmK8D6rvd7NywSEkdMJtuxKyEkYnCY" */ signing_key: string @@ -276,14 +340,34 @@ export interface RequestsHeartbeatStore { phone_numbers: string[] } +export interface RequestsMessageAttachment { + /** + * Content is the base64-encoded attachment data + * @example "base64data..." + */ + content: string + /** + * ContentType is the MIME type of the attachment + * @example "image/jpeg" + */ + content_type: string + /** + * Name is the original filename of the attachment + * @example "photo.jpg" + */ + name: string +} + export interface RequestsMessageBulkSend { + /** Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS */ + attachments?: string[] /** @example "This is a sample text message" */ content: string /** * Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app * @example false */ - encrypted: boolean + encrypted?: boolean /** @example "+18005550199" */ from: string /** @@ -325,6 +409,8 @@ export interface RequestsMessageEvent { } export interface RequestsMessageReceive { + /** Attachments is the list of MMS attachments received with the message */ + attachments?: RequestsMessageAttachment[] /** @example "This is a sample text message received on a phone" */ content: string /** @@ -338,7 +424,7 @@ export interface RequestsMessageReceive { * SIM card that received the message * @example "SIM1" */ - sim: string + sim: EntitiesSIM /** * Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible * @example "2022-06-05T14:26:09.527976+03:00" @@ -349,13 +435,18 @@ export interface RequestsMessageReceive { } export interface RequestsMessageSend { + /** + * Attachments are optional. When you provide a list of attachments, the message will be sent out as an MMS + * @example ["https://example.com/image.jpg","https://example.com/video.mp4"] + */ + attachments?: string[] /** @example "This is a sample text message" */ content: string /** - * Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app + * Encrypted is an optional parameter used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app * @example false */ - encrypted: boolean + encrypted?: boolean /** @example "+18005550199" */ from: string /** @@ -364,14 +455,26 @@ export interface RequestsMessageSend { */ request_id?: string /** - * SendAt is an optional parameter used to schedule a message to be sent at a later time - * @example "2022-06-05T14:26:09.527976+03:00" + * SendAt is an optional parameter used to schedule a message to be sent in the future. The time is considered to be in your profile's local timezone and you can queue messages for up to 20 days (480 hours) in the future. + * @example "2025-12-19T16:39:57-08:00" */ send_at?: string /** @example "+18005550100" */ to: string } +export interface RequestsMessageSendScheduleStore { + name: string + timezone: string + windows: RequestsMessageSendScheduleWindow[] +} + +export interface RequestsMessageSendScheduleWindow { + day_of_week: number + end_minute: number + start_minute: number +} + export interface RequestsMessageThreadUpdate { /** @example true */ is_archived: boolean @@ -407,6 +510,8 @@ export interface RequestsPhoneUpsert { * @example 12345 */ message_expiration_seconds: number + /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ + message_send_schedule_id?: string /** @example 1 */ messages_per_minute: number /** @example "e.g. This phone cannot receive calls. Please send an SMS instead." */ @@ -431,6 +536,23 @@ export interface RequestsUserNotificationUpdate { webhook_enabled: boolean } +export interface RequestsUserPaymentInvoice { + /** @example "221B Baker Street, London" */ + address: string + /** @example "Los Angeles" */ + city: string + /** @example "US" */ + country: string + /** @example "Acme Corp" */ + name: string + /** @example "Thank you for your business!" */ + notes: string + /** @example "CA" */ + state: string + /** @example "9800" */ + zip_code: string +} + export interface RequestsUserUpdate { /** @example "32343a19-da5e-4b1b-a767-3298a73703cb" */ active_phone_id: string @@ -465,7 +587,7 @@ export interface ResponsesBadRequest { export interface ResponsesBillingUsageResponse { data: EntitiesBillingUsage - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -473,7 +595,15 @@ export interface ResponsesBillingUsageResponse { export interface ResponsesBillingUsagesResponse { data: EntitiesBillingUsage[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ + message: string + /** @example "success" */ + status: string +} + +export interface ResponsesBulkMessagesResponse { + data: EntitiesBulkMessage[] + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -481,7 +611,7 @@ export interface ResponsesBillingUsagesResponse { export interface ResponsesDiscordResponse { data: EntitiesDiscord - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -489,7 +619,7 @@ export interface ResponsesDiscordResponse { export interface ResponsesDiscordsResponse { data: EntitiesDiscord[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -497,7 +627,7 @@ export interface ResponsesDiscordsResponse { export interface ResponsesHeartbeatResponse { data: EntitiesHeartbeat - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -505,7 +635,7 @@ export interface ResponsesHeartbeatResponse { export interface ResponsesHeartbeatsResponse { data: EntitiesHeartbeat[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -520,7 +650,23 @@ export interface ResponsesInternalServerError { export interface ResponsesMessageResponse { data: EntitiesMessage - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ + message: string + /** @example "success" */ + status: string +} + +export interface ResponsesMessageSendScheduleResponse { + data: EntitiesMessageSendSchedule + /** @example "Request handled successfully" */ + message: string + /** @example "success" */ + status: string +} + +export interface ResponsesMessageSendSchedulesResponse { + data: EntitiesMessageSendSchedule[] + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -528,7 +674,7 @@ export interface ResponsesMessageResponse { export interface ResponsesMessageThreadsResponse { data: EntitiesMessageThread[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -536,7 +682,7 @@ export interface ResponsesMessageThreadsResponse { export interface ResponsesMessagesResponse { data: EntitiesMessage[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -564,9 +710,16 @@ export interface ResponsesOkString { status: string } +export interface ResponsesPaymentRequired { + /** @example "You have reached the maximum number of allowed resources. Please upgrade your plan." */ + message: string + /** @example "error" */ + status: string +} + export interface ResponsesPhoneAPIKeyResponse { data: EntitiesPhoneAPIKey - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -574,7 +727,7 @@ export interface ResponsesPhoneAPIKeyResponse { export interface ResponsesPhoneAPIKeysResponse { data: EntitiesPhoneAPIKey[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -582,7 +735,7 @@ export interface ResponsesPhoneAPIKeysResponse { export interface ResponsesPhoneResponse { data: EntitiesPhone - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -590,7 +743,7 @@ export interface ResponsesPhoneResponse { export interface ResponsesPhonesResponse { data: EntitiesPhone[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -607,7 +760,7 @@ export interface ResponsesUnauthorized { export interface ResponsesUnprocessableEntity { data: Record - /** @example "validation errors while sending message" */ + /** @example "validation errors while handling request" */ message: string /** @example "error" */ status: string @@ -615,7 +768,47 @@ export interface ResponsesUnprocessableEntity { export interface ResponsesUserResponse { data: EntitiesUser - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ + message: string + /** @example "success" */ + status: string +} + +export interface ResponsesUserSubscriptionPaymentsResponse { + data: { + attributes: { + billing_reason: string + card_brand: string + card_last_four: string + created_at: string + currency: string + currency_rate: string + discount_total: number + discount_total_formatted: string + discount_total_usd: number + refunded: boolean + refunded_amount: number + refunded_amount_formatted: string + refunded_amount_usd: number + refunded_at: any + status: string + status_formatted: string + subtotal: number + subtotal_formatted: string + subtotal_usd: number + tax: number + tax_formatted: string + tax_inclusive: boolean + tax_usd: number + total: number + total_formatted: string + total_usd: number + updated_at: string + } + id: string + type: string + }[] + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -623,7 +816,7 @@ export interface ResponsesUserResponse { export interface ResponsesWebhookResponse { data: EntitiesWebhook - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string @@ -631,7 +824,7 @@ export interface ResponsesWebhookResponse { export interface ResponsesWebhooksResponse { data: EntitiesWebhook[] - /** @example "item created successfully" */ + /** @example "Request handled successfully" */ message: string /** @example "success" */ status: string diff --git a/web/models/message.ts b/web/models/message.ts index 35306648..b17b53ec 100644 --- a/web/models/message.ts +++ b/web/models/message.ts @@ -1,6 +1,7 @@ export interface Message { contact: string content: string + attachments: Array | null created_at: string failure_reason: string id: string diff --git a/web/package.json b/web/package.json index 044d499b..16f18812 100644 --- a/web/package.json +++ b/web/package.json @@ -26,23 +26,23 @@ "@nuxtjs/dotenv": "^1.4.2", "@nuxtjs/firebase": "^8.2.2", "@nuxtjs/sitemap": "^2.4.0", - "chart.js": "^4.4.9", + "chart.js": "^4.5.1", "chartjs-adapter-moment": "^1.0.1", - "core-js": "^3.39.0", + "core-js": "^3.49.0", "date-fns": "^2.30.0", - "dotenv": "^16.5.0", + "dotenv": "^17.2.3", "firebase": "^10.14.1", "firebaseui": "^6.1.0", - "jest-environment-jsdom": "^29.7.0", - "libphonenumber-js": "^1.11.17", + "jest-environment-jsdom": "^30.3.0", + "libphonenumber-js": "^1.12.36", "moment": "^2.30.1", "nuxt": "^2.18.1", "nuxt-highlightjs": "^1.0.3", "pusher-js": "^8.4.0", "qrcode": "^1.5.0", - "ufo": "^1.6.1", + "ufo": "^1.6.4", "vue": "^2.7.16", - "vue-chartjs": "^5.3.2", + "vue-chartjs": "^5.3.3", "vue-class-component": "^7.2.6", "vue-glow": "^1.4.2", "vue-property-decorator": "^9.1.2", @@ -51,38 +51,38 @@ "vue-template-compiler": "^2.7.16", "vuetify": "^2.7.2", "vuex": "^3.6.2", - "webpack": "^5.99.7" + "webpack": "^5.104.1" }, "devDependencies": { - "@babel/eslint-parser": "^7.27.1", - "@commitlint/cli": "^19.8.0", - "@commitlint/config-conventional": "^19.8.0", + "@babel/eslint-parser": "^7.28.6", + "@commitlint/cli": "^20.4.0", + "@commitlint/config-conventional": "^20.5.3", "@nuxt/types": "^2.18.1", "@nuxt/typescript-build": "^3.0.2", "@nuxtjs/eslint-config-typescript": "^12.1.0", "@nuxtjs/eslint-module": "^4.1.0", "@nuxtjs/stylelint-module": "^5.2.0", "@nuxtjs/vuetify": "^1.12.3", - "@types/qrcode": "^1.5.5", + "@types/qrcode": "^1.5.6", "@vue/test-utils": "^1.3.6", - "axios": "^0.30.0", + "axios": "^0.31.1", "babel-core": "7.0.0-bridge.0", - "babel-jest": "^29.7.0", + "babel-jest": "^30.2.0", "eslint": "^8.57.1", - "eslint-config-prettier": "^10.1.2", + "eslint-config-prettier": "^10.1.8", "eslint-plugin-nuxt": "^4.0.0", - "eslint-plugin-vue": "^9.32.0", + "eslint-plugin-vue": "^9.33.0", "highlight.js": "^11.11.1", - "jest": "^29.7.0", - "lint-staged": "^15.5.1", - "node-fetch-native": "^1.6.4", - "postcss-html": "^1.7.0", - "prettier": "3.4.2", + "jest": "^30.2.0", + "lint-staged": "^16.1.4", + "node-fetch-native": "^1.6.7", + "postcss-html": "^1.8.1", + "prettier": "3.8.1", "stylelint": "^15.11.0", "stylelint-config-prettier": "^9.0.5", "stylelint-config-recommended-vue": "^1.5.0", "stylelint-config-standard": "^34.0.0", - "ts-jest": "^29.2.5", + "ts-jest": "^29.4.6", "vue-client-only": "^2.1.0", "vue-jest": "^3.0.7", "vue-meta": "^2.4.0", diff --git a/web/pages/billing/index.vue b/web/pages/billing/index.vue index d17b7c9a..039f129f 100644 --- a/web/pages/billing/index.vue +++ b/web/pages/billing/index.vue @@ -226,7 +226,7 @@ -
Overview
+
Overview

This is the summary of the sent messages and received messages in -

Usage History
+ +
Usage History

Summary of all the sent and received messages in the past 12 months @@ -337,6 +417,150 @@ + + + Generate Invoice + + Create an invoice for your + {{ selectedPayment?.attributes.total_formatted }} payment on + {{ selectedPayment?.attributes.created_at | timestamp }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ mdiDownloadOutline }} + Download Invoice + + + + Close + + + + @@ -347,8 +571,12 @@ import { mdiAccountCircle, mdiShieldCheck, mdiDelete, + mdiDownloadOutline, mdiCog, mdiContentSave, + mdiCheck, + mdiAlert, + mdiInvoice, mdiEye, mdiEyeOff, mdiCallReceived, @@ -356,6 +584,11 @@ import { mdiCreditCard, mdiSquareEditOutline, } from '@mdi/js' +import { + RequestsUserPaymentInvoice, + ResponsesUserSubscriptionPaymentsResponse, +} from '~/models/api' +import { ErrorMessages } from '~/plugins/errors' type PaymentPlan = { name: string @@ -364,6 +597,14 @@ type PaymentPlan = { messagesPerMonth: number } +type subscriptionPayment = { + attributes: { + created_at: string + total_formatted: string + } + id: string +} + export default Vue.extend({ name: 'BillingIndex', middleware: ['auth'], @@ -372,7 +613,11 @@ export default Vue.extend({ mdiEye, mdiEyeOff, mdiArrowLeft, + mdiDownloadOutline, mdiAccountCircle, + mdiCheck, + mdiAlert, + mdiInvoice, mdiShieldCheck, mdiDelete, mdiCog, @@ -382,7 +627,267 @@ export default Vue.extend({ mdiCreditCard, mdiSquareEditOutline, loading: true, + loadingSubscriptionPayments: false, dialog: false, + payments: null as ResponsesUserSubscriptionPaymentsResponse | null, + selectedPayment: null as subscriptionPayment | null, + errorMessages: new ErrorMessages(), + invoiceFormName: '', + invoiceFormAddress: '', + invoiceFormCity: '', + invoiceFormState: '', + invoiceFormZipCode: '', + invoiceFormCountry: '', + invoiceFormNotes: '', + subscriptionInvoiceDialog: false, + countries: [ + { text: 'Afghanistan', value: 'AF' }, + { text: 'Åland Islands', value: 'AX' }, + { text: 'Albania', value: 'AL' }, + { text: 'Algeria', value: 'DZ' }, + { text: 'American Samoa', value: 'AS' }, + { text: 'Andorra', value: 'AD' }, + { text: 'Angola', value: 'AO' }, + { text: 'Anguilla', value: 'AI' }, + { text: 'Antarctica', value: 'AQ' }, + { text: 'Antigua and Barbuda', value: 'AG' }, + { text: 'Argentina', value: 'AR' }, + { text: 'Armenia', value: 'AM' }, + { text: 'Aruba', value: 'AW' }, + { text: 'Australia', value: 'AU' }, + { text: 'Austria', value: 'AT' }, + { text: 'Azerbaijan', value: 'AZ' }, + { text: 'Bahamas', value: 'BS' }, + { text: 'Bahrain', value: 'BH' }, + { text: 'Bangladesh', value: 'BD' }, + { text: 'Barbados', value: 'BB' }, + { text: 'Belarus', value: 'BY' }, + { text: 'Belgium', value: 'BE' }, + { text: 'Belize', value: 'BZ' }, + { text: 'Benin', value: 'BJ' }, + { text: 'Bermuda', value: 'BM' }, + { text: 'Bhutan', value: 'BT' }, + { text: 'Bolivia', value: 'BO' }, + { text: 'Bonaire', value: 'BQ' }, + { text: 'Bosnia and Herzegovina', value: 'BA' }, + { text: 'Botswana', value: 'BW' }, + { text: 'Bouvet Island', value: 'BV' }, + { text: 'Brazil', value: 'BR' }, + { text: 'British Indian Ocean', value: 'IO' }, + { text: 'Brunei Darussalam', value: 'BN' }, + { text: 'Bulgaria', value: 'BG' }, + { text: 'Burkina Faso', value: 'BF' }, + { text: 'Burundi', value: 'BI' }, + { text: 'Cabo Verde', value: 'CV' }, + { text: 'Cambodia', value: 'KH' }, + { text: 'Cameroon', value: 'CM' }, + { text: 'Canada', value: 'CA' }, + { text: 'Cayman Islands', value: 'KY' }, + { text: 'Central African Republic', value: 'CF' }, + { text: 'Chad', value: 'TD' }, + { text: 'Chile', value: 'CL' }, + { text: 'China', value: 'CN' }, + { text: 'Christmas Island', value: 'CX' }, + { text: 'Cocos (Keeling) Islands', value: 'CC' }, + { text: 'Colombia', value: 'CO' }, + { text: 'Comoros', value: 'KM' }, + { text: 'Congo', value: 'CG' }, + { text: 'Congo', value: 'CD' }, + { text: 'Cook Islands', value: 'CK' }, + { text: 'Costa Rica', value: 'CR' }, + { text: "Côte d'Ivoire", value: 'CI' }, + { text: 'Cuba', value: 'CU' }, + { text: 'Curaçao', value: 'CW' }, + { text: 'Cyprus', value: 'CY' }, + { text: 'Czechia', value: 'CZ' }, + { text: 'Denmark', value: 'DK' }, + { text: 'Djibouti', value: 'DJ' }, + { text: 'Dominica', value: 'DM' }, + { text: 'Dominican Republic', value: 'DO' }, + { text: 'Ecuador', value: 'EC' }, + { text: 'Egypt', value: 'EG' }, + { text: 'El Salvador', value: 'SV' }, + { text: 'Equatorial Guinea', value: 'GQ' }, + { text: 'Eritrea', value: 'ER' }, + { text: 'Estonia', value: 'EE' }, + { text: 'Eswatini', value: 'SZ' }, + { text: 'Ethiopia', value: 'ET' }, + { text: 'Falkland Islands', value: 'FK' }, + { text: 'Faroe Islands', value: 'FO' }, + { text: 'Fiji', value: 'FJ' }, + { text: 'Finland', value: 'FI' }, + { text: 'France', value: 'FR' }, + { text: 'French Guiana', value: 'GF' }, + { text: 'French Polynesia', value: 'PF' }, + { text: 'French Southern Territories', value: 'TF' }, + { text: 'Gabon', value: 'GA' }, + { text: 'Gambia', value: 'GM' }, + { text: 'Georgia', value: 'GE' }, + { text: 'Germany', value: 'DE' }, + { text: 'Ghana', value: 'GH' }, + { text: 'Gibraltar', value: 'GI' }, + { text: 'Greece', value: 'GR' }, + { text: 'Greenland', value: 'GL' }, + { text: 'Grenada', value: 'GD' }, + { text: 'Guadeloupe', value: 'GP' }, + { text: 'Guam', value: 'GU' }, + { text: 'Guatemala', value: 'GT' }, + { text: 'Guernsey', value: 'GG' }, + { text: 'Guinea', value: 'GN' }, + { text: 'Guinea-Bissau', value: 'GW' }, + { text: 'Guyana', value: 'GY' }, + { text: 'Haiti', value: 'HT' }, + { text: 'Heard Island and McDonald Islands', value: 'HM' }, + { text: 'Holy See', value: 'VA' }, + { text: 'Honduras', value: 'HN' }, + { text: 'Hong Kong', value: 'HK' }, + { text: 'Hungary', value: 'HU' }, + { text: 'Iceland', value: 'IS' }, + { text: 'India', value: 'IN' }, + { text: 'Indonesia', value: 'ID' }, + { text: 'Iran', value: 'IR' }, + { text: 'Iraq', value: 'IQ' }, + { text: 'Ireland', value: 'IE' }, + { text: 'Isle of Man', value: 'IM' }, + { text: 'Israel', value: 'IL' }, + { text: 'Italy', value: 'IT' }, + { text: 'Jamaica', value: 'JM' }, + { text: 'Japan', value: 'JP' }, + { text: 'Jersey', value: 'JE' }, + { text: 'Jordan', value: 'JO' }, + { text: 'Kazakhstan', value: 'KZ' }, + { text: 'Kenya', value: 'KE' }, + { text: 'Kiribati', value: 'KI' }, + { text: 'North Korea', value: 'KP' }, + { text: 'South Korea', value: 'KR' }, + { text: 'Kuwait', value: 'KW' }, + { text: 'Kyrgyzstan', value: 'KG' }, + { text: 'Lao People’s Democratic Republic', value: 'LA' }, + { text: 'Latvia', value: 'LV' }, + { text: 'Lebanon', value: 'LB' }, + { text: 'Lesotho', value: 'LS' }, + { text: 'Liberia', value: 'LR' }, + { text: 'Libya', value: 'LY' }, + { text: 'Liechtenstein', value: 'LI' }, + { text: 'Lithuania', value: 'LT' }, + { text: 'Luxembourg', value: 'LU' }, + { text: 'Macao', value: 'MO' }, + { text: 'Madagascar', value: 'MG' }, + { text: 'Malawi', value: 'MW' }, + { text: 'Malaysia', value: 'MY' }, + { text: 'Maldives', value: 'MV' }, + { text: 'Mali', value: 'ML' }, + { text: 'Malta', value: 'MT' }, + { text: 'Marshall Islands', value: 'MH' }, + { text: 'Martinique', value: 'MQ' }, + { text: 'Mauritania', value: 'MR' }, + { text: 'Mauritius', value: 'MU' }, + { text: 'Mayotte', value: 'YT' }, + { text: 'Mexico', value: 'MX' }, + { text: 'Micronesia', value: 'FM' }, + { text: 'Moldova', value: 'MD' }, + { text: 'Monaco', value: 'MC' }, + { text: 'Mongolia', value: 'MN' }, + { text: 'Montenegro', value: 'ME' }, + { text: 'Montserrat', value: 'MS' }, + { text: 'Morocco', value: 'MA' }, + { text: 'Mozambique', value: 'MZ' }, + { text: 'Myanmar', value: 'MM' }, + { text: 'Namibia', value: 'NA' }, + { text: 'Nauru', value: 'NR' }, + { text: 'Nepal', value: 'NP' }, + { text: 'Netherlands', value: 'NL' }, + { text: 'New Caledonia', value: 'NC' }, + { text: 'New Zealand', value: 'NZ' }, + { text: 'Nicaragua', value: 'NI' }, + { text: 'Niger', value: 'NE' }, + { text: 'Nigeria', value: 'NG' }, + { text: 'Niue', value: 'NU' }, + { text: 'Norfolk Island', value: 'NF' }, + { text: 'North Macedonia', value: 'MK' }, + { text: 'Northern Mariana Islands', value: 'MP' }, + { text: 'Norway', value: 'NO' }, + { text: 'Oman', value: 'OM' }, + { text: 'Pakistan', value: 'PK' }, + { text: 'Palau', value: 'PW' }, + { text: 'Panama', value: 'PA' }, + { text: 'Papua New Guinea', value: 'PG' }, + { text: 'Paraguay', value: 'PY' }, + { text: 'Peru', value: 'PE' }, + { text: 'Philippines', value: 'PH' }, + { text: 'Pitcairn', value: 'PN' }, + { text: 'Poland', value: 'PL' }, + { text: 'Portugal', value: 'PT' }, + { text: 'Puerto Rico', value: 'PR' }, + { text: 'Qatar', value: 'QA' }, + { text: 'Réunion', value: 'RE' }, + { text: 'Romania', value: 'RO' }, + { text: 'Russian Federation', value: 'RU' }, + { text: 'Rwanda', value: 'RW' }, + { text: 'Saint Barthélemy', value: 'BL' }, + { text: 'Saint Helena, Ascension and Tristan da Cunha', value: 'SH' }, + { text: 'Saint Kitts and Nevis', value: 'KN' }, + { text: 'Saint Lucia', value: 'LC' }, + { text: 'Saint Martin (French part)', value: 'MF' }, + { text: 'Saint Pierre and Miquelon', value: 'PM' }, + { text: 'Saint Vincent and the Grenadines', value: 'VC' }, + { text: 'Samoa', value: 'WS' }, + { text: 'San Marino', value: 'SM' }, + { text: 'Sao Tome and Principe', value: 'ST' }, + { text: 'Saudi Arabia', value: 'SA' }, + { text: 'Senegal', value: 'SN' }, + { text: 'Serbia', value: 'RS' }, + { text: 'Seychelles', value: 'SC' }, + { text: 'Sierra Leone', value: 'SL' }, + { text: 'Singapore', value: 'SG' }, + { text: 'Slovakia', value: 'SK' }, + { text: 'Slovenia', value: 'SI' }, + { text: 'Solomon Islands', value: 'SB' }, + { text: 'Somalia', value: 'SO' }, + { text: 'South Africa', value: 'ZA' }, + { text: 'South Georgia and the South Sandwich Islands', value: 'GS' }, + { text: 'South Sudan', value: 'SS' }, + { text: 'Spain', value: 'ES' }, + { text: 'Sri Lanka', value: 'LK' }, + { text: 'Sudan', value: 'SD' }, + { text: 'Suriname', value: 'SR' }, + { text: 'Svalbard and Jan Mayen', value: 'SJ' }, + { text: 'Sweden', value: 'SE' }, + { text: 'Switzerland', value: 'CH' }, + { text: 'Syrian Arab Republic', value: 'SY' }, + { text: 'Taiwan, Province of China', value: 'TW' }, + { text: 'Tajikistan', value: 'TJ' }, + { text: 'Tanzania, United Republic of', value: 'TZ' }, + { text: 'Thailand', value: 'TH' }, + { text: 'Timor-Leste', value: 'TL' }, + { text: 'Togo', value: 'TG' }, + { text: 'Tokelau', value: 'TK' }, + { text: 'Tonga', value: 'TO' }, + { text: 'Trinidad and Tobago', value: 'TT' }, + { text: 'Tunisia', value: 'TN' }, + { text: 'Turkey', value: 'TR' }, + { text: 'Turkmenistan', value: 'TM' }, + { text: 'Turks and Caicos Islands', value: 'TC' }, + { text: 'Tuvalu', value: 'TV' }, + { text: 'Uganda', value: 'UG' }, + { text: 'Ukraine', value: 'UA' }, + { text: 'United Arab Emirates', value: 'AE' }, + { text: 'United Kingdom', value: 'GB' }, + { text: 'United States', value: 'US' }, + { text: 'United States Minor Outlying Islands', value: 'UM' }, + { text: 'Uruguay', value: 'UY' }, + { text: 'Uzbekistan', value: 'UZ' }, + { text: 'Vanuatu', value: 'VU' }, + { text: 'Venezuela', value: 'VE' }, + { text: 'Viet Nam', value: 'VN' }, + { text: 'Virgin Islands (British)', value: 'VG' }, + { text: 'Virgin Islands (U.S.)', value: 'VI' }, + { text: 'Wallis and Futuna', value: 'WF' }, + { text: 'Western Sahara', value: 'EH' }, + { text: 'Yemen', value: 'YE' }, + { text: 'Zambia', value: 'ZM' }, + { text: 'Zimbabwe', value: 'ZW' }, + ], plans: [ { name: 'Free', @@ -459,6 +964,81 @@ export default Vue.extend({ } }, computed: { + invoiceStateOptions() { + if (this.invoiceFormCountry === 'US') { + return [ + { text: 'Alabama', value: 'AL' }, + { text: 'Alaska', value: 'AK' }, + { text: 'Arizona', value: 'AZ' }, + { text: 'Arkansas', value: 'AR' }, + { text: 'California', value: 'CA' }, + { text: 'Colorado', value: 'CO' }, + { text: 'Connecticut', value: 'CT' }, + { text: 'Delaware', value: 'DE' }, + { text: 'Florida', value: 'FL' }, + { text: 'Georgia', value: 'GA' }, + { text: 'Hawaii', value: 'HI' }, + { text: 'Idaho', value: 'ID' }, + { text: 'Illinois', value: 'IL' }, + { text: 'Indiana', value: 'IN' }, + { text: 'Iowa', value: 'IA' }, + { text: 'Kansas', value: 'KS' }, + { text: 'Kentucky', value: 'KY' }, + { text: 'Louisiana', value: 'LA' }, + { text: 'Maine', value: 'ME' }, + { text: 'Maryland', value: 'MD' }, + { text: 'Massachusetts', value: 'MA' }, + { text: 'Michigan', value: 'MI' }, + { text: 'Minnesota', value: 'MN' }, + { text: 'Mississippi', value: 'MS' }, + { text: 'Missouri', value: 'MO' }, + { text: 'Montana', value: 'MT' }, + { text: 'Nebraska', value: 'NE' }, + { text: 'Nevada', value: 'NV' }, + { text: 'New Hampshire', value: 'NH' }, + { text: 'New Jersey', value: 'NJ' }, + { text: 'New Mexico', value: 'NM' }, + { text: 'New York', value: 'NY' }, + { text: 'North Carolina', value: 'NC' }, + { text: 'North Dakota', value: 'ND' }, + { text: 'Ohio', value: 'OH' }, + { text: 'Oklahoma', value: 'OK' }, + { text: 'Oregon', value: 'OR' }, + { text: 'Pennsylvania', value: 'PA' }, + { text: 'Rhode Island', value: 'RI' }, + { text: 'South Carolina', value: 'SC' }, + { text: 'South Dakota', value: 'SD' }, + { text: 'Tennessee', value: 'TN' }, + { text: 'Texas', value: 'TX' }, + { text: 'Utah', value: 'UT' }, + { text: 'Vermont', value: 'VT' }, + { text: 'Virginia', value: 'VA' }, + { text: 'Washington', value: 'WA' }, + { text: 'West Virginia', value: 'WV' }, + { text: 'Wisconsin', value: 'WI' }, + { text: 'Wyoming', value: 'WY' }, + { text: 'District of Columbia', value: 'DC' }, + ] + } + if (this.invoiceFormCountry === 'CA') { + return [ + { text: 'Alberta', value: 'AB' }, + { text: 'British Columbia', value: 'BC' }, + { text: 'Manitoba', value: 'MB' }, + { text: 'New Brunswick', value: 'NB' }, + { text: 'Newfoundland and Labrador', value: 'NL' }, + { text: 'Nova Scotia', value: 'NS' }, + { text: 'Ontario', value: 'ON' }, + { text: 'Prince Edward Island', value: 'PE' }, + { text: 'Quebec', value: 'QC' }, + { text: 'Saskatchewan', value: 'SK' }, + { text: 'Northwest Territories', value: 'NT' }, + { text: 'Nunavut', value: 'NU' }, + { text: 'Yukon', value: 'YT' }, + ] + } + return [] + }, checkoutURL() { const url = new URL(this.$config.checkoutURL) const user = this.$store.getters.getAuthUser @@ -513,7 +1093,51 @@ export default Vue.extend({ this.$store.dispatch('loadBillingUsageHistory'), ]) this.loading = false + this.loadSubscriptionInvoices() + }, + + loadSubscriptionInvoices() { + this.loadingSubscriptionPayments = true + this.$store + .dispatch('indexSubscriptionPayments') + .then((response: ResponsesUserSubscriptionPaymentsResponse) => { + this.payments = response + }) + .finally(() => { + this.loadingSubscriptionPayments = false + }) }, + + generateInvoice() { + this.errorMessages = new ErrorMessages() + this.loading = true + this.$store + .dispatch('generateSubscriptionPaymentInvoice', { + subscriptionInvoiceId: this.selectedPayment?.id || '', + request: { + name: this.invoiceFormName, + address: this.invoiceFormAddress, + city: this.invoiceFormCity, + state: this.invoiceFormState, + zip_code: this.invoiceFormZipCode, + country: this.invoiceFormCountry, + notes: this.invoiceFormNotes, + }, + } as { + subscriptionInvoiceId: string + request: RequestsUserPaymentInvoice + }) + .then(() => { + this.subscriptionInvoiceDialog = false + }) + .catch((error: ErrorMessages) => { + this.errorMessages = error + }) + .finally(() => { + this.loading = false + }) + }, + updateDetails() { this.loading = true this.$store @@ -540,6 +1164,11 @@ export default Vue.extend({ this.loading = false }) }, + + showInvoiceDialog(payment: subscriptionPayment) { + this.selectedPayment = payment + this.subscriptionInvoiceDialog = true + }, }, }) diff --git a/web/pages/bulk-messages/index.vue b/web/pages/bulk-messages/index.vue index 5b8f2011..74632210 100644 --- a/web/pages/bulk-messages/index.vue +++ b/web/pages/bulk-messages/index.vue @@ -39,7 +39,15 @@ >Excel template and upload it here to send your SMS messages to multiple - recipients at once. + recipients at once. You can also configure + send schedules + on your phone to make sure messages are sent out at specific times + of the day e.g + Mon - Fri 9am - 5pm.

{{ errorTitle }}
@@ -88,6 +96,62 @@ + + +

Bulk Message History

+

+ Your 10 most recent bulk SMS uploads are shown below, including a + delivery status breakdown for each batch. Click on a row to see + individual messages on the search page. +

+ + + + +
+
@@ -137,9 +201,11 @@ export default Vue.extend({ mdiSquareEditOutline, formFile: null, loading: true, + loadingHistory: true, errorTitle: '', errorMessages: new ErrorMessages(), dialog: false, + bulkOrders: [] as any[], } }, head() { @@ -151,8 +217,32 @@ export default Vue.extend({ async mounted() { await this.$store.dispatch('loadUser') this.loading = false + this.fetchBulkOrders() }, methods: { + cleanName(requestId: string): string { + if (requestId.startsWith('bulk-csv-')) { + return requestId.replace(/^bulk-csv-/, '') + '.csv' + } + if (requestId.startsWith('bulk-xls-')) { + return requestId.replace(/^bulk-xls-/, '') + '.xlsx' + } + return requestId.replace(/^bulk-/, '') + }, + fetchBulkOrders() { + this.loadingHistory = true + this.$store + .dispatch('fetchBulkMessageOrders') + .then((orders: any[]) => { + this.bulkOrders = orders + }) + .catch(() => { + // silently fail - the table will show "no data" + }) + .finally(() => { + this.loadingHistory = false + }) + }, sendBulkMessages() { this.loading = true this.errorMessages = new ErrorMessages() @@ -178,3 +268,13 @@ export default Vue.extend({ }, }) + + diff --git a/web/pages/index.vue b/web/pages/index.vue index dad84598..731aaecb 100644 --- a/web/pages/index.vue +++ b/web/pages/index.vue @@ -51,8 +51,8 @@

- ⚡Trusted by 8,370+ happy users who have sent or received - more than 3,994,092+ messages. + ⚡Trusted by 23,273+ users who send/receive more than + 500,000 messages per month.

excel template - and upload it on httpSMS to send your SMS messages to multiple + and upload it on httpSMS to send SMS messages to up to 1,000 recipients at once without writing any code. + + +
+

Schedule Text Messages

+
+ Control when your SMS will reach your recipients, allowing you + to perfectly time promotions, critical alerts etc by scheduling + your messages in advance. +
+ {{ mdiClockOutline }}Documentation +
+
+ + + +
@@ -642,6 +668,26 @@ Console.WriteLine(await response.Content.ReadAsStringAsync());
+ + + + + + + @@ -734,23 +780,28 @@ Console.WriteLine(await response.Content.ReadAsStringAsync()); - + -

Ultra

+

+ {{ pricingLabels[pricing] }} Plan +

- Send and receive up to 10,000 SMS messages like a power user. + Send and receive up to {{ planMessages }} SMS messages like a + power user.

- $20/month + ${{ planMonthlyPrice }}/month

- $200/year + ${{ planYearlyPrice }}/year

- or $200 per year + or ${{ planYearlyPrice }} per year

- or $16.66 per month + or ${{ planYearlyMonthlyPrice }} per month

Try For Free{{ mdiCheckCircle }}Send or receive up to 10,000 SMS/month + >Send or receive up to + {{ pricingLabels[pricing] }} SMS/month

@@ -899,7 +951,7 @@ Console.WriteLine(await response.Content.ReadAsStringAsync()); Can I install the app on my Iphone? -