Compare commits
57 Commits
db88d660cf
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ea0967216 | ||
|
|
3c121c1f2e | ||
|
|
e7a5755848 | ||
|
|
535dca65f1 | ||
|
|
7601520082 | ||
|
|
d2366e36cd | ||
|
|
190eefee83 | ||
|
|
5033c1b568 | ||
|
|
9a927d171b | ||
|
|
c1ed7f0629 | ||
|
|
3eb184ef8d | ||
|
|
e8978753e0 | ||
|
|
73032ddbf6 | ||
|
|
8bdd382865 | ||
|
|
dce8f35afd | ||
|
|
8bf063c745 | ||
|
|
6e8875ec64 | ||
|
|
ce44b8103e | ||
|
|
4caca226eb | ||
|
|
95d1d196a6 | ||
|
|
242315b7dc | ||
|
|
86b469f293 | ||
|
|
616ece8334 | ||
|
|
eccc9fcc11 | ||
|
|
0c86f5d6e9 | ||
|
|
0f68e5820b | ||
|
|
da881f4c66 | ||
|
|
55bfb03959 | ||
|
|
0e0d598b6d | ||
|
|
1050b3ca34 | ||
|
|
911c967f33 | ||
|
|
692594260e | ||
|
|
52c5d43868 | ||
|
|
a08e08aa3f | ||
|
|
6b383bd323 | ||
|
|
fd9a507b3b | ||
|
|
288b061064 | ||
|
|
760f4127ee | ||
|
|
90adf30064 | ||
|
|
1748c3fbad | ||
|
|
7e40bc125a | ||
|
|
1986895b2e | ||
|
|
8eb3c74cd2 | ||
|
|
04067a758a | ||
|
|
6aa7b222ce | ||
|
|
bd971edf91 | ||
|
|
9c28cb7a93 | ||
|
|
9a1eb86093 | ||
|
|
959fd6e8d9 | ||
|
|
986af9d158 | ||
|
|
472094ff25 | ||
|
|
4bc71a8287 | ||
|
|
6c06b3e4bd | ||
|
|
02fce37a63 | ||
|
|
f5396fe27e | ||
|
|
d6d3cd31ba | ||
|
|
a5f446cc39 |
104
action.yml
104
action.yml
@@ -1,22 +1,40 @@
|
||||
name: 'Hello World'
|
||||
description: 'Greet someone'
|
||||
name: 'Telegram Bot'
|
||||
description: 'Telegram Bot API'
|
||||
inputs:
|
||||
message:
|
||||
description: "Text"
|
||||
required: false
|
||||
default: ""
|
||||
default: ''
|
||||
caption:
|
||||
description: "Text"
|
||||
required: false
|
||||
default: |
|
||||
<a href='${{ github.event.repository.html_url }}/actions/runs/${{ github.run_number }}'>#${{ github.run_number }}</a> <b>${{ github.event.repository.name }}</b>: ${{ github.workflow }}
|
||||
on: <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
|
||||
default: ""
|
||||
default: ''
|
||||
# update:
|
||||
# description: "Update message by ID"
|
||||
# required: false
|
||||
# default: 'false'
|
||||
# delete:
|
||||
# description: "Update message by ID"
|
||||
# required: false
|
||||
# default: 'false'
|
||||
delete:
|
||||
description: "Message ID to delete"
|
||||
required: false
|
||||
default: ''
|
||||
status:
|
||||
description: "Status message"
|
||||
required: false
|
||||
default: ${{ job.status }}
|
||||
chat_id:
|
||||
description: "Chat ID"
|
||||
required: true
|
||||
@@ -25,35 +43,21 @@ inputs:
|
||||
description: "Message ID"
|
||||
required: false
|
||||
default: ${{ secrets.TELEGRAM_TOKEN }}
|
||||
who-to-greet: # id of input
|
||||
description: 'Who to greet'
|
||||
required: true
|
||||
default: 'World'
|
||||
outputs:
|
||||
message_id:
|
||||
description: "Message ID"
|
||||
value: ${{ env.TELEGRAM_MESSAGE_ID }}
|
||||
random-number:
|
||||
description: "Random number"
|
||||
value: ${{ steps.random-number-generator.outputs.random-number }}
|
||||
value: ${{ env.OUTPUT_MESSAGE_ID }}
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Set Greeting
|
||||
run: |
|
||||
echo "Hello $INPUT_WHO_TO_GREET."
|
||||
echo MESSAGE=$MESSAGE
|
||||
echo inputs.message_id==${{ inputs.message_id }}
|
||||
echo env.MESSAGE_ID=${{ env.MESSAGE_ID }}
|
||||
- name: Setup
|
||||
run: echo "OUTPUT_MESSAGE_ID=" >> $GITHUB_ENV
|
||||
shell: bash
|
||||
env:
|
||||
INPUT_WHO_TO_GREET: ${{ inputs.who-to-greet }}
|
||||
MESSAGE: ${{ inputs.message_id }}
|
||||
|
||||
- name: Random Number Generator
|
||||
id: random-number-generator
|
||||
run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
# - name: Random Number Generator
|
||||
# id: random-number-generator
|
||||
# run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
|
||||
# shell: bash
|
||||
|
||||
- name: Set GitHub Path
|
||||
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
|
||||
@@ -62,9 +66,45 @@ runs:
|
||||
GITHUB_ACTION_PATH: ${{ github.action_path }}
|
||||
|
||||
- name: Send message
|
||||
run: sendMessage ${{ inputs.bot_token }} ${{ inputs.chat_id }} ${{ inputs.message }}
|
||||
run: |
|
||||
button_url=${{ inputs.button_url }}
|
||||
STATUS=${{ inputs.status }}
|
||||
if [[ "$STATUS" == "success" ]]; then
|
||||
STATUS="✅"
|
||||
elif [[ "$STATUS" == "failure" ]]; then
|
||||
STATUS="❌"
|
||||
button_url=""
|
||||
elif [[ "$STATUS" == "cancelled" ]]; then
|
||||
STATUS="⚠️"
|
||||
button_url=""
|
||||
fi
|
||||
if [[ "$STATUS" != '' ]]; then
|
||||
STATUS="$STATUS "
|
||||
fi
|
||||
CAPTION="$STATUS${{ inputs.caption }}"
|
||||
echo "Caption: $CAPTION"
|
||||
message="${{ inputs.message }}"
|
||||
PARSED_TEXT=$(echo -e "$CAPTION$message")
|
||||
echo "PARSED_TEXT: $PARSED_TEXT"
|
||||
sendMessage "${{ inputs.bot_token }}" ${{ inputs.chat_id }} "$PARSED_TEXT" "${{ inputs.button_title }}" "$button_url"
|
||||
shell: bash
|
||||
|
||||
- name: Run goodbye.sh
|
||||
run: goodbye.sh
|
||||
- name: Delete message
|
||||
if: inputs.delete != ''
|
||||
run: deleteMessage "${{ inputs.bot_token }}" ${{ inputs.chat_id }} ${{ inputs.delete }}
|
||||
shell: bash
|
||||
|
||||
# - name: Send job status
|
||||
# if: inputs.status != ''
|
||||
# run: |
|
||||
# if [[ "${{ job.status }}" == "success" ]]; then
|
||||
# STATUS="✅"
|
||||
# elif [[ "${{ job.status }}" == "failure" ]]; then
|
||||
# STATUS="❌"
|
||||
# elif [[ "${{ job.status }}" == "cancelled" ]]; then
|
||||
# STATUS="⚠️"
|
||||
# else
|
||||
# STATUS="❓"
|
||||
# fi
|
||||
# sendMessage "${{ inputs.bot_token }}" ${{ inputs.chat_id }} "$STATUS ${{ inputs.status }}"
|
||||
# shell: bash
|
||||
7
deleteMessage
Executable file
7
deleteMessage
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
curl -s --show-error -X POST "https://api.telegram.org/bot$1/deleteMessage" \
|
||||
-d "message_id=$3" \
|
||||
-d "chat_id=$2"
|
||||
|
||||
echo "Message with ID $3 was deleted"
|
||||
@@ -1 +0,0 @@
|
||||
echo Goodbye
|
||||
55
sendMessage
55
sendMessage
@@ -1,22 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
MESSAGE=$(echo -e "$3")
|
||||
BOT_TOKEN="$1"
|
||||
CHAT_ID="$2"
|
||||
TEXT="$3"
|
||||
DOWNLOAD_TITLE="$4" # Необязательный
|
||||
DOWNLOAD_URL="$5" # Необязательный
|
||||
|
||||
echo token=$1
|
||||
echo chat_id=$2
|
||||
echo text=$3
|
||||
# Базовый JSON без reply_markup
|
||||
JSON=$(jq -nc \
|
||||
--arg chat_id "$CHAT_ID" \
|
||||
--arg text "$TEXT" \
|
||||
'{
|
||||
chat_id: $chat_id,
|
||||
text: $text,
|
||||
parse_mode: "HTML",
|
||||
link_preview_options: { "is_disabled": true }
|
||||
}')
|
||||
|
||||
response=$(curl -s -X -v POST "https://api.telegram.org/bot$1/sendMessage" \
|
||||
-d "chat_id=$2" \
|
||||
-d "parse_mode=MarkdownV2" \
|
||||
-d "link_preview_options={\"is_disabled\":true}" \
|
||||
-d "text=test: $(echo -e "$3")")
|
||||
# Если передана ссылка — добавим кнопку
|
||||
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
|
||||
|
||||
# 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
|
||||
echo "$JSON: $JSON"
|
||||
|
||||
echo "Sent message ID: $message_id"
|
||||
echo "TELEGRAM_MESSAGE_ID=$message_id" >> $GITHUB_ENV
|
||||
# Отправка запроса
|
||||
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"
|
||||
Reference in New Issue
Block a user