Skip to content

Commit

Permalink
Adding help slash command (#437)
Browse files Browse the repository at this point in the history
* fix: removing old items from rewards.json

* feat: implementing a slash command for help

* chore: add comments and remove console log and warn

* chore: clean up and lint

* chore: clean up and lint

* chore: linting fixed and cleaned

---------

Co-authored-by: zjorge96 <[email protected]>
  • Loading branch information
densellp and zjorge96 authored Oct 19, 2023
1 parent c61fe1f commit cfea27f
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 44 deletions.
142 changes: 141 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ const { App } = require("@slack/bolt");
const express = require("express");
const webserver = express();
const winston = require("./winston");
const {
recognizeEmoji,
maximum,
reactionEmoji,
goldenRecognizeEmoji,
slashCommand,
} = require("./config");

const app = new App({
token: process.env.BOT_USER_OAUTH_ACCESS_TOKEN,
Expand Down Expand Up @@ -65,9 +72,142 @@ require("fs")
require("./features/" + file)(app);
});

/// ////////////////////////////////////////////////////////////
// Slash Command Logic //
/// ////////////////////////////////////////////////////////////

app.command(slashCommand, async ({ command, ack, respond }) => {
await ack();
const userCommand = parseCommand(command);

switch (userCommand.command) {
case "help":
await respond(helpMarkdown);
}
});

(async () => {
await app.start();
await app.start(3000);
webserver.listen(process.env.PORT || 3000);

winston.info("⚡️ Bolt app is running!");
})();

/// ////////////////////////////////////////////////////////////
// Functions //
/// ////////////////////////////////////////////////////////////

// Parse Command Function
function parseCommand(command) {
const parsed = {
// Default values for each parameter
valid: false, // indicates if a command is valid
command: "", // holds the type of command
user: "", // holds the value for the user that will be targeted
};

const raw = command.text.split(" "); // raw command as an array
parsed.command = raw[0];

switch (raw[0]) {
case "help":
parsed.valid = true; // command is valid, but doesn't require any additional info
break;
}

// if none of the above cases are true, parsed.valid will stay false

return parsed;
}

/// ////////////////////////////////////////////////////////////
// Variables //
/// ////////////////////////////////////////////////////////////

// Text is rendered into help command
const helpMarkdown = `
:wave: Hi there! Let's take a look at what I can do!
*Give Recognition*
You can give up to ${maximum} recognitions per day.
First, make sure I have been invited to the channel you want to recognize \
someone in. Then, write a brief message describing what someone did, \
\`@mention\` them and include the ${recognizeEmoji} emoji...I'll take it from there!
> Thanks @alice for helping me fix my pom.xml ${recognizeEmoji}
Recognize multiple people at once!
> @bob and @alice crushed that showcase! ${recognizeEmoji}
Use \`#tags\` to call out specific Liatrio values!
> I love the #energy in your Terraform demo @alice! ${recognizeEmoji}
The more emojis you add, the more recognition they get!
> @alice just pushed the cleanest code I've ever seen! ${recognizeEmoji} ${recognizeEmoji} ${recognizeEmoji}
Use multipliers to give more recognition!
> @alice presented an amazing demo at a conference! ${recognizeEmoji} x2
or
> @alice presented an amazing demo at a conference! x2 ${recognizeEmoji}
If someone else has given a ${recognizeEmoji} to someone, and you'd like to \
give one of your own for the same reason, you can react to the message with \
a ${reactionEmoji}. Gratibot will record your shout-out as though you sent \
the same message that you reacted to.
*Redeeming*
Send me a direct message with 'redeem' and I'll give you the options for prizes to redeem! Once you've selcted an item then I'll start a MPIM with the redemption admins to promote the dialog to acknowledge and receive your item.
Refunds can be given via the 'refund' command if the item redeem can't be fulfilled for whatever reason. Only redemption admins can give refunds. Deduction ID is sent as part of the MPIM when an item is redeemed
> @gratibot refund DEDUCTIONID
*View Balance*
Send me a direct message with 'balance' and I'll let you know how many \
recognitions you have left to give and how many you have received.
> You have received 0 ${recognizeEmoji} and you have ${maximum} ${recognizeEmoji} remaining to \
give away today
*View Leaderboard*
Send me a direct message with 'leaderboard' and I'll show you who is giving \
and receiving the most recognition. I'll also show who currently holds the :goldenfistbump:!
*View Metrics*
Send me a direct message with 'metrics' and I'll show you how many times \
people have given recognitions over the last month.
*Give Golden Recognition*
The golden fistbump ${goldenRecognizeEmoji} is a special recognition that can only be held by one user at a time. Only the current holder of the golden recognition can give the golden recognition.
Giving a golden fistbump is the same as giving a normal fistbump
> Thanks @alice for helping fix the prod issues! ${goldenRecognizeEmoji}
Upon receiving the golden fistbump, the user will receive 20 fistbumps and will have a 2X multiplier applied to all incoming fistbumps while the golden fistbump is held.
`;
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ config.reactionEmoji = process.env.REACTION_EMOJI || ":nail_care:";
config.maximum = process.env.GRATIBOT_LIMIT || 5;
config.minimumMessageLength = 20;
config.botName = process.env.BOT_NAME || "gratibot";
config.slashCommand = process.env.SLASH_COMMAND || "/gratibot";

config.usersExemptFromMaximum = process.env.EXEMPT_USERS?.split(",") || [
"U037FL37G",
Expand All @@ -31,4 +32,10 @@ config.redemptionAdmins = process.env.REDEMPTION_ADMINS?.split(",") || [
"U04666K57CP",
];

config.usersDeduction = process.env.USERS_DEDUCTION?.split(",") || [
"U04666K57CP", // Danielle
"U8T585Y8J", // Jeremy
"U02KPMFA9DG", // Smith
];

module.exports = config;
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
- GOLDEN_RECOGNIZE_HOLDER
- REDEMPTION_ADMINS
- BOT_NAME
- SLASH_COMMAND
mongodb:
ports:
- 27017:27017
Expand Down
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions rewards.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
[
{
"name": "Visa Gift Card",
"description": "$25 Visa Gift Card",
"imageURL": "https://gratibotjtest.blob.core.windows.net/gratibotimages/image (11).png",
"cost": 100
[
{
"name": "Pre-Loved Laptop",
"description": "Pre-Loved Laptop",
"imageURL": "https://gratibotjtest.blob.core.windows.net/gratibotimages/Pre Loved Laptop.jpeg",
"cost": 500
},
{
"name": "Custom Nike Air Force 1's",
"description": "Nike Air Force 1 Shoes",
"imageURL": "https://gratibotjtest.blob.core.windows.net/gratibotimages/Liatrio_Nike_Air_Force1.png",
"cost": 500
},
{
"name": "Pre-Loved Laptop",
"description": "Pre-Loved Laptop",
"imageURL": "https://gratibotjtest.blob.core.windows.net/gratibotimages/Pre Loved Laptop.jpeg",
"cost": 500
},
{
"name": "Hawaiian Shirt",
"description": "Hawaiian Shirt.",
"imageURL": "https://gratibotjtest.blob.core.windows.net/gratibotimages/5_HawaiianShirt.png",
"cost": 80
},
{
{
"name": "Visa Gift Card",
"description": "$25 Visa Gift Card",
"imageURL": "https://gratibotjtest.blob.core.windows.net/gratibotimages/image (11).png",
"cost": 100
},
{
"name": "Donation: Open Source Mental Health",
"description": "Donate $50 to Open Source Mental Health",
"imageURL": "https://gratibotjtest.blob.core.windows.net/gratibotimages/OSMH logo.jpeg",
Expand Down

0 comments on commit cfea27f

Please sign in to comment.