Added ovh sms service name variable and cleaned code
This commit is contained in:
parent
56fe8a43b4
commit
869a30fac0
@ -121,6 +121,9 @@ export class BackendVariables {
|
||||
@IsNotEmpty()
|
||||
public readonly OVH_CONSUMER_KEY!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly OVH_SMS_SERVICE_NAME!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly SMS_FACTOR_TOKEN!: string;
|
||||
|
||||
@ -165,6 +168,7 @@ export class BackendVariables {
|
||||
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"]!;
|
||||
this.OVH_SMS_SERVICE_NAME = process.env["OVH_SMS_SERVICE_NAME"]!;
|
||||
this.SMS_FACTOR_TOKEN = process.env["SMS_FACTOR_TOKEN"]!;
|
||||
|
||||
|
||||
|
@ -15,26 +15,18 @@ export default class OvhService extends BaseService {
|
||||
consumerKey: this.variables.OVH_CONSUMER_KEY,
|
||||
});
|
||||
|
||||
ovh.request("GET", "/sms", function (err: any, serviceName: string) {
|
||||
if (err) {
|
||||
console.log(err, serviceName);
|
||||
const serviceName = this.variables.OVH_SMS_SERVICE_NAME;
|
||||
|
||||
ovh.request('POST', '/sms/' + serviceName + '/jobs/', {
|
||||
message: message,
|
||||
sender: "LeCoffre",
|
||||
receivers: [phoneNumber],
|
||||
}, (error: any, response: any) => {
|
||||
if (error) {
|
||||
console.error('Error sending Ovh Sms:', error);
|
||||
return false;
|
||||
} 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);
|
||||
},
|
||||
);
|
||||
console.log('SMS sent successfully via Ovh:', response);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -17,12 +17,12 @@ export default class SmsFactorService extends BaseService {
|
||||
to: phoneNumber,
|
||||
text: message,
|
||||
}).then(response => {
|
||||
console.log('SMS sent successfully:', response.data);
|
||||
console.log('SMS sent successfully via Sms Factor :', response.data);
|
||||
return true;
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error sending SMS:', error.response.data);
|
||||
console.error('Error sending Sms Factor SMS:', error.response.data);
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user