diff --git a/README.md b/README.md index 1631846..8415d22 100644 --- a/README.md +++ b/README.md @@ -1 +1,88 @@ -# Chrono-slack-app \ No newline at end of file +# Chrono + +Chrono is a Slack app that helps teams coordinate across time zones. It provides simple commands to convert times, check individual availability, and view current times for team members in a channel or user group. + +--- + +## Features + +### Slash Commands + +- **`/convert [time] [from_timezone] [to_timezone]`** + Example: `/convert 3pm est pst` + Converts a time between two time zones. Inputs are not case sensitive. + +- **`/timefor @user`** + Example: `/time @user` + Converts a time (assumed to be your current time in your local timezone) into the target user’s time zone. + +- **`/teamclock` or `/teamclock @usergroup`** + Displays the current time for each member in the channel or user group. Indicates general availability (e.g. before 9 AM = unavailable). + +### Workflows + +- **Quick Convert** + DM-based version of `/convert`. Enter a time and time zone, receive the converted time. + +- **Teammate Time** + DM-based version of `/time`. Enter a time and a user to receive the converted time in their zone. + +--- + +## Setup & Installation + +### 1. Create the Slack App + +1. Visit: [https://api.slack.com/apps](https://api.slack.com/apps) +2. Choose "Create New App" and "From an app manifest" +3. Select a workspace and paste the contents of `manifest.json` into the JSON input field. +4. Click Next, review, and Create. +5. Click Install to Workspace and authorize the app. + +### 2. Configure Environment Variables + +Create a `.env` file in the project root directory with the following: + +``` +SLACK_BOT_TOKEN=your-bot-token +SLACK_APP_TOKEN=your-app-level-token + +``` + +To get these: + +- **Bot Token**: Found under **OAuth & Permissions** in the app settings. Copy the "Bot User OAuth Token". +- **App Token**: Found under **Basic Information > App-Level Tokens**. Create one with `connections:write` scope. + +--- + +### 3. Run Chrono Locally + +Make sure Node.js is installed. + +Run: + +```bash +git clone https://github.com/yourusername/chrono.git +cd chrono +npm install +node app.js +``` + +(Chrono uses Socket Mode) + +--- + +### 4. Start Using Chrono + +Once the app is running and installed: + +- Add the bot to a channel: + ``` + /invite @Chrono + ``` + +- Try out a command: + ``` + /convert 2pm est pst + ``` \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..b32f54e --- /dev/null +++ b/app.js @@ -0,0 +1,39 @@ +const { App } = require('@slack/bolt'); + +// Import slash commands +const convertCommand = require("./commands/convertTime"); +const timeForCommand = require("./commands/timeFor"); +const teamClockCommand = require("./commands/teamClock"); + +// Import workflows +const { + handleTimeZoneConversionWF, + handleUserConversionWF, +} = require("./workflows/conversionWorkflows.js"); + +// Initializing Bolt app with Socket Mode +const app = new App({ + token: process.env.SLACK_BOT_TOKEN, + socketMode: true, + appToken: process.env.SLACK_APP_TOKEN, +}); + +// Handle app_mention events +app.event("app_mention", async ({ event, say }) => { + await say(`Hello there, <@${event.user}>!`); +}); + +// Register slash commands +app.command("/convert", convertCommand); +app.command("/timefor", timeForCommand); +app.command("/teamclock", teamClockCommand); + +// Register workflow functions +app.function("Time_zone_converted_WF", handleTimeZoneConversionWF); +app.function("Userconv", handleUserConversionWF); + +// Start Bolt app +(async () => { + await app.start(); + app.logger.info("⚡️ Bolt app is running!"); +})(); \ No newline at end of file diff --git a/commands/convertTime.js b/commands/convertTime.js new file mode 100644 index 0000000..f5e1897 --- /dev/null +++ b/commands/convertTime.js @@ -0,0 +1,22 @@ +// Import logic file +const { convertTimeCommandText } = require("./convertTimeLogic"); + +const convertCommand = async ({ command, ack, respond, logger }) => { + try { + await ack(); + const { error, result } = convertTimeCommandText(command.text); + + if (error) { + await respond({ text: error }); + return; + } + + await respond({ text: result }); + + } catch (error) { + logger.error('Error handling convert command:', error); + } +}; + +module.exports = convertCommand; + diff --git a/commands/convertTimeLogic.js b/commands/convertTimeLogic.js new file mode 100644 index 0000000..907009f --- /dev/null +++ b/commands/convertTimeLogic.js @@ -0,0 +1,75 @@ +/* Handles the /convert slash command + * Converts a given time from a given timezone to a target timezone + * Expects input: '/convert