# Slack Integration Fix - Action Checklist

**Last Updated:** 2026-03-06

Immediate action items to verify and fix the Slack integration.

## ✅ Implementation Complete

All code improvements have been implemented:
- ✅ Enhanced error logging with correlation IDs
- ✅ Retry logic with exponential backoff and jitter
- ✅ Payload validation
- ✅ Webhook URL validation
- ✅ Dedicated log file
- ✅ Monitoring and alerting
- ✅ Diagnostic scripts
- ✅ Documentation

## 🔍 Immediate Actions Required

### Step 1: Run Diagnostics (5 minutes)

```bash
# Run comprehensive diagnostics
php v2/scripts/affiliate/diagnose-slack-integration.php --verbose
```

**What to check:**
- ✅ cURL extension available
- ✅ Configuration enabled (`SLACK_LOOP_UPDATES_ENABLED = true`)
- ✅ Webhook URL configured and valid format
- ✅ Payload generation works
- ✅ Webhook connectivity test passes

### Step 2: Test Webhook (2 minutes)

```bash
# Test webhook connectivity
php v2/scripts/affiliate/test-slack-webhook.php --verbose
```

**Expected result:**
- ✅ Test message appears in #loop-updates channel
- ✅ No errors in output
- ✅ Success message displayed

### Step 3: Check Error Logs (5 minutes)

```bash
# Check dedicated log file
tail -n 50 v2/logs/affiliate-slack.log

# Check PHP error log
grep "[Affiliate Slack]" /var/log/php-fpm/error.log | tail -20
# or
grep "[Affiliate Slack]" /var/log/apache2/error.log | tail -20
```

**What to look for:**
- Recent failures with correlation IDs
- Error messages indicating root cause
- Retry attempts (if any)

### Step 4: Verify Webhook URL (5 minutes)

**In Slack API Dashboard:**
1. Go to https://api.slack.com/apps → **Ordio Loop**
2. Click **Incoming Webhooks**
3. Verify webhook for **#loop-updates** channel exists
4. Check if webhook is active
5. If expired/invalid: Regenerate webhook URL

**Update configuration:**
- Set `SLACK_LOOP_UPDATES_WEBHOOK_URL` environment variable, OR
- Update `v2/config/slack-config.local.php` with new webhook URL

### Step 5: Test Partner Registration Flow (10 minutes)

```bash
# Simulate partner registration
php v2/scripts/affiliate/test-partner-registration-slack.php --type=email
```

**Expected result:**
- ✅ Notification appears in #loop-updates
- ✅ Log entry created in `v2/logs/affiliate-slack.log`
- ✅ Success message displayed

## 🔧 If Issues Found

### Issue: Webhook URL Invalid/Expired

**Solution:**
1. Regenerate webhook in Slack API dashboard
2. Update environment variable or `slack-config.local.php`
3. Run test again: `php v2/scripts/affiliate/test-slack-webhook.php`

### Issue: Configuration Disabled

**Solution:**
1. Check `SLACK_LOOP_UPDATES_ENABLED` constant
2. Verify webhook URL is set and valid format
3. Run diagnostics: `php v2/scripts/affiliate/diagnose-slack-integration.php`

### Issue: cURL Errors

**Solution:**
1. Check network connectivity
2. Verify SSL certificates are up to date
3. Check firewall rules
4. Review error logs for specific cURL error codes

### Issue: Payload Validation Errors

**Solution:**
1. Check error logs for missing fields
2. Verify payload structure matches notification type
3. Review `validateSlackPayload()` function requirements

## 📊 Monitoring Setup (Recommended)

### Set Up Health Check Cron Job

```bash
# Add to crontab (check every 6 hours)
0 */6 * * * php /path/to/v2/scripts/affiliate/health-check-slack.php
```

### Monitor Log File

```bash
# Real-time monitoring
tail -f v2/logs/affiliate-slack.log
```

### Check Status Endpoint

```bash
# Admin-only endpoint
curl -b cookies.txt https://www.ordio.com/v2/api/slack-notification-status.php
```

## ✅ Verification Checklist

After fixes are applied:

- [ ] Diagnostic script passes all checks
- [ ] Test webhook sends message successfully
- [ ] Test partner registration sends notification
- [ ] Log file is being written to
- [ ] No errors in PHP error log
- [ ] Next real partner registration triggers notification
- [ ] Health check cron job set up (optional but recommended)

## 📝 Next Partner Registration

When next partner registers:

1. **Immediately check:**
   - Does notification appear in #loop-updates?
   - Check log file: `tail -f v2/logs/affiliate-slack.log`
   - Look for correlation ID in logs

2. **If notification appears:**
   - ✅ Integration is working!
   - Monitor for 24-48 hours
   - Review statistics weekly

3. **If notification doesn't appear:**
   - Check log file for failure entry
   - Review correlation ID in logs
   - Run diagnostics again
   - Check webhook URL validity

## 🆘 Still Not Working?

1. **Run full diagnostics:**
   ```bash
   php v2/scripts/affiliate/diagnose-slack-integration.php --verbose
   ```

2. **Check all logs:**
   ```bash
   tail -100 v2/logs/affiliate-slack.log
   grep "[Affiliate Slack]" /var/log/php-fpm/error.log
   ```

3. **Test webhook manually:**
   ```bash
   curl -X POST https://hooks.slack.com/services/T.../B.../... \
     -H 'Content-Type: application/json' \
     -d '{"text":"Manual test"}'
   ```

4. **Review documentation:**
   - [SLACK_TROUBLESHOOTING.md](SLACK_TROUBLESHOOTING.md) - Detailed troubleshooting
   - [SLACK_MONITORING.md](SLACK_MONITORING.md) - Monitoring guide
   - [SLACK_QUICK_START.md](SLACK_QUICK_START.md) - Quick reference

## 📞 Support

If issues persist after following all steps:
- Review error logs with correlation IDs
- Check Slack API status: https://status.slack.com
- Verify webhook URL in Slack API dashboard
- Contact Slack support if webhook issues persist

## Related Documentation

- [SLACK_INTEGRATION_FIX_SUMMARY.md](SLACK_INTEGRATION_FIX_SUMMARY.md) - Complete implementation summary
- [SLACK_LOOP_UPDATES.md](SLACK_LOOP_UPDATES.md) - Integration overview
- [SLACK_TROUBLESHOOTING.md](SLACK_TROUBLESHOOTING.md) - Troubleshooting guide
- [SLACK_MONITORING.md](SLACK_MONITORING.md) - Monitoring guide
- [SLACK_QUICK_START.md](SLACK_QUICK_START.md) - Quick reference
