-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarizer.js
64 lines (60 loc) · 1.72 KB
/
summarizer.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
const AWS = require('aws-sdk'),
s3 = new AWS.S3(),
sagemakerruntime = new AWS.SageMakerRuntime(),
ses = new AWS.SES({ region: 'us-east-1' }),
path = require('path'),
ENDPOINT_NAME = process.env.ENDPOINT_NAME;
exports.handler = (event, context, callback) => {
const eventRecord = event.Records && event.Records[0],
inputBucket = eventRecord.s3.bucket.name,
key = eventRecord.s3.object.key,
id = context.awsRequestId,
emailId = "[email protected]";
s3.getObject({
Bucket: inputBucket,
Key: key
}, function(err, data) {
if (err) {
console.log(err, err.stack);
callback(err);
} else {
const record = JSON.parse(data.Body);
const transcribedText = record.results.transcripts[0].transcript;
var params = {
Body: transcribedText,
ContentType: 'application/json',
EndpointName: ENDPOINT_NAME
};
sagemakerruntime.invokeEndpoint(params, function(err, data) {
if (err) console.log(err, err.stack);
else sendEmail(emailId, data);
});
}
});
};
function sendEmail(emailId, data, callback) {
var params = {
Destination: {
ToAddresses: [emailId]
},
Message: {
Body: {
Text: {
Data: data
}
},
Subject: {
Data: "Chime Meeting Summary"
}
},
Source: "[email protected]"
};
ses.sendEmail(params, function(err, data) {
if (err) {
console.log(err);
}
else {
console.log(data);
}
});
}