-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
59 lines (49 loc) · 1.31 KB
/
index.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
let AWS = require('aws-sdk');
//
// Create the DynamoDB object
//
let ddb = new AWS.DynamoDB.DocumentClient({
apiVersion: '2012-08-10',
region: process.env.AWS_REGION
});
//
// This lambda saves the name that the user over the phone said.
//
exports.handler = (event) => {
return new Promise(function(resolve, reject) {
//
// 1. Simplify the variable that we need.
//
let name = event.Details.ContactData.Attributes.first_name
let phone_nr = event.Details.ContactData.CustomerEndpoint.Address
//
// 2. Prepare the query
//
let params = {
TableName: "0x4447_connect_sessions",
Item: {
id: phone_nr,
type: 'basic',
name: name,
timestamp_created: Math.floor(Date.now() / 1000)
},
};
//
// 3. Execute the query
//
ddb.put(params, function(error, data) {
//
// 1. Check if there were any errors
//
if(error)
{
console.info(params);
return reject(error);
}
//
// -> Tell Lambda that we are done working.
//
return resolve({});
});
});
};