diff --git a/bot/src/commands/button.js b/bot/src/commands/button.js index fa711d7..1c11c20 100644 --- a/bot/src/commands/button.js +++ b/bot/src/commands/button.js @@ -1,10 +1,18 @@ +/* + This is a sample command that creates a button in the slack message. + The button click event is handled by the button method. + +*/ + import logger from "command-handler/src/util/logger.js"; +//initialize logger const log = logger(); export default { description: 'creates a button', + //button click event handler This is called when the button is clicked button: ({ handler, body, response }) => { log.info("Clicked the button", body.user) response({ @@ -12,9 +20,15 @@ export default { }) }, + //run method is called when the command is executed + //To execute this command type !button in the slack channel where the bot is installed + //The paramaters are descructured from the object passed to the run method + //response is used to send the response back to the slack channel + //event is the event object that contains the event details from slack. run: ({ response, event }) => { response({ + //blocks is used to create a button in the slack message blocks: [ { "type": "section", @@ -32,6 +46,7 @@ export default { } } ], + //text is fallback text that is displayed when the message is not supported text: `Hey there <@${event.user}>!` }) } diff --git a/bot/src/commands/hello.js b/bot/src/commands/hello.js index ea9b3da..6e5b965 100644 --- a/bot/src/commands/hello.js +++ b/bot/src/commands/hello.js @@ -1,3 +1,8 @@ +/* + This is a simple command that replies with "Hey there <@user>!" after 5 seconds. +*/ + +//delay function to simulate a delay const delay = (ms) => { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -6,10 +11,12 @@ export default { description: 'Replies with Hello', run: async ({ response, event }) => { + //call the delay function to simulate a delay of 5 seconds. await delay(5000); + //send the response back to the slack channel After the delay response({ text: `Hey there <@${event.user}>!` - }) + }); } } \ No newline at end of file diff --git a/bot/src/commands/ping.js b/bot/src/commands/ping.js index 86cc005..e991185 100644 --- a/bot/src/commands/ping.js +++ b/bot/src/commands/ping.js @@ -1,3 +1,7 @@ +/* + This is a simple command that replies with pong +*/ + export default { description: 'Replies with pong', diff --git a/bot/src/index.js b/bot/src/index.js index a84d2c4..4810b37 100644 --- a/bot/src/index.js +++ b/bot/src/index.js @@ -18,10 +18,13 @@ const customLogger = { }; //receiver to integrate express with bolt +//The receiver is what allows Bolt to communicate with Slack's servers. +//The receiver listens for incoming HTTP requests from Slack, and then forwards them to the Bolt app. const receiver = new ExpressReceiver({ signingSecret: process.env.SIGNING_SECRET, }); +// Initialize Bolt app with custom logger and receiver const app = new App({ token: process.env.BOT_TOKEN, receiver, @@ -30,11 +33,13 @@ const app = new App({ logger: customLogger, }); +//function that starts the server and initializes the command handler (async () => { server(receiver); new CH({ + //passing the bolt app to the command handler app, - featuresDir: path.join(process.cwd(), 'src', 'features'), + //directory where the commands are located commandsDir: path.join(process.cwd(), 'src', 'commands'), }); })(); \ No newline at end of file diff --git a/server/server.js b/server/server.js index 48e75b7..8eab0ab 100644 --- a/server/server.js +++ b/server/server.js @@ -1,18 +1,28 @@ +/* + This is the entry point for the Bolt app. It defines the express server that listens for incoming requests from Slack. +*/ + import express from 'express'; import logger from '../command-handler/src/util/logger.js'; +// This function creates an express server that listens for incoming requests from Slack. export default (receiver) => { const app = express(); const log = logger(); + // The port on which the express server will listen for incoming requests. + // The default port is 5000, but it can be overridden by setting the SERVER_PORT environment variable. const port = process.env.SERVER_PORT || 5000; + // Attach the receiver's request listener to the express server. app.use('/', receiver.router); + // Define a simple health check route that returns a 200 status code. app.get('/', (req, res) => { res.sendStatus(200); - }) + }); + // Start the express server. app.listen(port, () => { log.info(`The Bolt express server is listening on ${port}`) - }) + }); } \ No newline at end of file