dt-common-device 13.3.8 → 13.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Integrations/twilio/index.d.ts +1 -0
- package/dist/Integrations/twilio/index.js +1 -0
- package/dist/Integrations/twilio/interface/twilloInterface.d.ts +1 -4
- package/dist/Integrations/twilio/twilio.service.d.ts +1 -0
- package/dist/Integrations/twilio/twilio.service.js +20 -5
- package/package.json +1 -1
|
@@ -79,6 +79,7 @@ const typedi_1 = __importStar(require("typedi"));
|
|
|
79
79
|
const Connection_repository_1 = require("../../entities/connection/Connection.repository");
|
|
80
80
|
const IConnection_1 = require("../../entities/connection/IConnection");
|
|
81
81
|
const twilio_1 = __importDefault(require("twilio"));
|
|
82
|
+
const Property_repository_1 = require("../../entities/property/Property.repository");
|
|
82
83
|
let TwilioService = (() => {
|
|
83
84
|
let _classDecorators = [(0, typedi_1.Service)()];
|
|
84
85
|
let _classDescriptor;
|
|
@@ -87,12 +88,13 @@ let TwilioService = (() => {
|
|
|
87
88
|
var TwilioService = _classThis = class {
|
|
88
89
|
constructor() {
|
|
89
90
|
this.connectionRepository = typedi_1.default.get(Connection_repository_1.ConnectionRepository);
|
|
91
|
+
this.propertyRepository = typedi_1.default.get(Property_repository_1.PropertyRepository);
|
|
90
92
|
}
|
|
91
93
|
// -----------------------------
|
|
92
94
|
// Send SMS
|
|
93
95
|
// -----------------------------
|
|
94
96
|
async sendSMS(data) {
|
|
95
|
-
const { propertyId,
|
|
97
|
+
const { propertyId, message } = data;
|
|
96
98
|
//find fromNumber from the dt_connections table based on the propertyId
|
|
97
99
|
const response = await this.connectionRepository.queryConnections({ propertyId, connectionProvider: IConnection_1.ConnectionProvider.Twilio });
|
|
98
100
|
//need connectionId, clientSecret, metaData
|
|
@@ -101,15 +103,28 @@ let TwilioService = (() => {
|
|
|
101
103
|
if (!fromNumber) {
|
|
102
104
|
throw new Error("From number not found");
|
|
103
105
|
}
|
|
106
|
+
//find toNumber and sms_enabled from the property settings table based on the propertyId
|
|
107
|
+
const _settingsRes = await this.propertyRepository.getPropertyPreferences(propertyId);
|
|
108
|
+
if (!_settingsRes) {
|
|
109
|
+
throw new Error("Property settings not found");
|
|
110
|
+
}
|
|
111
|
+
const smsEnabled = _settingsRes?.settings?.notificationPreferences?.smsNotification?.enabled;
|
|
112
|
+
const toNumber = _settingsRes?.settings?.notificationPreferences?.smsNotification?.toNumber;
|
|
113
|
+
if (!toNumber) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!smsEnabled) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
104
119
|
//TODO: Need to do singletone pattern for the client
|
|
105
120
|
const client = (0, twilio_1.default)(id, clientSecret);
|
|
106
121
|
try {
|
|
107
|
-
const
|
|
108
|
-
body:
|
|
122
|
+
const smsResponse = await client.messages.create({
|
|
123
|
+
body: message,
|
|
109
124
|
from: fromNumber,
|
|
110
|
-
to:
|
|
125
|
+
to: toNumber,
|
|
111
126
|
});
|
|
112
|
-
return
|
|
127
|
+
return smsResponse;
|
|
113
128
|
}
|
|
114
129
|
catch (error) {
|
|
115
130
|
throw new Error(`Error sending SMS: ${error}`);
|