add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import axios from 'axios';
import SMSClientInterface from '@/services/SMSClient/SMSClientInterfaces';
import config from '@/config';
export default class EasySMSClient implements SMSClientInterface {
token: string;
clientName: string = 'easysms';
/**
*
* @param {string} token
*/
constructor(token: string) {
this.token = token;
}
/**
* Normalizes the phone number string.
* @param {string} phoneNumber
* @returns {string}
*/
normlizePhoneNumber = (phoneNumber: string) => {
let normalized = phoneNumber;
normalized = normalized.replace(/^00/, '');
normalized = normalized.replace(/^0/, '');
normalized = normalized.replace(/^218/, '');
return normalized;
};
/**
* Send message to given phone number via easy SMS client.
* @param {string} to
* @param {string} message
*/
send = (to: string, message: string) => {
const API_KEY = this.token;
const parsedTo = this.normlizePhoneNumber(to);
const encodedMessage = encodeURIComponent(message);
const encodeTo = encodeURIComponent(parsedTo);
const params = `action=send-sms&api_key=${API_KEY}&to=${encodeTo}&sms=${encodedMessage}&unicode=1`;
return new Promise((resolve, reject) => {
axios
.get(`https://easysms.devs.ly/sms/api?${params}`)
.then((response) => {
if (response.data.code === 'ok') {
resolve(response);
} else {
reject(response.data);
}
})
.catch((error) => {
reject(error);
});
});
};
}

View File

@@ -0,0 +1,39 @@
import { Container } from 'typedi';
import SMSClientInterface from '@/services/SMSClient/SMSClientInterface';
import { thomsonCrossSectionDependencies } from 'mathjs';
export default class SMSAPI {
smsClient: SMSClientInterface;
constructor(smsClient: SMSClientInterface) {
this.smsClient = smsClient;
}
/**
* Sends the message to the target via the client.
* @param {string} to
* @param {string} message
* @param {array} extraParams
* @param {array} extraHeaders
*/
sendMessage(
to: string,
message: string,
extraParams?: [],
extraHeaders?: []
) {
return this.smsClient.send(to, message);
}
/**
*
* @param to
* @param message
* @returns
*/
sendMessageJob(to: string, message: string) {
const agenda = Container.get('agenda');
return agenda.now('sms-notification', { to, message });
}
}

View File

@@ -0,0 +1,5 @@
export default interface SMSClientInterface {
clientName: string;
send(to: string, message: string): boolean;
}

View File

@@ -0,0 +1,3 @@
import SMSAPI from './SMSAPI';
export default SMSAPI;