Skip to content

Commit

Permalink
[Refactor] Messagebird -> Twilio
Browse files Browse the repository at this point in the history
Switched SMS backend to Twilio as the response contains "accountSid",
which I will use as user token.
References #61.
  • Loading branch information
angel-penchev committed Feb 8, 2021
1 parent 9909901 commit b528447
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 42 deletions.
4 changes: 3 additions & 1 deletion server/.env.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
POSTGRES_USER=*insert username here*
POSTGRES_PASSWORD=*insert password here*
STRIPE_SECRET_KEY=*insert secret key here*
MESSAGEBIRD_SECRET_KEY=*insert secret key here*
TWILIO_SERVICE_ID=*insert secret key here*
TWILIO_ACCOUNT_SID=*insert secret key here*
TWILIO_AUTH_TOKEN=*insert secret key here*

RABBITMQ_URL=amqp://queue
RABBITMQ_URL_TEST=amqp://localhost
Expand Down
167 changes: 156 additions & 11 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"dotenv": "^8.2.0",
"express": "^4.17.1",
"faker": "^5.3.1",
"messagebird": "^3.5.0",
"moment": "^2.29.1",
"pg": "^8.5.1",
"pgmock2": "^2.0.6",
"stripe": "^8.134.0",
"ts-node": "^9.1.1",
"twilio": "^3.55.1",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions server/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ CREATE TABLE IF NOT EXISTS order_logs (
order_id UUID REFERENCES orders(id),
subject TEXT NOT NULL,
body TEXT NOT NULL
)

CREATE TABLE users(
id INTEGER PRIMARY KEY,
token TEXT NOT NULL,
phone_number TEXT NOT NULL
)
51 changes: 48 additions & 3 deletions server/services/core/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import {QueryConfig, QueryResult, QueryResultRow} from 'pg';
import * as Bluebird from 'bluebird';
import Stripe from 'stripe';
import {AxiosRequestConfig, AxiosResponse} from 'axios';
import {MessageBird} from 'messagebird';
import Twilio from 'twilio';
import {
VerificationInstance,
} from 'twilio/lib/rest/verify/v2/service/verification';
import {
VerificationCheckInstance
} from 'twilio/lib/rest/verify/v2/service/verificationCheck';

/**
* Validator object structure.
Expand Down Expand Up @@ -630,12 +636,51 @@ export interface RequestLibrary {
): Promise<R>;
}

/**
* SMS Client object structure.
*
* @export
* @interface SMSClient
*/
export interface SMSClient {
verify: MessageBird['verify'];
verify: Twilio.Twilio['verify'];
}

/**
* SMS Verification Instance object structure.
*
* @export
* @interface SMSVerificationInstance
* @extends {VerificationInstance}
*/
export interface SMSVerificationInstance extends VerificationInstance {}

/**
* SMS Verification Instance object structure.
*
* @export
* @interface SMSVerificationInstance
* @extends {VerificationInstance}
*/
export interface SMSVerificationCheckInstance
extends VerificationCheckInstance {}

/**
* SMS API object structure.
*
* @export
* @interface SMSApi
*/
export interface SMSApi {
sendToken(
phoneNumber: string,
callback: (id: string) => any,
callback: (verificationInstance: SMSVerificationInstance) => any,
channel: 'sms' | 'call',
): void;

verifyCode(
phoneNumber: string,
code: string,
callback: (phoneNumber: any) => any,
): void;
}
4 changes: 3 additions & 1 deletion server/services/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const config = Object.freeze({
postgresUser: String(process.env.POSTGRES_USER),
postgresPassword: String(process.env.POSTGRES_PASSWORD),
stripeSecretKey: String(process.env.STRIPE_SECRET_KEY),
messagebirdSecretKey: String(process.env.MESSAGEBIRD_SECRET_KEY),
twilioServiceId: String(process.env.TWILIO_SERVICE_ID),
twilioAccountSid: String(process.env.TWILIO_ACCOUNT_SID),
twilioAuthToken: String(process.env.TWILIO_AUTH_TOKEN),

rabbitMqUrl: String(process.env.RABBITMQ_URL),
rabbitMqUrlTest: String(process.env.RABBITMQ_URL_TEST),
Expand Down
Loading

0 comments on commit b528447

Please sign in to comment.