Przejdź do treści

Notifer CLI

Notifer CLI to narzędzie wiersza poleceń open-source do interakcji z Notifer. Pozwala publikować wiadomości, subskrybować tematy, zarządzać kluczami API i konfigurować tematy - wszystko z terminala.

Open Source

CLI jest open source i dostępne na github.com/nexolab-projects/notifer-cli

Instalacja

Zainstaluj przez pip:

pip install notifer-cli

Lub zainstaluj ze źródeł:

git clone https://github.com/nexolab-projects/notifer-cli.git
cd notifer-cli
pip install -e .

Zweryfikuj instalację:

notifer --version

Szybki start

1. Uwierzytelnienie

# Opcja 1: Logowanie z email/hasłem
notifer login user@example.com

# Opcja 2: Użyj klucza API
notifer config set api-key noti_your_key_here

2. Utwórz temat

Tematy muszą istnieć przed publikowaniem

Musisz utworzyć temat przed publikowaniem do niego wiadomości. Tematy NIE są tworzone automatycznie.

notifer topics create my-topic --description "My first topic"

3. Opublikuj wiadomość

notifer publish my-topic "Hello from CLI!"

4. Subskrybuj wiadomości

notifer subscribe my-topic

Dokumentacja poleceń

Konfiguracja

notifer config init

Utwórz nowy plik konfiguracyjny w ~/.notifer.yaml:

notifer config init

notifer config show

Wyświetl aktualną konfigurację:

notifer config show

Wynik:

server: https://app.notifer.io
api_key: noti_abc...
email: user@example.com
defaults:
  priority: 3
  tags: []

notifer config set <key> <value>

Ustaw wartość konfiguracji:

# Ustaw klucz API
notifer config set api-key noti_your_key_here

# Ustaw email
notifer config set email user@example.com

Prawidłowe klucze: api-key, email

notifer config get <key>

Pobierz wartość konfiguracji:

notifer config get api-key

Uwierzytelnianie

notifer login [email]

Zaloguj się z email i hasłem. Przechowuje tokeny JWT w ~/.notifer.yaml:

# Z email jako argumentem
notifer login user@example.com
# Password: ********

# Lub z pytaniem o oba
notifer login
# Email: user@example.com
# Password: ********

Wynik:

╭─────────── Login Successful ───────────╮
│ ✓ Logged in as user@example.com        │
│                                        │
│ Username: john_doe                     │
│ Tier: pro                              │
│ Tokens saved to: ~/.notifer.yaml       │
╰────────────────────────────────────────╯

notifer logout

Wyczyść zapisane dane uwierzytelniające:

notifer logout

Publikowanie wiadomości

notifer publish <topic> <message> [OPTIONS]

Opublikuj wiadomość do tematu:

notifer publish my-topic "Hello World!"

Opcje:

Opcja Opis
--title, -t Tytuł wiadomości
--priority, -p Poziom priorytetu (1-5, domyślnie: 3)
--tags Tagi oddzielone przecinkami
--api-key Nadpisz klucz API
--server Nadpisz URL serwera

Przykłady:

# Podstawowa wiadomość
notifer publish alerts "Server is up"

# Z tytułem i priorytetem
notifer publish alerts "Server is down!" \
  --title "Critical Alert" \
  --priority 5

# Z tagami
notifer publish monitoring "CPU at 95%" \
  --tags "server,cpu,warning"

# Połączone opcje
notifer publish deployments "Build #123 completed" \
  --title "Build Success" \
  --priority 4 \
  --tags "ci,build,success"

# Z treścią markdown
notifer publish updates "# Release v1.2.3\n\n**Features:**\n- New dashboard\n- Bug fixes"

Wynik:

╭─────────── Published ───────────╮
│ ✓ Message published to alerts   │
│                                 │
│ ID: msg_abc123xyz               │
│ Timestamp: 2025-12-15T10:30:00Z │
│ Priority: 4                     │
╰─────────────────────────────────╯

Obsługa błędów:

Jeśli temat nie istnieje:

✗ Error: Topic 'nonexistent' not found. Create the topic first via the web app, API, or CLI before publishing messages.


Subskrybowanie tematów

notifer subscribe <topics> [OPTIONS]

Subskrybuj temat i odbieraj wiadomości w czasie rzeczywistym przez SSE:

notifer subscribe my-topic

Opcje:

Opcja Opis
--output, -o Zapisz wiadomości do pliku (format JSONL)
--since Pokaż tylko wiadomości od znacznika czasu (format ISO)
--json Wypisz surowy JSON (bez formatowania)
--api-key Nadpisz klucz API
--server Nadpisz URL serwera

Przykłady:

# Podstawowa subskrypcja
notifer subscribe alerts

# Zapisz do pliku
notifer subscribe alerts --output messages.jsonl

# Surowy wynik JSON (do przekierowania)
notifer subscribe alerts --json

# Przekieruj do jq
notifer subscribe alerts --json | jq '.message'

# Wiadomości od określonego czasu
notifer subscribe alerts --since "2025-12-15T00:00:00Z"

Wynik (sformatowany):

╭───────── Listening ─────────╮
│ Subscribed to: alerts       │
│ Press Ctrl+C to stop        │
╰─────────────────────────────╯

P5 Critical Alert (2025-12-15 10:30:00)
Server is down!
Tags: server, critical
────────────────────────────────────────────────────────

P3 Deploy (2025-12-15 10:31:15)
Deployment completed successfully
Tags: ci, deploy
────────────────────────────────────────────────────────

Wynik (JSON):

{"id":"msg_abc123","topic":"alerts","message":"Server is down!","title":"Critical Alert","priority":5,"tags":["server","critical"],"timestamp":"2025-12-15T10:30:00Z"}

Format pliku JSONL:

{"id":"msg_abc123","topic":"alerts","message":"Hello","timestamp":"2025-12-15T10:30:00Z"}
{"id":"msg_def456","topic":"alerts","message":"World","timestamp":"2025-12-15T10:31:00Z"}

Zarządzanie tematami

notifer topics list [OPTIONS]

Wyświetl listę tematów:

# Wyświetl wszystkie publiczne tematy
notifer topics list

# Wyświetl tylko swoje tematy
notifer topics list --mine

# Ogranicz wyniki
notifer topics list --limit 10

Wynik:

                              Topics
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ Name        ┃ Access      ┃ Messages ┃ Subscribers ┃ Description      ┃
┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ alerts      │ 🌍 Public   │ 1234     │ 56          │ System alerts    │
│ deployments │ 🔒 Private  │ 89       │ 12          │ CI/CD events     │
│ monitoring  │ 🌍 Public   │ 567      │ 23          │ Server metrics   │
└─────────────┴─────────────┴──────────┴─────────────┴──────────────────┘

notifer topics get <name>

Pobierz szczegółowe informacje o temacie:

notifer topics get alerts

Wynik:

╭─────────── Topic: alerts ───────────╮
│ Name: alerts                        │
│ Access: 🌍 Public                   │
│ Discoverable: Yes                   │
│ Messages: 1234                      │
│ Subscribers: 56                     │
│ Created: 2025-11-01 10:00           │
│                                     │
│ Description:                        │
│ System alerts and notifications     │
╰─────────────────────────────────────╯

notifer topics create <name> [OPTIONS]

Utwórz nowy temat:

notifer topics create my-topic

Opcje:

Opcja Opis
--description, -d Opis tematu
--private Ustaw temat jako prywatny
--no-discover Ukryj w przeglądaniu/odkrywaniu

Przykłady:

# Publiczny temat
notifer topics create alerts --description "System alerts"

# Prywatny temat
notifer topics create private-alerts --private --description "Internal alerts"

# Ukryty przed odkrywaniem
notifer topics create hidden-topic --no-discover

notifer topics delete <topic_id>

Usuń temat na stałe:

notifer topics delete abc123

Zostaniesz poproszony o potwierdzenie:

Permanently delete topic abc123? This cannot be undone! [y/N]: y
✓ Topic deleted: abc123


Zarządzanie kluczami API

notifer keys list

Wyświetl listę wszystkich swoich kluczy API:

notifer keys list

Wynik:

                                    API Keys
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Name       ┃ Prefix     ┃ Scopes          ┃ Requests ┃ Status    ┃ Created    ┃ Last Used  ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ ci-deploy  │ noti_abc   │ publish, topics │ 1234     │ ✓ Active  │ 2025-11-01 │ 2025-12-15 │
│ monitoring │ noti_def   │ *               │ 567      │ ✓ Active  │ 2025-11-02 │ 2025-12-14 │
│ old-key    │ noti_ghi   │ publish         │ 89       │ ✗ Revoked │ 2025-10-01 │ 2025-10-15 │
└────────────┴────────────┴─────────────────┴──────────┴───────────┴────────────┴────────────┘

notifer keys create <name> [OPTIONS]

Utwórz nowy klucz API:

notifer keys create "CI/CD Pipeline"

Opcje:

Opcja Opis
--description, -d Opis klucza
--scopes, -s Zakresy oddzielone przecinkami (domyślnie: *)
--expires Data wygaśnięcia (format ISO)

Przykłady:

# Klucz z pełnym dostępem
notifer keys create "Full Access"

# Ograniczone zakresy
notifer keys create "CI/CD" --scopes "publish,topics:read"

# Z datą wygaśnięcia
notifer keys create "Temp Key" --expires "2025-12-31T23:59:59Z"

Wynik:

╭─────────────── API Key Created ───────────────╮
│ ⚠ IMPORTANT: Save this key now - it won't    │
│ be shown again!                               │
│                                               │
│ noti_abc123def456ghi789jkl012mno345pqr        │
│                                               │
│ Name: CI/CD Pipeline                          │
│ Scopes: publish, topics:read                  │
│ Created: 2025-12-15T10:30:00                  │
╰───────────────────────────────────────────────╯

Save this key to config file? [y/N]: y
✓ Key saved to ~/.notifer.yaml

notifer keys revoke <key_id>

Unieważnij klucz API (zachowuje dla historii audytu):

notifer keys revoke abc123

notifer keys delete <key_id>

Usuń klucz API na stałe:

notifer keys delete abc123

Plik konfiguracyjny

CLI przechowuje konfigurację w ~/.notifer.yaml:

# Uwierzytelnianie (użyj jednego z poniższych)
api_key: noti_abc123def456...

# LUB tokeny JWT (z logowania)
email: user@example.com
access_token: eyJhbGciOiJIUzI1NiIs...
refresh_token: eyJhbGciOiJIUzI1NiIs...

# Domyślne opcje
defaults:
  priority: 3
  tags: []

Kolejność priorytetów

Wartości konfiguracji są rozwiązywane w tej kolejności (najwyższy priorytet pierwszy):

  1. Opcje wiersza poleceń (--api-key)
  2. Zmienne środowiskowe (NOTIFER_API_KEY)
  3. Plik konfiguracyjny (~/.notifer.yaml)
  4. Wartości domyślne

Zmienne środowiskowe

Nadpisz klucz API zmienną środowiskową:

export NOTIFER_API_KEY=noti_abc123...

notifer publish my-topic "Hello"
Zmienna Opis
NOTIFER_API_KEY Klucz API do uwierzytelniania

Przypadki użycia

Integracja CI/CD

GitHub Actions

name: Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Notifer CLI
        run: pip install notifer-cli

      - name: Deploy
        run: ./deploy.sh

      - name: Notify Success
        if: success()
        run: |
          notifer publish deployments "Deploy succeeded" \
            --title "Deploy Success" \
            --priority 4 \
            --tags "ci,deploy,success" \
            --api-key ${{ secrets.NOTIFER_API_KEY }} \
            --server https://app.notifer.io

      - name: Notify Failure
        if: failure()
        run: |
          notifer publish deployments "Deploy failed!" \
            --title "Deploy Failed" \
            --priority 5 \
            --tags "ci,deploy,error" \
            --api-key ${{ secrets.NOTIFER_API_KEY }} \
            --server https://app.notifer.io

GitLab CI

deploy:
  script:
    - pip install notifer-cli
    - ./deploy.sh
  after_script:
    - |
      if [ "$CI_JOB_STATUS" == "success" ]; then
        notifer publish deployments "Deploy succeeded" \
          --priority 4 \
          --api-key $NOTIFER_API_KEY \
          --server https://app.notifer.io
      else
        notifer publish deployments "Deploy failed!" \
          --priority 5 \
          --api-key $NOTIFER_API_KEY \
          --server https://app.notifer.io
      fi

Skrypty powłoki

Skrypt wdrożeniowy

#!/bin/bash
# deploy.sh

API_KEY="noti_abc123..."
SERVER="https://app.notifer.io"

# Powiadom o starcie
notifer publish deployments "Deploy started for $VERSION" \
  --priority 3 \
  --tags "deployment,start" \
  --api-key "$API_KEY" \
  --server "$SERVER"

# Uruchom wdrożenie
./deploy-script.sh
EXIT_CODE=$?

# Powiadom o wyniku
if [ $EXIT_CODE -eq 0 ]; then
  notifer publish deployments "Deploy succeeded!" \
    --title "Deploy Success" \
    --priority 4 \
    --tags "deployment,success" \
    --api-key "$API_KEY" \
    --server "$SERVER"
else
  notifer publish deployments "Deploy failed!" \
    --title "Deploy Failed" \
    --priority 5 \
    --tags "deployment,failure" \
    --api-key "$API_KEY" \
    --server "$SERVER"
fi

Aliasy Bash

Dodaj do ~/.bashrc lub ~/.zshrc:

# Szybki alias powiadomień
alias notify='notifer publish notifications'

# Użycie
notify "Task completed!"

# Powiadom po zakończeniu polecenia
long-running-command && notify "Success!" || notify "Failed!" --priority 5

Monitorowanie

Kolektor logów

#!/bin/bash
# Zbieraj wiadomości i zapisuj do pliku
notifer subscribe alerts,errors \
  --output /var/log/notifer-alerts.jsonl \
  --api-key "$NOTIFER_API_KEY"

Przetwarzanie wiadomości z jq

# Strumieniuj i filtruj wiadomości o wysokim priorytecie
notifer subscribe alerts --json | jq -r 'select(.priority >= 4) | .message'

# Zlicz wiadomości według tematu
notifer subscribe alerts,deployments --json | jq -s 'group_by(.topic) | map({topic: .[0].topic, count: length})'

Rozwiązywanie problemów

Problemy z połączeniem

# Przetestuj łączność z serwerem
curl https://app.notifer.io/health

# Użyj szczegółowego wyjścia do debugowania
notifer --debug publish my-topic "Test"

Problemy z uwierzytelnianiem

# Sprawdź aktualną konfigurację
notifer config show

# Zaloguj się ponownie
notifer logout
notifer login

# Lub ustaw nowy klucz API
notifer config set api-key noti_new_key_here

Typowe błędy

Błąd Rozwiązanie
Topic not found Najpierw utwórz temat: notifer topics create <name>
Unauthorized Sprawdź klucz API lub zaloguj się ponownie
Connection refused Zweryfikuj URL serwera w konfiguracji
Invalid credentials Uruchom ponownie notifer login

Następne kroki