add inline keyboard button
This commit is contained in:
10
action.yml
10
action.yml
@@ -11,6 +11,14 @@ inputs:
|
||||
default: |
|
||||
<a href='${{ github.event.repository.html_url }}/actions/runs/${{ github.run_number }}'>%23${{ github.run_number }}</a> <b>${{ github.event.repository.name }}</b>: ${{ github.workflow }}
|
||||
\nrunner: <a href='${{ github.server_url }}/-/admin/actions/runners'>${{ env.GITEA_RUNNER_NAME }}</a>
|
||||
button_url:
|
||||
description: "Button URL"
|
||||
required: false
|
||||
default: ''
|
||||
button_title:
|
||||
description: "Button title"
|
||||
required: false
|
||||
default: ''
|
||||
message_id:
|
||||
description: "Message ID"
|
||||
required: false
|
||||
@@ -74,7 +82,7 @@ runs:
|
||||
CAPTION="$STATUS${{ inputs.caption }}"
|
||||
echo $CAPTION
|
||||
echo "$CAPTION${{ inputs.message }}"
|
||||
sendMessage "${{ inputs.bot_token }}" ${{ inputs.chat_id }} "$CAPTION${{ inputs.message }}"
|
||||
sendMessage "${{ inputs.bot_token }}" ${{ inputs.chat_id }} "$CAPTION${{ inputs.message }}" "${{ inputs.button_title }}" "${{ inputs.button_url }}"
|
||||
shell: bash
|
||||
|
||||
- name: Delete message
|
||||
|
||||
54
sendMessage
54
sendMessage
@@ -1,16 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
response=$(curl -s -X POST "https://api.telegram.org/bot$1/sendMessage" \
|
||||
-d "chat_id=$2" \
|
||||
-d "parse_mode=HTML" \
|
||||
-d "link_preview_options={\"is_disabled\":true}" \
|
||||
-d "text=$(echo -e $3)")
|
||||
BOT_TOKEN="$1"
|
||||
CHAT_ID="$2"
|
||||
TEXT="$3"
|
||||
DOWNLOAD_TITLE="$4" # Необязательный
|
||||
DOWNLOAD_URL="$5" # Необязательный
|
||||
|
||||
# if command -v jq >/dev/null 2>&1; then
|
||||
message_id=$(echo "$response" | jq '.result.message_id')
|
||||
# else
|
||||
# message_id=$(echo "$response" | grep -o '"message_id":[0-9]*' | sed 's/"message_id"://')
|
||||
# fi
|
||||
# Обработка текста с \n
|
||||
PARSED_TEXT=$(printf "%b" "$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
|
||||
echo "OUTPUT_MESSAGE_ID=$message_id" >> "$GITHUB_ENV"
|
||||
Reference in New Issue
Block a user