-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
76 lines (64 loc) · 2.06 KB
/
utils.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
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');
const client = new textToSpeech.TextToSpeechClient({
credentials: JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS)
});
const language = require('@google-cloud/language');
const Filter = require('bad-words');
const sgMail = require('@sendgrid/mail');
hasProfanity = (text) => {
const filter = new Filter();
return filter.isProfane(text);
}
getTTS = async (text) => {
const request = {
input: {text: text},
voice: {languageCode: 'en-US', ssmlGender: 'MALE', name:'en-US-Wavenet-D'},
audioConfig: {audioEncoding: 'MP3'},
};
const [response] = await client.synthesizeSpeech(request);
return response.audioContent;
}
checkSentiment = async (text) => {
const languageClient = new language.LanguageServiceClient({
credentials: JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS)
});
const document = {
content: text,
type: 'PLAIN_TEXT',
};
const [result] = await languageClient.analyzeSentiment({document: document});
const sentiment = result.documentSentiment;
console.log(text);
console.log(sentiment);
return sentiment;
}
sendEmails = (participants) => {
console.log(participants);
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
console.log("key: ", process.env.SENDGRID_API_KEY);
participants.forEach(x => {
const msg = {
to: x.email,
from: 'uGraduated@gmail.com',
templateId: 'd-c6861d28111a4fb892652fa95532eee3',
dynamic_template_data: {
subject: `Congratuations ${x.name}! uGraduated!`,
name: x.name,
},
};
sgMail.send(msg).then(() => {
console.log('Message sent')
}).catch((error) => {
console.log(JSON.stringify(error))
})
})
return true;
}
module.exports = {
getTTS: getTTS,
checkSentiment: checkSentiment,
hasProfanity: hasProfanity,
sendEmails: sendEmails,
}