-
Notifications
You must be signed in to change notification settings - Fork 0
/
email-sms.js
115 lines (95 loc) · 2.41 KB
/
email-sms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const client = require('twilio')(sails.config.twilioAccountSid, sails.config.twilioAuthToken);
module.exports = {
friendlyName: 'Send sms',
description: '',
inputs: {
phoneNumber: {
description: 'The confirmation token from the phone.',
example: '+380661338622',
},
phoneProofToken: {
description: 'The confirmation token from the phone.',
example: '123456',
},
},
exits: {
success: {
description: 'Phone register success',
},
},
fn: async function(inputs, exits) {
client.messages
.create({
to: inputs.phoneNumber,
from: sails.config.twilioNumberFrom,
body: `Your code for LandMoney is ${inputs.phoneProofToken}`,
})
.then(message => console.log(message.sid));
return exits.success();
},
};
module.exports = class SmsService {
constructor(messagebird_access_key) {
this.messagebird = require('messagebird')(messagebird_access_key);
}
sendSms(phonenumber, message) {
let thisContext = this;
return new Promise(function(resolve, reject) {
var params = {
originator: 'Relate',
recipients: [phonenumber],
body: message,
};
thisContext.messagebird.messages.create(params, function(err, response) {
if (err) {
console.log(err);
reject(err);
}
console.log(response);
resolve(response);
});
});
}
validatePhonenumber(phonenumber) {
let thisContext = this;
return new Promise(function(resolve, reject) {
console.log('phonenumberphonenumber: ' + phonenumber);
thisContext.messagebird.lookup.read(phonenumber, function(err, response) {
if (err) {
console.log(err);
console.log(response);
reject(err);
}
console.log(response);
resolve(response);
});
});
}
};
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(sails.config.sendgridApiKey);
module.exports = {
inputs: {
to: {
type: 'string',
required: true,
},
subject: {
type: 'string',
},
html: {
type: 'string',
},
},
exits: {},
fn: async function(inputs, exits) {
const msg = {
to: inputs.to,
from: '[email protected]',
subject: inputs.subject || 'Sample subject',
html: inputs.html || '<h1>sample html</h1>',
};
sgMail.send(msg);
exits.success();
},
};