-
Notifications
You must be signed in to change notification settings - Fork 0
/
slackresponses.js
181 lines (180 loc) Β· 6.13 KB
/
slackresponses.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const Boxed = require("./boxed/boxed");
const getSnackRequestFields = (snackRequest, except) => {
let fields = [
{
title: "Name",
value: snackRequest.snack.name,
short: true,
},
{
title: "Description",
value: snackRequest.snack.description,
short: true,
},
{
title: "Brand",
value: snackRequest.snack.brand,
short: true,
},
{
title: "URL",
value: Boxed.getUrlForProductId(snackRequest.snack.boxedId),
short: true,
},
{
title: "First Requested By",
value: snackRequest.initialRequester.name,
short: true,
},
{
title: "Number of Requests",
value: 1 + snackRequest.additionalRequesters.length,
short: true,
},
];
//Remove undefined fields
fields = fields.filter(field => field.value);
return except ? fields.filter(field => !except.includes(field.title)) : fields;
};
module.exports = {
addedRequester: request => {
return {
attachments: [
{
// prettier-ignore
pretext: `${request.snack.name} was already added to the request list π
I'll just make a note that you want that too β
`,
image_url: request.snack.imageUrl,
fields: getSnackRequestFields(request),
},
],
response_type: "ephemeral",
replace_original: true,
delete_original: true,
};
},
alreadyRequested: request => {
return {
attachments: [
{
// prettier-ignore
pretext: `π You've already requested ${request.snack.name} π`,
image_url: request.snack.imageUrl,
fields: getSnackRequestFields(request),
},
],
response_type: "ephemeral",
replace_original: true,
delete_original: true,
};
},
createdRequest: request => {
return {
attachments: [
{
// prettier-ignore
pretext: `π A request has been created for ${request.snack.name}! π`,
image_url: request.snack.imageUrl,
fields: getSnackRequestFields(request, "Number of Requests"),
},
],
response_type: "ephemeral",
replace_original: true,
delete_original: true,
};
},
boxedSearchResult: (name, imageUrl, buttonValue) => {
return [
{
type: "section",
text: {
type: "mrkdwn",
text: `*${name}*`,
},
},
{
type: "image",
title: {
type: "plain_text",
text: "Product Image",
emoji: true,
},
image_url: `https://d2ln0cvn4pv5w2.cloudfront.net/unsafe/fit-in/256x256/filters:quality(100):max_bytes(200000):fill(white)/${imageUrl}`,
alt_text: "Product Image",
},
{
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
emoji: true,
text: "Request This β
",
},
value: buttonValue,
action_id: "createNewRequest",
},
],
},
];
},
similarRequest: (existingRequest, newSnack, buttonValue) => {
return {
text: "π€ It looks like a similar request was made earlier...",
attachments: [
{
pretext: "Here's a comparision",
image_url: existingRequest.snack.imageUrl,
thumb_url: newSnack.imageUrl,
fields: [
{
title: "Your snack's name",
value: newSnack.name,
short: true,
},
{
title: "Already requested snack's name",
value: existingRequest.snack.name,
short: true,
},
{
title: "Your snack's description",
value: newSnack.description,
short: true,
},
{
title: "Already requested snack's description",
value: existingRequest.snack.description,
short: true,
},
],
},
{
pretext: "Do you want to add a vote for the existing item?",
fallback: "Looks like your workspace hasn't enabled buttons...",
callback_id: "resolve_similar_request",
color: "#3AA3E3",
attachment_type: "default",
actions: [
{
name: "addToExistingRequest",
text: "β
Sure",
type: "button",
value: buttonValue,
},
{
name: "createNewRequest",
text: "π
No, make a new request",
type: "button",
value: buttonValue,
},
],
},
],
response_type: "ephemeral",
replace_original: true,
delete_original: true,
};
},
};