Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ROCKETCHAT_SERVER_URL=https://chat.yourcompany.com
ROCKETCHAT_BOT_USERNAME=geekbot
ROCKETCHAT_BOT_PASSWORD=your-password

# Alternative: read password from a file (avoids shell/env escaping issues)
# ROCKETCHAT_BOT_PASSWORD_FILE=/run/secrets/bot_password

ROCKETCHAT_MAIN_ADMIN=admin_username
STANDUP_DB_PATH=/data/standup-bot.db

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ cp .env.example .env
|----------|----------|---------|-------------|
| `ROCKETCHAT_SERVER_URL` | Yes | — | Rocket.Chat server URL |
| `ROCKETCHAT_BOT_USERNAME` | Yes | — | Bot account username |
| `ROCKETCHAT_BOT_PASSWORD` | Yes | — | Bot account password |
| `ROCKETCHAT_BOT_PASSWORD` | One of | — | Bot account password (use if password has no special chars) |
| `ROCKETCHAT_BOT_PASSWORD_FILE` | One of | — | Path to file containing the bot password (avoids shell/env escaping) |
| `ROCKETCHAT_MAIN_ADMIN` | Yes | — | Rocket.Chat username of the main bot administrator |
| `STANDUP_DB_PATH` | No | `~/standup-bot.db` | Path to the SQLite database file |

Expand Down
14 changes: 13 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"fmt"
"os"
"strings"
)

type Config struct {
Expand All @@ -13,10 +14,21 @@ type Config struct {
}

func Load() (*Config, error) {
botPass := os.Getenv("ROCKETCHAT_BOT_PASSWORD")
if botPass == "" {
if path := os.Getenv("ROCKETCHAT_BOT_PASSWORD_FILE"); path != "" {
b, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("reading ROCKETCHAT_BOT_PASSWORD_FILE: %w", err)
}
botPass = strings.TrimSpace(string(b))
}
}

cfg := &Config{
ServerURL: os.Getenv("ROCKETCHAT_SERVER_URL"),
BotUser: os.Getenv("ROCKETCHAT_BOT_USERNAME"),
BotPass: os.Getenv("ROCKETCHAT_BOT_PASSWORD"),
BotPass: botPass,
MainAdmin: os.Getenv("ROCKETCHAT_MAIN_ADMIN"),
}

Expand Down
19 changes: 19 additions & 0 deletions internal/rocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/url"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -75,6 +76,9 @@ func (c *Client) Connect(user, password string) error {
log.Printf("Connecting to Rocket.Chat at %s", c.serverURL.String())

if err := c.connect(); err != nil {
if isAuthError(err) {
return fmt.Errorf("authentication failed — check bot credentials: %w", err)
}
return err
}

Expand Down Expand Up @@ -117,6 +121,17 @@ func (c *Client) connect() error {
return nil
}

func isAuthError(err error) bool {
if err == nil {
return false
}
s := err.Error()
return strings.Contains(s, "401") ||
strings.Contains(s, "User not found") ||
strings.Contains(s, "error-login-blocked") ||
strings.Contains(s, "Login has been temporarily blocked")
}

func (c *Client) Disconnect() {
c.mu.Lock()
defer c.mu.Unlock()
Expand Down Expand Up @@ -244,6 +259,10 @@ func (c *Client) watchConnection() {
err := c.connect()
c.mu.Unlock()

if isAuthError(err) {
log.Fatalf("Authentication failed — check bot credentials: %v", err)
}

if err == nil {
log.Println("Reconnected successfully")

Expand Down
Loading