-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-command.sh
More file actions
executable file
·65 lines (50 loc) · 2.63 KB
/
api-command.sh
File metadata and controls
executable file
·65 lines (50 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
#
# Примеры использования команды `express-botx api`.
#
# Использование:
#
# PATH=./dist:$PATH \
# OPTS="--config config-local.yaml --bot=devops-bot" \
# CHAT=express-botx-development \
# examples/scripts/api-command.sh
#
# Переменные:
# OPTS — флаги подключения (конфиг, бот, хост и т.д.)
# CHAT — алиас чата из конфига или UUID
#
set -euo pipefail
set -x
# ── Резолвим алиас чата в UUID ──────────────────────────────────────────────
CHAT_UUID=$(express-botx chats info $OPTS --chat-id="$CHAT" --format json \
| grep -o '"group_chat_id": *"[^"]*"' | cut -d'"' -f4)
# ── Получить список чатов бота ───────────────────────────────────────────────
express-botx api $OPTS /api/v3/botx/chats/list
# ── Фильтрация ответа через jq (-q) ─────────────────────────────────────────
express-botx api $OPTS /api/v3/botx/chats/list -q '.result[].name'
# ── Показать заголовки ответа (-i) ───────────────────────────────────────────
express-botx api $OPTS -i /api/v3/botx/chats/list
# ── Типизированные поля: -f (строки) и -F (bool, number) ────────────────────
express-botx api $OPTS -X POST /api/v3/botx/chats/stealth_set \
-f group_chat_id="$CHAT_UUID" \
-F burn_in=60 \
-F stealth=true
# ── Отправить уведомление в чат (--input файл, raw JSON) ────────────────────
PAYLOAD=$(mktemp)
cat > "$PAYLOAD" <<JSON
{
"group_chat_id": "$CHAT_UUID",
"notification": {
"status": "ok",
"body": "test from api command ($(date +%H:%M:%S))"
}
}
JSON
express-botx api $OPTS -X POST /api/v4/botx/notifications/direct \
--input "$PAYLOAD" -H 'Content-Type: application/json'
rm -f "$PAYLOAD"
# ── Создать чат (закомментировано — создаёт реальный чат, удалить через API нельзя)
#
# echo '{"name":"test","chat_type":"group_chat","members":["<USER-HUID>"]}' \
# | express-botx api $OPTS -X POST /api/v3/botx/chats/create \
# --input - -H 'Content-Type: application/json'