-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
47 lines (41 loc) · 1.3 KB
/
Copy pathutils.js
File metadata and controls
47 lines (41 loc) · 1.3 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
const unirest = require('unirest');
function setupTextContent(jokeObject){
if(jokeObject == null) throw new Error('Null or no object passed into setupTextContent function.');
let textContent =`Hey, it's Dad-Bot.\n
Wanna hear a joke? :D\n\n
${jokeObject.setup}\n\n
${jokeObject.punchline}
`
return textContent;
}
function setupTextDetail(textContent){
if(textContent == null) throw new Error('Null or no object passed into setupTextDetail function.');
let textObject = {
body: textContent,
from: process.env.TWILIO_PHONE_NUMBER,
to: process.env.PHONE_NUMBER
}
return textObject;
}
async function getDadJokeAsync(callback){
unirest("GET", "https://dad-jokes.p.rapidapi.com/random/joke")
.headers({
"x-rapidapi-key": process.env.RAPID_API_KEY,
"x-rapidapi-host": "dad-jokes.p.rapidapi.com",
"useQueryString": true
})
.end(function (res){
if (res.error){
console.error(`Error getting joke: ${res.error}`);
callback(res.error, null);
} else {
console.log("Fetching joke successful");
callback(null, res.body.body[0]);
}
});
}
module.exports = {
setupTextContent: setupTextContent,
setupTextDetail: setupTextDetail,
getDadJokeAsync: getDadJokeAsync
}