Skip to content

Commit 01787cf

Browse files
authored
Merge pull request #20 from rpiambulance/dev
Fix #18
2 parents 8af30c4 + b8aadde commit 01787cf

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

handlers/buttons.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const approveMessage = (
1919
adminMessageTs,
2020
approver
2121
) => {
22-
postToChannel(channel_id, text, user_id);
22+
postToChannel(channel_id, text, user_id, true);
2323
updateModMessage(
2424
"approved",
2525
channel_id,
@@ -30,6 +30,18 @@ const approveMessage = (
3030
);
3131
};
3232

33+
const approveNoAt = (channel_id, text, user_id, adminMessageTs, approver) => {
34+
postToChannel(channel_id, text, user_id, false);
35+
updateModMessage(
36+
"approved without at-channel",
37+
channel_id,
38+
text,
39+
user_id,
40+
adminMessageTs,
41+
approver
42+
);
43+
};
44+
3345
const rejectMessage = (channel_id, text, user_id, adminMessageTs, rejector) => {
3446
updateModMessage(
3547
"rejected",
@@ -52,4 +64,4 @@ const cancelRequest = (channel_id, user_id, ts) => {
5264
});
5365
};
5466

55-
module.exports = { approveMessage, rejectMessage, cancelRequest };
67+
module.exports = { approveMessage, approveNoAt, rejectMessage, cancelRequest };

handlers/message.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ const sendForApproval = async (text, channel_id, user_id, hash) => {
5656
style: "primary",
5757
action_id: `APP_${hash}`
5858
},
59+
{
60+
type: "button",
61+
text: {
62+
type: "plain_text",
63+
text: "Approve without @channel"
64+
},
65+
action_id: `NOAT_${hash}`
66+
},
5967
{
6068
type: "button",
6169
text: {
@@ -72,7 +80,8 @@ const sendForApproval = async (text, channel_id, user_id, hash) => {
7280
return ts;
7381
};
7482

75-
const postToChannel = (channel_id, text, user_id) => {
83+
const postToChannel = (channel_id, text, user_id, atChannel) => {
84+
const atChannelText = atChannel ? "<!channel>" : "the channel";
7685
postMessage({
7786
token: TOKEN,
7887
channel: channel_id,
@@ -82,7 +91,7 @@ const postToChannel = (channel_id, text, user_id) => {
8291
type: "section",
8392
text: {
8493
type: "mrkdwn",
85-
text: `<@${user_id}> has sent the following message to <!channel>:\n\n${text}`
94+
text: `<@${user_id}> has sent the following message to ${atChannelText}:\n\n${text}`
8695
}
8796
}
8897
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "at-channel",
3-
"version": "0.9.0",
3+
"version": "1.1.0",
44
"description": "Allows the approval of @channel requests in a slack workspace",
55
"main": "server.js",
66
"scripts": {

server.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { isModerator } = require("./utilities/helperFunctions.js");
77
const { slashChannel } = require("./handlers/slashCommands.js");
88
const {
99
approveMessage,
10+
approveNoAt,
1011
rejectMessage,
1112
cancelRequest
1213
} = require("./handlers/buttons.js");
@@ -21,7 +22,8 @@ app.command(
2122
);
2223

2324
app.action(
24-
/^(APP|REJ)_.*/,
25+
//APP = approved; NOAT = approved without @channel; REJ = reject
26+
/^(APP|NOAT|REJ)_.*/,
2527
async ({ ack, next }) => {
2628
ack();
2729
next();
@@ -45,6 +47,8 @@ app.action(
4547
.replace(">", "");
4648
if (/^APP_.*/.test(action_id)) {
4749
approveMessage(channel_id, text, user_id, ts, id);
50+
} else if (/^NOAT_.*/.test(action_id)) {
51+
approveNoAt(channel_id, text, user_id, ts, id);
4852
} else if (/^REJ_.*/.test(action_id)) {
4953
rejectMessage(channel_id, text, user_id, ts, id);
5054
}

utilities/helperFunctions.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ const updateModMessage = (status, channel_id, text, user_id, ts, moderator) => {
7878
});
7979
return;
8080
}
81-
82-
const emoji = status == "approved" ? ":heavy_check_mark:" : ":x:";
81+
82+
const emoji =
83+
status == "approved"
84+
? ":heavy_check_mark:"
85+
: status == "approved without at-channel"
86+
? ":heavy_minus_sign:"
87+
: ":x:";
8388
update({
8489
token: TOKEN,
8590
channel: MOD_CHANNEL_ID,
@@ -107,9 +112,9 @@ const updateModMessage = (status, channel_id, text, user_id, ts, moderator) => {
107112
});
108113
};
109114

110-
const randomEmoji = (sentiment) => {
115+
const randomEmoji = sentiment => {
111116
let emojis = [];
112-
switch(sentiment){
117+
switch (sentiment) {
113118
case "happy":
114119
emojis = emojisList.happy;
115120
break;

0 commit comments

Comments
 (0)