-
Notifications
You must be signed in to change notification settings - Fork 3
/
getChat.js
41 lines (37 loc) · 1015 Bytes
/
getChat.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
const AWS = require("aws-sdk");
const ddb = new AWS.DynamoDB.DocumentClient({
apiVersion: "2012-08-10",
region: "eu-west-1",
});
exports.handler = async (event) => {
let connectionData;
const { storeId, conversationId } = JSON.parse(event.body);
try {
const params = {
FilterExpression:
"conversationId = :conversationId AND storeId = :storeId",
ExpressionAttributeValues: {
":storeId": storeId,
":conversationId": conversationId,
},
ExpressionAttributeNames: {
"#d": "date",
"#f": "format",
},
ProjectionExpression:
"conversationId,storeId,#d,#f,message,audioFile,authorId,productId",
TableName: "yownit_chat",
};
connectionData = await ddb.scan(params).promise();
} catch (e) {
console.log(e);
return { statusCode: 500, body: e.stack };
}
return {
statusCode: 200,
body: JSON.stringify(connectionData),
headers: {
"Access-Control-Allow-Origin": "*",
},
};
};