Files
telegram-bot/sendMessage
2025-06-01 18:57:44 +03:00

48 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
BOT_TOKEN="$1"
CHAT_ID="$2"
TEXT="$3"
DOWNLOAD_TITLE="$4" # Необязательный
DOWNLOAD_URL="$5" # Необязательный
# Обработка текста с \n
PARSED_TEXT=$(echo -e $TEXT)
# Базовый JSON без reply_markup
JSON=$(jq -nc \
--arg chat_id "$CHAT_ID" \
--arg text "$PARSED_TEXT" \
'{
chat_id: $chat_id,
text: $text,
parse_mode: "HTML",
link_preview_options: { "is_disabled": true }
}')
# Если передана ссылка — добавим кнопку
if [[ -n "$DOWNLOAD_URL" ]]; then
JSON=$(echo "$JSON" | jq \
--arg text "$DOWNLOAD_TITLE" \
--arg url "$DOWNLOAD_URL" \
'. + {
reply_markup: {
inline_keyboard: [[
{ text: $text, url: $url }
]]
}
}')
fi
echo $JSON
# Отправка запроса
response=$(curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d "$JSON")
# Получаем message_id
message_id=$(echo "$response" | jq '.result.message_id')
echo "Sent message with ID: $message_id"
echo "OUTPUT_MESSAGE_ID=$message_id" >> "$GITHUB_ENV"