feat: add messaging gateway startup functionality
- Introduced a new function to check for configured messaging platform tokens and prompt the user to start the gateway. - Updated the installation scripts to automatically start the gateway if messaging tokens are detected, enhancing user experience. - Expanded the README to include instructions for starting the gateway, ensuring users are informed about the necessary steps for message handling.
This commit is contained in:
parent
1c6846c4c2
commit
59cb0cecb2
3 changed files with 115 additions and 0 deletions
12
README.md
12
README.md
|
|
@ -85,6 +85,18 @@ All your settings are stored in `~/.hermes/` for easy access:
|
||||||
└── logs/ # Logs
|
└── logs/ # Logs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Messaging Platforms (Telegram, Discord, Slack)
|
||||||
|
|
||||||
|
If you configured a messaging bot token during setup, **start the gateway** so Hermes can receive and send messages:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hermes gateway # Run in foreground (see output)
|
||||||
|
hermes gateway install # Or install as a background service (Linux)
|
||||||
|
hermes gateway start # Start the background service
|
||||||
|
```
|
||||||
|
|
||||||
|
The installer will offer to do this automatically if it detects a bot token. See [Messaging Gateway](#messaging-gateway) below for full setup instructions.
|
||||||
|
|
||||||
### Managing Configuration
|
### Managing Configuration
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -544,6 +544,49 @@ function Invoke-SetupWizard {
|
||||||
Pop-Location
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Start-GatewayIfConfigured {
|
||||||
|
$envPath = "$HermesHome\.env"
|
||||||
|
if (-not (Test-Path $envPath)) { return }
|
||||||
|
|
||||||
|
$hasMessaging = $false
|
||||||
|
$content = Get-Content $envPath -ErrorAction SilentlyContinue
|
||||||
|
foreach ($var in @("TELEGRAM_BOT_TOKEN", "DISCORD_BOT_TOKEN", "SLACK_BOT_TOKEN", "SLACK_APP_TOKEN", "WHATSAPP_ENABLED")) {
|
||||||
|
$match = $content | Where-Object { $_ -match "^${var}=.+" -and $_ -notmatch "your-token-here" }
|
||||||
|
if ($match) { $hasMessaging = $true; break }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $hasMessaging) { return }
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Info "Messaging platform token detected!"
|
||||||
|
Write-Info "The gateway needs to be running for Hermes to send/receive messages."
|
||||||
|
Write-Host ""
|
||||||
|
$response = Read-Host "Would you like to start the gateway now? [Y/n]"
|
||||||
|
|
||||||
|
if ($response -eq "" -or $response -match "^[Yy]") {
|
||||||
|
$hermesCmd = "$InstallDir\venv\Scripts\hermes.exe"
|
||||||
|
if (-not (Test-Path $hermesCmd)) {
|
||||||
|
$hermesCmd = "hermes"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Info "Starting gateway in background..."
|
||||||
|
try {
|
||||||
|
$logFile = "$HermesHome\logs\gateway.log"
|
||||||
|
Start-Process -FilePath $hermesCmd -ArgumentList "gateway" `
|
||||||
|
-RedirectStandardOutput $logFile `
|
||||||
|
-RedirectStandardError "$HermesHome\logs\gateway-error.log" `
|
||||||
|
-WindowStyle Hidden
|
||||||
|
Write-Success "Gateway started! Your bot is now online."
|
||||||
|
Write-Info "Logs: $logFile"
|
||||||
|
Write-Info "To stop: close the gateway process from Task Manager"
|
||||||
|
} catch {
|
||||||
|
Write-Warn "Failed to start gateway. Run manually: hermes gateway"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Info "Skipped. Start the gateway later with: hermes gateway"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Write-Completion {
|
function Write-Completion {
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "┌─────────────────────────────────────────────────────────┐" -ForegroundColor Green
|
Write-Host "┌─────────────────────────────────────────────────────────┐" -ForegroundColor Green
|
||||||
|
|
@ -622,6 +665,7 @@ function Main {
|
||||||
Set-PathVariable
|
Set-PathVariable
|
||||||
Copy-ConfigTemplates
|
Copy-ConfigTemplates
|
||||||
Invoke-SetupWizard
|
Invoke-SetupWizard
|
||||||
|
Start-GatewayIfConfigured
|
||||||
|
|
||||||
Write-Completion
|
Write-Completion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -701,6 +701,64 @@ run_setup_wizard() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maybe_start_gateway() {
|
||||||
|
# Check if any messaging platform tokens were configured
|
||||||
|
ENV_FILE="$HERMES_HOME/.env"
|
||||||
|
if [ ! -f "$ENV_FILE" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
HAS_MESSAGING=false
|
||||||
|
for VAR in TELEGRAM_BOT_TOKEN DISCORD_BOT_TOKEN SLACK_BOT_TOKEN SLACK_APP_TOKEN WHATSAPP_ENABLED; do
|
||||||
|
VAL=$(grep "^${VAR}=" "$ENV_FILE" 2>/dev/null | cut -d'=' -f2-)
|
||||||
|
if [ -n "$VAL" ] && [ "$VAL" != "your-token-here" ]; then
|
||||||
|
HAS_MESSAGING=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$HAS_MESSAGING" = false ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
log_info "Messaging platform token detected!"
|
||||||
|
log_info "The gateway needs to be running for Hermes to send/receive messages."
|
||||||
|
echo ""
|
||||||
|
read -p "Would you like to install the gateway as a background service? [Y/n] " -n 1 -r
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
|
||||||
|
HERMES_CMD="$HOME/.local/bin/hermes"
|
||||||
|
if [ ! -x "$HERMES_CMD" ]; then
|
||||||
|
HERMES_CMD="hermes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v systemctl &> /dev/null; then
|
||||||
|
log_info "Installing systemd service..."
|
||||||
|
if $HERMES_CMD gateway install 2>/dev/null; then
|
||||||
|
log_success "Gateway service installed"
|
||||||
|
if $HERMES_CMD gateway start 2>/dev/null; then
|
||||||
|
log_success "Gateway started! Your bot is now online."
|
||||||
|
else
|
||||||
|
log_warn "Service installed but failed to start. Try: hermes gateway start"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_warn "Systemd install failed. You can start manually: hermes gateway"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_info "systemd not available — starting gateway in background..."
|
||||||
|
nohup $HERMES_CMD gateway > "$HERMES_HOME/logs/gateway.log" 2>&1 &
|
||||||
|
GATEWAY_PID=$!
|
||||||
|
log_success "Gateway started (PID $GATEWAY_PID). Logs: ~/.hermes/logs/gateway.log"
|
||||||
|
log_info "To stop: kill $GATEWAY_PID"
|
||||||
|
log_info "To restart later: hermes gateway"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_info "Skipped. Start the gateway later with: hermes gateway"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
print_success() {
|
print_success() {
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${GREEN}${BOLD}"
|
echo -e "${GREEN}${BOLD}"
|
||||||
|
|
@ -779,6 +837,7 @@ main() {
|
||||||
setup_path
|
setup_path
|
||||||
copy_config_templates
|
copy_config_templates
|
||||||
run_setup_wizard
|
run_setup_wizard
|
||||||
|
maybe_start_gateway
|
||||||
|
|
||||||
print_success
|
print_success
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue