Skip to content

Commit 24cf884

Browse files
committed
Add local setup guide. NdoleStudio#42
1 parent 9554540 commit 24cf884

15 files changed

Lines changed: 305 additions & 30 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.idea
22
.env*
3+
!.env.docker
4+
!.env.production
35
*serviceAccountKey.json
46
android/app/debug/
57
*main.exe*

README.md

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ Quick Start Guide 👉 [https://docs.httpsms.com](https://docs.httpsms.com)
1515

1616
<img width="1115" alt="header" src="https://user-images.githubusercontent.com/4196457/194767449-f12d84a0-22f1-4787-afb2-17398fb459f6.png">
1717

18+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
19+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
20+
21+
- [Why?](#why)
22+
- [Web UI](#web-ui)
23+
- [API](#api)
24+
- [Android App](#android-app)
25+
- [Chat/forum](#chatforum)
26+
- [Features](#features)
27+
- [End-to-end Encryption](#end-to-end-encryption)
28+
- [Webhook](#webhook)
29+
- [Back Pressure](#back-pressure)
30+
- [Message Expiration](#message-expiration)
31+
- [API Clients](#api-clients)
32+
- [Flows](#flows)
33+
- [Sending an SMS Message](#sending-an-sms-message)
34+
- [Local Setup - Docker](#local-setup---docker)
35+
- [1. Setup Firebase](#1-setup-firebase)
36+
- [2. Setup SMTP Email service](#2-setup-smtp-email-service)
37+
- [3. Download the code](#3-download-the-code)
38+
- [4. Setup the environment variables](#4-setup-the-environment-variables)
39+
- [5. Build and Run](#5-build-and-run)
40+
- [6. Create the System User](#6-create-the-system-user)
41+
- [7. Build the Android App.](#7-build-the-android-app)
42+
- [License](#license)
43+
44+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
45+
1846
## Why?
1947

2048
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.
83111

84112
## API Clients
85113

86-
- Go: https://github.com/NdoleStudio/httpsms-go
87-
- JavaScript/TypeScript: https://github.com/NdoleStudio/httpsms-node
114+
- [x] Go: https://github.com/NdoleStudio/httpsms-go
115+
- [x] JavaScript/TypeScript: https://github.com/NdoleStudio/httpsms-node
88116

89117
## Flows
90118

@@ -103,6 +131,93 @@ Android App-->>httpSMS API: [Async] Send result of sending SMS
103131
Android App-->>httpSMS API: [Async] Send Delivery Report
104132
```
105133

134+
## Local Setup - Docker
135+
136+
### 1. Setup Firebase
137+
138+
- 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.
139+
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.
140+
For example, I created a firebase project called `httpsms-docker` and this is my web SDK configuration
141+
142+
```js
143+
const firebaseConfig = {
144+
apiKey: "AIzaSyAKqPvj51igvvNNcRt_gL0A6cgx3ZB-kuQ",
145+
authDomain: "httpsms-docker.firebaseapp.com",
146+
projectId: "httpsms-docker",
147+
storageBucket: "httpsms-docker.appspot.com",
148+
messagingSenderId: "668063041624",
149+
appId: "1:668063041624:web:29b9e3b7027965ba08a22d",
150+
measurementId: "G-18VRYL22PZ",
151+
};
152+
```
153+
154+
- 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`.
155+
- 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.
156+
- 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.
157+
158+
### 2. Setup SMTP Email service
159+
160+
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.
161+
You can use a service like [mailtrap](https://mailtrap.io/) to create an SMTP server for development purposes.
162+
163+
### 3. Download the code
164+
165+
Clone the httpSMS GitHub repository
166+
167+
```bash
168+
git clone https://github.com/NdoleStudio/httpsms.git
169+
```
170+
171+
### 4. Setup the environment variables
172+
173+
- Copy the `.env.docker` file in the `web` directory into `.env` and update the environment variables with your firebase web SDK configuration.
174+
175+
```bash
176+
cp web/.env.local.docker web/.env.local
177+
```
178+
179+
- Copy the `.env.docker` file in the `api` directory into `.env`
180+
181+
```bash
182+
cp api/.env.local.docker api/.env.local
183+
```
184+
185+
- Update the environment variables in the `.env` file in the `api` directory with your firebase service account credentials and SMTP server details.
186+
187+
```dotenv
188+
# SMTP email server settings
189+
SMTP_USERNAME=
190+
SMTP_PASSWORD=
191+
SMTP_HOST=
192+
SMTP_PORT=
193+
194+
# Firebase service account credentials
195+
FIREBASE_CREDENTIALS=
196+
197+
# This is the `projectId` from your firebase web config
198+
GCP_PROJECT_ID=
199+
```
200+
201+
- Don't bother about the `EVENTS_QUEUE_USER_API_KEY` and `EVENTS_QUEUE_USER_ID` settings. We will set that up later.
202+
203+
### 5. Build and Run
204+
205+
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.
206+
When it's finished, you'll be able to access the web UI at http://localhost:3000 and the API at http://localhost:8000
207+
208+
```bash
209+
docker compose up --build
210+
```
211+
212+
### 6. Create the System User
213+
214+
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.
215+
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
216+
217+
### 7. Build the Android App.
218+
219+
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.
220+
106221
## License
107222

108223
This project is licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - see the [LICENSE](LICENSE) file for details

api/.env.docker

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
ENV=production
2+
3+
# This is the project-id of the firebase project you created in the setup instructions
4+
GCP_PROJECT_ID=httpsms-docker
5+
6+
USE_HTTP_LOGGER=true
7+
8+
EVENTS_QUEUE_TYPE=emulator
9+
EVENTS_QUEUE_NAME=events-local
10+
EVENTS_QUEUE_ENDPOINT=http://localhost:8000/v1/events
11+
12+
# This is the user API key for the system admin user that is used to authenticate requests to the /v1/events endpoint
13+
# 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
14+
EVENTS_QUEUE_USER_API_KEY=system-user-api-key
15+
EVENTS_QUEUE_USER_ID=system-user-id
16+
17+
# This is the actual conetnt of your service account firebase-credentials.json file that you downloaded in the setup instructions
18+
# e.g FIREBASE_CREDENTIALS='{ "type": "service_account", "project_id": "httpsms-docker", "private_key_id":.....
19+
FIREBASE_CREDENTIALS=
20+
21+
# This is the from name for your emails
22+
SMTP_FROM_NAME=httpSMS
23+
# This is the address where your email messages should come from. You should make sure this matches what is configured on your SMTP service
24+
SMTP_FROM_EMAIL=httpsms@local.com
25+
26+
# These are the credentials for your SMTP email service
27+
SMTP_USERNAME=
28+
SMTP_PASSWORD=
29+
SMTP_HOST=smtp.mailtrap.io
30+
SMTP_PORT=2525
31+
32+
# This is the URL of the application UI and it's used to generate links in emails
33+
APP_URL=http://localhost:3000
34+
35+
# The name of the application you can set it to whatever you like
36+
APP_NAME=httpSMS
37+
38+
# This is the port where the API server will run on
39+
APP_PORT=8000
40+
41+
# Host for the swagger UI
42+
SWAGGER_HOST=localhost:8000
43+
44+
# Postgresql Database connection string
45+
DATABASE_URL=postgresql://dbusername:dbpassword@postgres:5432/httpsms
46+
DATABASE_URL_DEDICATED=postgresql://dbusername:dbpassword@postgres:5432/httpsms
47+
48+
# Redis connection string
49+
REDIS_URL=redis://redisusername:redispassword@redis:6379
50+
51+
# [optional] If you would like to use uptrace.dev for distributed tracing, you can set the DSN here.
52+
# This is optional and you can leave it empty if you don't want to use uptrace
53+
UPTRACE_DSN=

api/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.env
1+
.env.local
22
*main.exe
33
tmp
44
$path
@@ -7,3 +7,4 @@ $path
77
.flaskenv*
88
!.env.project
99
!.env.vault
10+
!.env.docker

api/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66

7-
_ "github.com/NdoleStudio/httpsms/docs"
7+
"github.com/NdoleStudio/httpsms/docs"
88
"github.com/NdoleStudio/httpsms/pkg/di"
99
)
1010

@@ -22,7 +22,7 @@ var Version string
2222
// @license.url https://raw.githubusercontent.com/NdoleStudio/http-sms-manager/main/LICENSE
2323
//
2424
// @host api.httpsms.com
25-
// @schemes https
25+
// @schemes http https
2626
// @BasePath /v1
2727
//
2828
// @securitydefinitions.apikey ApiKeyAuth
@@ -33,6 +33,8 @@ func main() {
3333
di.LoadEnv()
3434
}
3535

36+
docs.SwaggerInfo.Host = os.Getenv("SWAGGER_HOST")
37+
3638
container := di.NewContainer("http-sms", Version)
3739
container.Logger().Info(container.App().Listen(fmt.Sprintf("%s:%s", os.Getenv("APP_HOST"), os.Getenv("APP_PORT"))).Error())
3840
}

api/pkg/di/container.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (container *Container) App() (app *fiber.App) {
159159

160160
app = fiber.New()
161161

162-
if os.Getenv("APP_HTTP_LOGGER") == "true" {
162+
if os.Getenv("USE_HTTP_LOGGER") == "true" {
163163
app.Use(fiberLogger.New())
164164
}
165165

@@ -1335,10 +1335,6 @@ func (container *Container) RistrettoCache() (cache *ristretto.Cache) {
13351335
// InitializeTraceProvider initializes the open telemetry trace provider
13361336
func (container *Container) InitializeTraceProvider() func() {
13371337
return container.initializeUptraceProvider(container.version, container.projectID)
1338-
//if isLocal() {
1339-
// return container.initializeUptraceProvider(container.version, container.projectID)
1340-
//}
1341-
//return container.initializeGoogleTraceProvider(container.version, container.projectID)
13421338
}
13431339

13441340
func (container *Container) initializeGoogleTraceProvider(version string, namespace string) func() {

docker-compose.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: "3.8"
2+
3+
services:
4+
postgres:
5+
image: postgres:alpine
6+
environment:
7+
POSTGRES_DB: httpsms
8+
POSTGRES_PASSWORD: dbpassword
9+
POSTGRES_USER: dbusername
10+
volumes:
11+
- postgres:/var/lib/postgresql/data
12+
ports:
13+
- "5435:5432"
14+
restart: on-failure
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready", "-U", "dbusername", "-d", "httpsms"]
17+
interval: 30s
18+
timeout: 60s
19+
retries: 5
20+
start_period: 5s
21+
22+
redis:
23+
image: redis:latest
24+
command: redis-server
25+
volumes:
26+
- redis:/var/lib/redis
27+
ports:
28+
- "6379:6379"
29+
restart: on-failure
30+
31+
api:
32+
build:
33+
context: ./api
34+
ports:
35+
- "8000:8000"
36+
depends_on:
37+
postgres:
38+
condition: service_healthy
39+
redis:
40+
condition: service_started
41+
env_file:
42+
- ./api/.env
43+
44+
web:
45+
build:
46+
context: ./web
47+
ports:
48+
- "3000:3000"
49+
depends_on:
50+
api:
51+
condition: service_started
52+
53+
volumes:
54+
redis:
55+
postgres:

web/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
coverage
3+
.nuxt

web/.env.docker

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
API_BASE_URL=http://localhost:8000
2+
3+
APP_URL=http://localhost:3000
4+
APP_NAME=httpSMS
5+
APP_GITHUB_URL=https://github.com/NdoleStudio/httpsms
6+
APP_DOCUMENTATION_URL=https://docs.httpsms.com
7+
APP_DOWNLOAD_URL=https://github.com/NdoleStudio/httpsms/releases/latest/download/HttpSms.apk
8+
APP_ENV=production
9+
10+
# Firebase credentials
11+
FIREBASE_API_KEY=AIzaSyAKqPvj51igvvNNcRt_gL0A6cgx3ZB-kuQ
12+
FIREBASE_AUTH_DOMAIN=httpsms-docker.firebaseapp.com
13+
FIREBASE_PROJECT_ID=httpsms-docker
14+
FIREBASE_STORAGE_BUCKET=httpsms-docker.appspot.com
15+
FIREBASE_MESSAGING_SENDER_ID=668063041624
16+
FIREBASE_APP_ID=668063041624:web:29b9e3b7027965ba08a22d
17+
FIREBASE_MEASUREMENT_ID=G-18VRYL22PZ

web/.env.production

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
BASE_URL=https://api.httpsms.com
1+
API_BASE_URL=https://api.httpsms.com
22

33
APP_URL=https://httpsms.com
4-
APP_NAME="HTTP SMS"
4+
APP_NAME=httpSMS
55
APP_GITHUB_URL=https://github.com/NdoleStudio/httpsms
66
APP_DOCUMENTATION_URL=https://docs.httpsms.com
77
APP_DOWNLOAD_URL=https://github.com/NdoleStudio/httpsms/releases/latest/download/HttpSms.apk
88
APP_ENV=production
99

1010
CHECKOUT_URL=https://httpsms.lemonsqueezy.com/checkout/buy/706c5638-4c8d-40db-a6f2-b6371b7e0af4
1111
ENTERPRISE_CHECKOUT_URL=https://httpsms.lemonsqueezy.com/checkout/buy/d107cf05-4b13-4ebd-a770-c2cc75c69a14
12+
13+
FIREBASE_API_KEY=AIzaSyClL8AX2H_F77_n8yu5FgLzBmJTiSM0NsQ
14+
FIREABSE_AUTH_DOMAIN=httpsms-86c51.firebaseapp.com
15+
FIREBASE_PROJECT_ID=httpsms-86c51
16+
FIREBASE_STORAGE_BUCKET=httpsms-86c51.appspot.com
17+
FIREBASE_MESSAGING_SENDER_ID=877524083399
18+
FIREBASE_APP_ID=1:877524083399:web:430d6a29a0d808946514e2
19+
FIREBASE_MEASUREMENT_ID=G-EZ5W9DVK8T

0 commit comments

Comments
 (0)