Ovh
This commit is contained in:
parent
f00eda1714
commit
bb8b49edbe
@ -63,6 +63,7 @@
|
||||
"next": "^13.1.5",
|
||||
"node-cache": "^5.1.2",
|
||||
"node-schedule": "^2.1.1",
|
||||
"ovh": "^2.0.3",
|
||||
"prisma-query": "^2.0.0",
|
||||
"puppeteer": "^21.3.4",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
|
@ -112,6 +112,15 @@ export class BackendVariables {
|
||||
@IsNotEmpty()
|
||||
public readonly SMS_PROVIDER!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly OVH_APP_KEY!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly OVH_APP_SECRET!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly OVH_CONSUMER_KEY!: string;
|
||||
|
||||
public constructor() {
|
||||
dotenv.config();
|
||||
this.DATABASE_PORT = process.env["DATABASE_PORT"]!;
|
||||
@ -150,6 +159,10 @@ export class BackendVariables {
|
||||
this.DOCAPOST_APP_ID = process.env["DOCAPOST_APP_ID"]!;
|
||||
this.DOCAPOST_APP_PASSWORD = process.env["DOCAPOST_APP_PASSWORD"]!;
|
||||
this.SMS_PROVIDER = process.env["SMS_PROVIDER"]!;
|
||||
this.OVH_APP_KEY = process.env["OVH_APP_KEY"]!;
|
||||
this.OVH_APP_SECRET = process.env["OVH_APP_SECRET"]!;
|
||||
this.OVH_CONSUMER_KEY = process.env["OVH_CONSUMER_KEY"]!;
|
||||
|
||||
|
||||
}
|
||||
public async validate(groups?: string[]) {
|
||||
|
43
src/services/common/OvhService/OvhService.ts
Normal file
43
src/services/common/OvhService/OvhService.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
|
||||
Service()
|
||||
export default class OvhService extends BaseService {
|
||||
|
||||
constructor(private variables: BackendVariables) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all Customers
|
||||
* @throws {Error} If Customers cannot be get
|
||||
*/
|
||||
public async sendSms(phoneNumber: string, message: string): Promise<void> {
|
||||
|
||||
const ovh = require('ovh')({
|
||||
appKey: this.variables.OVH_APP_KEY,
|
||||
appSecret: this.variables.OVH_APP_SECRET,
|
||||
consumerKey: this.variables.OVH_CONSUMER_KEY,
|
||||
});
|
||||
|
||||
// Get the serviceName (name of your SMS account)
|
||||
ovh.request('GET', '/sms', function (err: any, serviceName: string) {
|
||||
if(err) {
|
||||
console.log(err, serviceName);
|
||||
}
|
||||
else {
|
||||
console.log("My account SMS is " + serviceName);
|
||||
|
||||
// Send a simple SMS with a short number using your serviceName
|
||||
ovh.request('POST', '/sms/' + serviceName + '/jobs', {
|
||||
message: message,
|
||||
senderForResponse: true,
|
||||
receivers: [phoneNumber]
|
||||
}, function (errsend: any, result: any) {
|
||||
console.log(errsend, result);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import AuthService from "@Services/common/AuthService/AuthService";
|
||||
import TotpCodes, { TotpCodesReasons } from "le-coffre-resources/dist/Customer/TotpCodes";
|
||||
import { Customer } from "le-coffre-resources/dist/Notary";
|
||||
import { Service } from "typedi";
|
||||
import OvhService from "@Services/common/OvhService/OvhService";
|
||||
|
||||
export class SmsNotExpiredError extends Error {
|
||||
constructor() {
|
||||
@ -50,6 +51,7 @@ export default class CustomersService extends BaseService {
|
||||
private authService: AuthService,
|
||||
private totpCodesRepository: TotpCodesRepository,
|
||||
private variables: BackendVariables,
|
||||
private ovhService: OvhService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@ -247,16 +249,16 @@ export default class CustomersService extends BaseService {
|
||||
private async sendSmsCodeToCustomer(totpPin: number, customer: Customer) {
|
||||
try {
|
||||
// Sélectionnez le fournisseur de SMS en fonction de la variable d'environnement
|
||||
const selectedProvider = this.variables.SMS_PROVIDER === 'OVH' ? this.smsService1 : this.smsService2;
|
||||
const selectedProvider = this.variables.SMS_PROVIDER === 'OVH' ? this.ovhService : null;
|
||||
|
||||
// Envoi du SMS
|
||||
let success = await selectedProvider.sendSms(customer.contact?.phone_number, totpPin);
|
||||
|
||||
// Si l'envoi échoue, basculez automatiquement sur le second fournisseur
|
||||
if (!success) {
|
||||
const alternateProvider = this.variables.SMS_PROVIDER === 'OVH' ? this.smsService2 : this.smsService1;
|
||||
success = await alternateProvider.sendSms(customer.contact?.phone_number, totpPin);
|
||||
}
|
||||
// if (!success) {
|
||||
// const alternateProvider = this.variables.SMS_PROVIDER === 'OVH' ? this.smsService2 : this.ovhService;
|
||||
// success = await alternateProvider.sendSms(customer.contact?.phone_number, totpPin);
|
||||
// }
|
||||
|
||||
return success;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user