-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda-send-transcript.js
More file actions
71 lines (53 loc) · 1.68 KB
/
lambda-send-transcript.js
File metadata and controls
71 lines (53 loc) · 1.68 KB
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
const aws = require("aws-sdk");
const s3 = new aws.S3({ apiVersion: '2006-03-01' });
var ses = new aws.SES();
const sesConfirmedAddress = "ainley.pena@scalar.ca";
exports.handler = (event, context, callback) => {
const bucket = event.Records[0].s3.bucket.name;
const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
const params = {
Bucket: bucket,
Key: key,
};
s3.getObject(params, function (err, data) {
if (err) {
console.log(err);
} else {
console.log(data.Body.toString()); //this will log data to console
}
//var fileData = JSON.parse(data.Body.toString());
var results = JSON.parse(data.Body.toString());
var transcript = results.results.transcripts[0].transcript;
console.log(transcript);
sendEmail(transcript);
});
};
function sendEmail(transcript) {
var emailRequestParams = {
Destination: {
ToAddresses: [sesConfirmedAddress]
},
Message: {
Body: {
Text: {
Data: "Hello! Here is transcription. \n\n\n" + transcript
}
},
Subject: {
Data: "Transcription from Call Center"
}
},
Source: sesConfirmedAddress,
ReplyToAddresses: [sesConfirmedAddress]
};
var sendEmailPromise = ses.sendEmail(emailRequestParams).promise();
var response = {
statusCode: 200
};
sendEmailPromise.then(function (result) {
console.log(result);
}).catch(function (err) {
console.log(err);
response.statusCode = 500;
});
}