36 lines
960 B
TypeScript
36 lines
960 B
TypeScript
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();
|
|
}
|
|
|
|
public async sendSms(phoneNumber: string, message: string): Promise<boolean> {
|
|
const ovh = require("ovh")({
|
|
appKey: this.variables.OVH_APP_KEY,
|
|
appSecret: this.variables.OVH_APP_SECRET,
|
|
consumerKey: this.variables.OVH_CONSUMER_KEY,
|
|
});
|
|
|
|
const serviceName = this.variables.OVH_SMS_SERVICE_NAME;
|
|
|
|
await ovh.request('POST', '/sms/' + serviceName + '/jobs/', {
|
|
message: message,
|
|
receivers: [phoneNumber],
|
|
senderForResponse: true,
|
|
// sender: "LEcoffre.io",
|
|
}, (error: any, response: any) => {
|
|
if (error) {
|
|
console.error('Error sending Ovh Sms');
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
});
|
|
return true;
|
|
}
|
|
}
|