-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardGenerator.js
53 lines (51 loc) · 1.36 KB
/
cardGenerator.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
let lengthValidator = require("./validators/lengthValidator");
//card block
let cardGenerator = (imgUrl, title, subtitle, defaultLink, BtnObjArr) => {
if (BtnObjArr.length > 3) {
console.warn(
`⚠ Warning: Max btn(3) amount crossed! only 3 buttons were kept and rest were removed`
);
return {
attachment: {
type: "template",
payload: {
template_type: "generic",
elements: [
{
title: lengthValidator(title, 80),
image_url: `${imgUrl}`,
subtitle: lengthValidator(subtitle, 80),
default_action: {
type: "web_url",
url: `${defaultLink}`,
},
buttons: [BtnObjArr[0], BtnObjArr[1], BtnObjArr[2]],
},
],
},
},
};
} else {
return {
attachment: {
type: "template",
payload: {
template_type: "generic",
elements: [
{
title: lengthValidator(title, 80),
image_url: `${imgUrl}`,
subtitle: lengthValidator(subtitle, 80),
default_action: {
type: "web_url",
url: `${defaultLink}`,
},
buttons: BtnObjArr,
},
],
},
},
};
}
};
module.exports = cardGenerator;