-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforward-msg-to-user.js
36 lines (29 loc) · 1.01 KB
/
forward-msg-to-user.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
exports.handler = function(context, event, callback) {
// console.log('test');
var striptags = require('striptags');
console.log('event only', event);
console.log('event.data', event.data);
var userId = event.data.item.user.user_id;
var convoParts = event.data.item.conversation_parts.conversation_parts;
var body = event.data.item.conversation_parts.conversation_parts[convoParts.length-1].body.replace(/<br>/, '\n');
var parsedBody = striptags(body);
console.log(userId);
console.log(parsedBody);
var client = context.getTwilioClient();
if(parsedBody){
console.log('sending sms', new Date());
client.messages.create({
from: '+61427860314',
to: userId,
body: parsedBody
}).then((message) => {
console.log('here', new Date());
console.log(message.sid);
callback(null);
}).catch((error) => {
callback(error);
});
} else {
callback(null);
}
};