Skip to content

A Node.js script to fetch time tracking data from Clockify API and send formatted daily updates to Slack using message blocks

Notifications You must be signed in to change notification settings

afzalimdad9/slack-updates

Repository files navigation

📅 Clockify Daily Update Bot for Slack

A Node.js script that automatically fetches time tracking data from Clockify API and sends formatted daily updates to Slack using simple text messages.

✨ Features

  • Clockify Integration: Fetches time entries and project data from Clockify API
  • Project Grouping: Groups tasks by project for better organization
  • Date Filtering: Only sends today's updates (or custom date)
  • Simple Text Format: Clean, readable text messages (no complex blocks)
  • Environment Configuration: Secure credential management
  • Error Handling: Comprehensive error handling and logging

🚀 Quick Start

1. Clone and Setup

git clone <your-repo>
cd slack-updates
npm install

2. Configure Environment

Copy the example environment file and fill in your credentials:

cp .env.example .env

Edit .env with your actual values:

# Clockify API Configuration
CLOCKIFY_API_KEY=your_clockify_api_key
CLOCKIFY_USER_ID=your_user_id
CLOCKIFY_WORKSPACE_ID=your_workspace_id

# Slack Configuration
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
SLACK_CHANNEL=#daily-updates
SLACK_BOT_NAME=Daily Update Bot
SLACK_BOT_ICON=:memo:

3. Test Configuration

# Test Clockify connection
npm run test:connection

# Test Slack webhook
npm run test:slack

# Test full functionality
npm test

4. Run the Bot

npm start

📋 Example Output

Daily Update:
 ReqMe:
Fix editor spacing issue in company description field and update readme with the latest environment configuration details in both frontend and backend
Update tags in wordpress SVN to 1.0.0 for plugin
Update the SOW for deals flow according to Yashua's feedback

⚙️ Configuration

Clockify Setup

  1. Get API Key:

    • Go to Clockify → Profile → API → Generate API Key
  2. Find User ID:

    • Go to Clockify → Profile → Copy User ID
  3. Find Workspace ID:

    • Go to Clockify → Workspace Settings → Copy Workspace ID

Slack Setup

  1. Create Webhook:

    • Go to Slack App → Your Apps → Create New App
    • Add "Incoming Webhooks" feature
    • Create webhook for your channel
    • Copy webhook URL
  2. Configure Channel:

    • Set SLACK_CHANNEL to your target channel (e.g., #daily-updates)

🔧 Customization

Change Date Filter

Edit config.js:

DATE_FILTER: {
  USE_TODAY: true,  // Set to false for custom date
  CUSTOM_DATE: "2025-07-30"  // Use when USE_TODAY is false
}

Modify Message Format

Edit the createSlackMessage function in slack-daily-update.js:

function createSlackMessage(entries, projects) {
  let message = `${config.MESSAGE.HEADER}:\n`;
  // Customize your message format here
}

Add User Information

To include user names in the output, modify the grouping logic:

// In createSlackMessage function
entries.forEach((entry) => {
  const projectId = entry.projectId;
  const projectName = getProjectName(projectId, projects);
  const userName = getUserName(entry.userId, users); // Add user lookup
  
  const key = `${projectName} - ${userName}`;
  // ... rest of the logic
});

🧪 Testing

Test Clockify Connection

npm run test:connection

Test Slack Webhook

npm run test:slack

Preview Message Format

npm test

This will show you exactly what the message will look like without sending it to Slack.

🐛 Troubleshooting

Common Issues

  1. 401 Unauthorized:

    • Check your CLOCKIFY_API_KEY
    • Verify the API key is active
  2. 404 Not Found:

    • Verify CLOCKIFY_WORKSPACE_ID and CLOCKIFY_USER_ID
    • Check if the workspace/user exists
  3. No entries found:

    • Check if you have time entries for the target date
    • Verify the date format and timezone
  4. Slack webhook errors:

    • Verify your webhook URL is correct
    • Check if the webhook is still active
    • Ensure the channel exists and the bot has access

Debug Mode

The script includes detailed logging. Check the console output for:

  • API request details
  • Response data
  • Message format preview
  • Error details

📅 Scheduling

Using Cron (Linux/Mac)

Add to your crontab:

# Run daily at 5:00 PM
0 17 * * * cd /path/to/slack-updates && npm start

Using Task Scheduler (Windows)

  1. Open Task Scheduler
  2. Create Basic Task
  3. Set trigger to daily at 5:00 PM
  4. Set action to start program: node
  5. Add arguments: slack-daily-update.js
  6. Set start in: /path/to/slack-updates

🔄 API Endpoints Used

  • GET /workspaces/{workspaceId}/projects - Fetch projects
  • GET /workspaces/{workspaceId}/user/{userId}/time-entries - Fetch time entries

📝 License

MIT License - feel free to use and modify as needed.

About

A Node.js script to fetch time tracking data from Clockify API and send formatted daily updates to Slack using message blocks

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published