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()
|
@IsNotEmpty()
|
||||||
public readonly OVH_CONSUMER_KEY!: string;
|
public readonly OVH_CONSUMER_KEY!: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
public readonly OVH_SMS_SERVICE_NAME!: string;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public readonly SMS_FACTOR_TOKEN!: string;
|
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_KEY = process.env["OVH_APP_KEY"]!;
|
||||||
this.OVH_APP_SECRET = process.env["OVH_APP_SECRET"]!;
|
this.OVH_APP_SECRET = process.env["OVH_APP_SECRET"]!;
|
||||||
this.OVH_CONSUMER_KEY = process.env["OVH_CONSUMER_KEY"]!;
|
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"]!;
|
this.SMS_FACTOR_TOKEN = process.env["SMS_FACTOR_TOKEN"]!;
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,29 +15,21 @@ export default class OvhService extends BaseService {
|
|||||||
consumerKey: this.variables.OVH_CONSUMER_KEY,
|
consumerKey: this.variables.OVH_CONSUMER_KEY,
|
||||||
});
|
});
|
||||||
|
|
||||||
ovh.request("GET", "/sms", function (err: any, serviceName: string) {
|
const serviceName = this.variables.OVH_SMS_SERVICE_NAME;
|
||||||
if (err) {
|
|
||||||
console.log(err, serviceName);
|
|
||||||
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/', {
|
||||||
ovh.request(
|
message: message,
|
||||||
"POST",
|
sender: "LeCoffre",
|
||||||
"/sms/" + serviceName + "/jobs",
|
receivers: [phoneNumber],
|
||||||
{
|
}, (error: any, response: any) => {
|
||||||
message: message,
|
if (error) {
|
||||||
senderForResponse: true,
|
console.error('Error sending Ovh Sms:', error);
|
||||||
receivers: [phoneNumber],
|
return false;
|
||||||
},
|
} else {
|
||||||
function (errsend: any, result: any) {
|
console.log('SMS sent successfully via Ovh:', response);
|
||||||
console.log(errsend, result);
|
return true;
|
||||||
},
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@ export default class SmsFactorService extends BaseService {
|
|||||||
to: phoneNumber,
|
to: phoneNumber,
|
||||||
text: message,
|
text: message,
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
console.log('SMS sent successfully:', response.data);
|
console.log('SMS sent successfully via Sms Factor :', response.data);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error sending SMS:', error.response.data);
|
console.error('Error sending Sms Factor SMS:', error.response.data);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user