================================================================================
                    MATTERMOST LOCAL API - QUICK SETUP GUIDE
================================================================================

🎯 **SIMPLE SSH-BASED SOLUTION**

Instead of complex web routing, this runs a LOCAL API on your Mattermost server
that uses SSH to retrieve onion addresses from the VPS.

================================================================================
                              SETUP STEPS
================================================================================

📦 **1. ON YOUR MATTERMOST SERVER:**

mkdir ~/btcpay-api
cd ~/btcpay-api

# Copy files (adjust paths for your environment):
cp /path/to/mattermost_local_api.js ./
cp /path/to/mattermost-local-package.json ./package.json
cp /path/to/vps_hardening_key ./

# Install dependencies:
npm install

# Fix SSH key permissions:
chmod 600 ./vps_hardening_key

🔧 **2. UPDATE CONFIGURATION:**

Edit mattermost_local_api.js and update:
ssh_key_path: '/home/your-user/btcpay-api/vps_hardening_key'

🚀 **3. START THE API:**

node mattermost_local_api.js

📱 **4. CONFIGURE MATTERMOST SLASH COMMAND:**

System Console → Integrations → Slash Commands → Add Slash Command:

Command: /btcpay
URL: http://localhost:3333/btcpay  
Method: POST
Token: dr7gz6xwmt8qjg71wxcqjwqz1r

================================================================================
                                 USAGE
================================================================================

💬 **IN MATTERMOST:**

/btcpay                    → Get onion addresses
/btcpay status             → Get system status  
/btcpay help               → Show commands

📤 **EXAMPLE RESPONSE:**

## 🧅 BTCPay Tor Onion Addresses

🌐 Domain: https://thebankofdebbie.giize.com

🧅 Tor Hidden Services:
• BTCPay Server: gs76yqhlb4oysidnnswfoigxtwz3kmlmz4ekp2r6knmerpvsjdtbpxyd.onion
• Bitcoin P2P: p4gve626jjn73ia35ikr7zhnmwknokrzv2eb2gfbqlytlgbckhaeibyd.onion

🔐 Access Methods:
• Clearnet: https://thebankofdebbie.giize.com
• Tor Browser: http://gs76yqhlb4oysidnnswfoigxtwz3kmlmz4ekp2r6knmerpvsjdtbpxyd.onion

📅 Retrieved: 2025-09-10 17:25:30
👤 Requested by: bankofdebbie

================================================================================
                               SECURITY
================================================================================

✅ **SECURE DESIGN:**
- Local API only (localhost:3333)
- SSH key authentication to VPS
- No VPS ports exposed for webhook
- Token validation for Mattermost
- On-demand connections only

❌ **NO PERSISTENT CONNECTIONS:**
- No permanent SSH tunnels
- No exposed VPS webhook ports  
- No authentication issues
- Clean, simple architecture

================================================================================
                               TESTING
================================================================================

🧪 **TEST COMMANDS:**

# Test SSH connectivity:
curl http://localhost:3333/test

# Test health:
curl http://localhost:3333/health

# Test Mattermost webhook:
curl -X POST http://localhost:3333/btcpay -H "Content-Type: application/json" -d '{"token":"dr7gz6xwmt8qjg71wxcqjwqz1r","user_name":"bankofdebbie","text":"onion"}'

================================================================================
                            FINAL RESULT
================================================================================

🎯 **PERFECT SOLUTION:**
- No complex nginx routing
- No VPS web services  
- No authentication issues
- Simple SSH-based retrieval
- Secure localhost-only API
- Clean Mattermost integration

🚀 **READY TO USE!**

Your BTCPay Server with Tor is fully operational.
Your Mattermost bot can now retrieve onion addresses securely via SSH.
No exposed ports, maximum security maintained.

================================================================================