-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
103 lines (89 loc) · 2.55 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
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
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 function will get the name of the person calling.
//
exports.handler = (event) => {
return new Promise(function(resolve, reject) {
//
// 1. Get the Phone number that called us.
//
let phone_nr = event.Details.ContactData.CustomerEndpoint.Address;
//
// 2. Prepare the query.
//
let params = {
TableName: "0x4447_connect_sessions",
Key: {
id: phone_nr,
type: 'basic'
}
};
//
// 3. Execute the query.
//
ddb.get(params, function(error, data) {
//
// 1. Check if there were any errors.
//
if(error)
{
console.info(params);
return reject(error);
}
//
// 2. This variable will be holding the user name if we get
// one.
//
let name = null;
//
// 3. Check if there was an order by converting the object in to
// an array and checking its length.
//
if(data.Item)
{
if(data.Item.name)
{
//
// 1. Save the name.
//
name = data.Item.name;
}
}
//
// 4. We create a variable that will tell Connect flow if we got a
// name or not and by default we assume that we did not found a
// a name.
//
let did_we_get_a_name = false;
//
// 5. Check if we got a name from the DB, and set the variable from
// above to true.
//
if(name)
{
did_we_get_a_name = true;
}
//
// 6. Prepare the object that needs to be returned to Connect
// so the flow knows what to do.
//
let result = {
first_name: name,
got_name: did_we_get_a_name,
Phone_Nr: phone_nr,
Caller_Type:'Client'
};
//
// -> Tell Lambda that we are done working.
//
return resolve(result);
});
});
};