Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Add local setup guide. #42

Acho Arnold24cf8842f559
diff --git a/.gitignore b/.gitignore
index aa102647..b114cdd0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
.idea
.env*
+!.env.docker
+!.env.production
*serviceAccountKey.json
android/app/debug/
*main.exe*
diff --git a/README.md b/README.md
index f634fa60..a4303575 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,34 @@ Quick Start Guide 👉 [https://docs.httpsms.com](https://docs.httpsms.com)
<img width="1115" alt="header" src="https://user-images.githubusercontent.com/4196457/194767449-f12d84a0-22f1-4787-afb2-17398fb459f6.png">
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+
+- [Why?](#why)
+- [Web UI](#web-ui)
+- [API](#api)
+- [Android App](#android-app)
+- [Chat/forum](#chatforum)
+- [Features](#features)
+ - [End-to-end Encryption](#end-to-end-encryption)
+ - [Webhook](#webhook)
+ - [Back Pressure](#back-pressure)
+ - [Message Expiration](#message-expiration)
+- [API Clients](#api-clients)
+- [Flows](#flows)
+ - [Sending an SMS Message](#sending-an-sms-message)
+- [Local Setup - Docker](#local-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)
+- [License](#license)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
## Why?
I'm originally from Cameroon and I wanted an automated way to send and receive SMS messages using an API.
@@ -83,8 +111,8 @@ will be notified.
## API Clients
-- Go: https://github.com/NdoleStudio/httpsms-go
-- JavaScript/TypeScript: https://github.com/NdoleStudio/httpsms-node
+- [x] Go: https://github.com/NdoleStudio/httpsms-go
+- [x] JavaScript/TypeScript: https://github.com/NdoleStudio/httpsms-node
## Flows
@@ -103,6 +131,93 @@ Android App-->>httpSMS API: [Async] Send result of sending SMS
Android App-->>httpSMS API: [Async] Send Delivery Report
```
+## Local Setup - Docker
+
+### 1. Setup Firebase
+
+- The httpSMS application uses [firebase cloud messaging](https://firebase.google.com/docs/cloud-messaging) for sending push notifications to your Android phone to trigger an SMS message to be sent out.
+ Visit the [firebase console](https://console.firebase.google.com/) and create a new project and follow the [steps here](https://firebase.google.com/docs/web/setup#register-app) to get your firebase web SDK config credentials.
+ For example, I created a firebase project called `httpsms-docker` and this is my web SDK configuration
+
+```js
+const firebaseConfig = {
+ apiKey: "AIzaSyAKqPvj51igvvNNcRt_gL0A6cgx3ZB-kuQ",
+ authDomain: "httpsms-docker.firebaseapp.com",
+ projectId: "httpsms-docker",
+ storageBucket: "httpsms-docker.appspot.com",
+ messagingSenderId: "668063041624",
+ appId: "1:668063041624:web:29b9e3b7027965ba08a22d",
+ measurementId: "G-18VRYL22PZ",
+};
+```
+
+- Enable `Email/Password` sign-in in the [Firebase console](https://console.firebase.google.com/u/0/), open the **Authentication** section. On the Sign in method tab, enable the `Email/password` sign-in method and click `Save`.
+- Generate your firebase service account credentials by following the [steps here](https://firebase.google.com/docs/admin/setup#initialize_the_sdk_in_non-google_environments) and save the credentials in a file called `firebase-credentials.json` we will use this file to authenticate with the firebase admin SDK.
+- Generate your Android `google-services.json` file using [the instructions here](https://support.google.com/firebase/answer/7015592?hl=en#android&zippy=%2Cin-this-article) we will use it letter to configure the android app.
+
+### 2. Setup SMTP Email service
+
+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
+
+Clone the httpSMS GitHub repository
+
+```bash
+git clone https://github.com/NdoleStudio/httpsms.git
+```
+
+### 4. Setup the environment variables
+
+- Copy the `.env.docker` file in the `web` directory into `.env` and update the environment variables with your firebase web SDK configuration.
+
+```bash
+cp web/.env.local.docker web/.env.local
+```
+
+- Copy the `.env.docker` file in the `api` directory into `.env`
+
+```bash
+cp api/.env.local.docker api/.env.local
+```
+
+- Update the environment variables in the `.env` file in the `api` directory with your firebase service account credentials and SMTP server details.
+
+```dotenv
+# SMTP email server settings
+SMTP_USERNAME=
+SMTP_PASSWORD=
+SMTP_HOST=
+SMTP_PORT=
+
+# Firebase service account credentials
+FIREBASE_CREDENTIALS=
+
+# This is the `projectId` from your firebase web config
+GCP_PROJECT_ID=
+```
+
+- 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
+
+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
+
+```bash
+docker compose up --build
+```
+
+### 6. 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
+
+### 7. 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.
+
## License
This project is licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - see the [LICENSE](LICENSE) file for details
diff --git a/api/.env.docker b/api/.env.docker
new file mode 100644
index 00000000..704fcfb1
--- /dev/null
+++ b/api/.env.docker
@@ -0,0 +1,53 @@
+ENV=production
+
+# This is the project-id of the firebase project you created in the setup instructions
+GCP_PROJECT_ID=httpsms-docker
+
+USE_HTTP_LOGGER=true
+
+EVENTS_QUEUE_TYPE=emulator
+EVENTS_QUEUE_NAME=events-local
+EVENTS_QUEUE_ENDPOINT=http://localhost:8000/v1/events
+
+# This is the user API key for the system admin user that is used to authenticate requests to the /v1/events endpoint
+# You need to create a system user in the `users` table in your database and put the API key and ID of this user here
+EVENTS_QUEUE_USER_API_KEY=system-user-api-key
+EVENTS_QUEUE_USER_ID=system-user-id
+
+# This is the actual conetnt of your service account firebase-credentials.json file that you downloaded in the setup instructions
+# e.g FIREBASE_CREDENTIALS='{ "type": "service_account", "project_id": "httpsms-docker", "private_key_id":.....
+FIREBASE_CREDENTIALS=
+
+# This is the from name for your emails
+SMTP_FROM_NAME=httpSMS
+# This is the address where your email messages should come from. You should make sure this matches what is configured on your SMTP service
+
+# These are the credentials for your SMTP email service
+SMTP_USERNAME=
+SMTP_PASSWORD=
+SMTP_HOST=smtp.mailtrap.io
+SMTP_PORT=2525
+
+# This is the URL of the application UI and it's used to generate links in emails
+APP_URL=http://localhost:3000
+
+# The name of the application you can set it to whatever you like
+APP_NAME=httpSMS
+
+# This is the port where the API server will run on
+APP_PORT=8000
+
+# Host for the swagger UI
+SWAGGER_HOST=localhost:8000
+
+# Postgresql Database connection string
+DATABASE_URL=postgresql://dbusername:dbpassword@postgres:5432/httpsms
+DATABASE_URL_DEDICATED=postgresql://dbusername:dbpassword@postgres:5432/httpsms
+
+# Redis connection string
+REDIS_URL=redis://redisusername:redispassword@redis:6379
+
+# [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=
diff --git a/api/.gitignore b/api/.gitignore
index 41524b6d..78b2e765 100644
--- a/api/.gitignore
+++ b/api/.gitignore
@@ -1,4 +1,4 @@
-.env
+.env.local
*main.exe
tmp
$path
@@ -7,3 +7,4 @@ $path
.flaskenv*
!.env.project
!.env.vault
+!.env.docker
diff --git a/api/main.go b/api/main.go
index 81982dd6..c31a53ee 100644
--- a/api/main.go
+++ b/api/main.go
@@ -4,7 +4,7 @@ import (
"fmt"
"os"
- _ "github.com/NdoleStudio/httpsms/docs"
+ "github.com/NdoleStudio/httpsms/docs"
"github.com/NdoleStudio/httpsms/pkg/di"
)
@@ -22,7 +22,7 @@ var Version string
// @license.url https://raw.githubusercontent.com/NdoleStudio/http-sms-manager/main/LICENSE
//
// @host api.httpsms.com
-// @schemes https
+// @schemes http https
// @BasePath /v1
//
// @securitydefinitions.apikey ApiKeyAuth
@@ -33,6 +33,8 @@ func main() {
di.LoadEnv()
}
+ docs.SwaggerInfo.Host = os.Getenv("SWAGGER_HOST")
+
container := di.NewContainer("http-sms", Version)
container.Logger().Info(container.App().Listen(fmt.Sprintf("%s:%s", os.Getenv("APP_HOST"), os.Getenv("APP_PORT"))).Error())
}
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index b68461af..1187b1ff 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -159,7 +159,7 @@ func (container *Container) App() (app *fiber.App) {
app = fiber.New()
- if os.Getenv("APP_HTTP_LOGGER") == "true" {
+ if os.Getenv("USE_HTTP_LOGGER") == "true" {
app.Use(fiberLogger.New())
}
@@ -1335,10 +1335,6 @@ func (container *Container) RistrettoCache() (cache *ristretto.Cache) {
// InitializeTraceProvider initializes the open telemetry trace provider
func (container *Container) InitializeTraceProvider() func() {
return container.initializeUptraceProvider(container.version, container.projectID)
- //if isLocal() {
- // return container.initializeUptraceProvider(container.version, container.projectID)
- //}
- //return container.initializeGoogleTraceProvider(container.version, container.projectID)
}
func (container *Container) initializeGoogleTraceProvider(version string, namespace string) func() {
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..16e885e9
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,55 @@
+version: "3.8"
+
+services:
+ postgres:
+ image: postgres:alpine
+ environment:
+ POSTGRES_DB: httpsms
+ POSTGRES_PASSWORD: dbpassword
+ POSTGRES_USER: dbusername
+ volumes:
+ - postgres:/var/lib/postgresql/data
+ ports:
+ - "5435:5432"
+ restart: on-failure
+ healthcheck:
+ test: ["CMD-SHELL", "pg_isready", "-U", "dbusername", "-d", "httpsms"]
+ interval: 30s
+ timeout: 60s
+ retries: 5
+ start_period: 5s
+
+ redis:
+ image: redis:latest
+ command: redis-server
+ volumes:
+ - redis:/var/lib/redis
+ ports:
+ - "6379:6379"
+ restart: on-failure
+
+ api:
+ build:
+ context: ./api
+ ports:
+ - "8000:8000"
+ depends_on:
+ postgres:
+ condition: service_healthy
+ redis:
+ condition: service_started
+ env_file:
+ - ./api/.env
+
+ web:
+ build:
+ context: ./web
+ ports:
+ - "3000:3000"
+ depends_on:
+ api:
+ condition: service_started
+
+volumes:
+ redis:
+ postgres:
diff --git a/web/.dockerignore b/web/.dockerignore
new file mode 100644
index 00000000..492c4b07
--- /dev/null
+++ b/web/.dockerignore
@@ -0,0 +1,3 @@
+node_modules
+coverage
+.nuxt
diff --git a/web/.env.docker b/web/.env.docker
new file mode 100644
index 00000000..d48c328f
--- /dev/null
+++ b/web/.env.docker
@@ -0,0 +1,17 @@
+API_BASE_URL=http://localhost:8000
+
+APP_URL=http://localhost:3000
+APP_NAME=httpSMS
+APP_GITHUB_URL=https://github.com/NdoleStudio/httpsms
+APP_DOCUMENTATION_URL=https://docs.httpsms.com
+APP_DOWNLOAD_URL=https://github.com/NdoleStudio/httpsms/releases/latest/download/HttpSms.apk
+APP_ENV=production
+
+# Firebase credentials
+FIREBASE_API_KEY=AIzaSyAKqPvj51igvvNNcRt_gL0A6cgx3ZB-kuQ
+FIREBASE_AUTH_DOMAIN=httpsms-docker.firebaseapp.com
+FIREBASE_PROJECT_ID=httpsms-docker
+FIREBASE_STORAGE_BUCKET=httpsms-docker.appspot.com
+FIREBASE_MESSAGING_SENDER_ID=668063041624
+FIREBASE_APP_ID=668063041624:web:29b9e3b7027965ba08a22d
+FIREBASE_MEASUREMENT_ID=G-18VRYL22PZ
diff --git a/web/.env.production b/web/.env.production
index c6425bfb..5e3f31a9 100644
--- a/web/.env.production
+++ b/web/.env.production
@@ -1,7 +1,7 @@
-BASE_URL=https://api.httpsms.com
+API_BASE_URL=https://api.httpsms.com
APP_URL=https://httpsms.com
-APP_NAME="HTTP SMS"
+APP_NAME=httpSMS
APP_GITHUB_URL=https://github.com/NdoleStudio/httpsms
APP_DOCUMENTATION_URL=https://docs.httpsms.com
APP_DOWNLOAD_URL=https://github.com/NdoleStudio/httpsms/releases/latest/download/HttpSms.apk
@@ -9,3 +9,11 @@ APP_ENV=production
CHECKOUT_URL=https://httpsms.lemonsqueezy.com/checkout/buy/706c5638-4c8d-40db-a6f2-b6371b7e0af4
ENTERPRISE_CHECKOUT_URL=https://httpsms.lemonsqueezy.com/checkout/buy/d107cf05-4b13-4ebd-a770-c2cc75c69a14
+
+FIREBASE_API_KEY=AIzaSyClL8AX2H_F77_n8yu5FgLzBmJTiSM0NsQ
+FIREABSE_AUTH_DOMAIN=httpsms-86c51.firebaseapp.com
+FIREBASE_PROJECT_ID=httpsms-86c51
+FIREBASE_STORAGE_BUCKET=httpsms-86c51.appspot.com
+FIREBASE_MESSAGING_SENDER_ID=877524083399
+FIREBASE_APP_ID=1:877524083399:web:430d6a29a0d808946514e2
+FIREBASE_MEASUREMENT_ID=G-EZ5W9DVK8T
diff --git a/web/Dockerfile b/web/Dockerfile
new file mode 100644
index 00000000..5b35076c
--- /dev/null
+++ b/web/Dockerfile
@@ -0,0 +1,24 @@
+# build stage
+FROM node:lts-alpine as build
+
+WORKDIR /app
+
+COPY package*.json ./
+
+# Install pnpm
+RUN npm install -g pnpm
+
+RUN pnpm install
+COPY . .
+RUN pnpm run generate
+
+# production stage
+FROM nginx:stable-alpine as production
+COPY --from=build /app/dist /usr/share/nginx/html
+
+# Copy the nginx configuration file
+COPY ./nginx.conf /etc/nginx/conf.d/default.conf
+
+EXPOSE 3000
+
+CMD ["nginx", "-g", "daemon off;"]
diff --git a/web/nginx.conf b/web/nginx.conf
new file mode 100644
index 00000000..979fe802
--- /dev/null
+++ b/web/nginx.conf
@@ -0,0 +1,9 @@
+server {
+ listen 3000;
+ server_name localhost;
+ root /usr/share/nginx/html;
+ index index.html index.htm;
+location / {
+ try_files $uri $uri/ /index.html;
+ }
+}
diff --git a/web/nuxt.config.js b/web/nuxt.config.js
index bd28a0ff..ccdbbd95 100644
--- a/web/nuxt.config.js
+++ b/web/nuxt.config.js
@@ -90,13 +90,13 @@ export default {
'@nuxtjs/firebase',
{
config: {
- apiKey: 'AIzaSyClL8AX2H_F77_n8yu5FgLzBmJTiSM0NsQ',
- authDomain: 'httpsms-86c51.firebaseapp.com',
- projectId: 'httpsms-86c51',
- storageBucket: 'httpsms-86c51.appspot.com',
- messagingSenderId: '877524083399',
- appId: '1:877524083399:web:430d6a29a0d808946514e2',
- measurementId: 'G-EZ5W9DVK8T',
+ apiKey: process.env.FIREBASE_API_KEY,
+ authDomain: process.env.FIREBASE_AUTH_DOMAIN,
+ projectId: process.env.FIREBASE_PROJECT_ID,
+ storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
+ messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
+ appId: process.env.FIREBASE_APP_ID,
+ measurementId: process.env.FIREBASE_MEASUREMENT_ID,
},
services: {
analytics: true,
diff --git a/web/plugins/axios.ts b/web/plugins/axios.ts
index 83b1f27c..5bed0603 100644
--- a/web/plugins/axios.ts
+++ b/web/plugins/axios.ts
@@ -1,7 +1,7 @@
import axios from 'axios'
const client = axios.create({
- baseURL: process.env.BASE_URL || 'http://localhost:8000',
+ baseURL: process.env.API_BASE_URL || 'http://localhost:8000',
headers: {
'X-Client-Version': process.env.GITHUB_SHA || 'dev',
},
diff --git a/web/store/README.md b/web/store/README.md
deleted file mode 100644
index 1972d277..00000000
--- a/web/store/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-# STORE
-
-**This directory is not required, you can delete it if you don't want to use it.**
-
-This directory contains your Vuex Store files.
-Vuex Store option is implemented in the Nuxt.js framework.
-
-Creating a file in this directory automatically activates the option in the framework.
-
-More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store).