From 917fb03d4289e133e6d2a6ba8ecebc176266a456 Mon Sep 17 00:00:00 2001 From: Henrik Neef Date: Sun, 16 Nov 2025 12:59:59 +0100 Subject: [PATCH] Dateien nach ".gitea/workflows" hochladen --- .gitea/workflows/test-telegram.yml | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .gitea/workflows/test-telegram.yml diff --git a/.gitea/workflows/test-telegram.yml b/.gitea/workflows/test-telegram.yml new file mode 100644 index 0000000..1ab1fb3 --- /dev/null +++ b/.gitea/workflows/test-telegram.yml @@ -0,0 +1,93 @@ +name: Test Telegram Send + +on: + workflow_dispatch: + inputs: + test_message: + description: 'Test message to send' + required: false + default: 'Test message from Gitea Actions' + +jobs: + test-telegram: + runs-on: ubuntu-latest + + steps: + - name: Test Telegram Bot Connection + env: + BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + CHAT_ID_1: ${{ secrets.TELEGRAM_CHAT_ID_1_GROUP }} + run: | + echo "=== Telegram Configuration Check ===" + echo "Bot token configured: $([ -n "$BOT_TOKEN" ] && echo 'YES' || echo 'NO')" + echo "Bot token length: ${#BOT_TOKEN}" + echo "Chat ID configured: $([ -n "$CHAT_ID_1" ] && echo 'YES' || echo 'NO')" + echo "Chat ID value: ${CHAT_ID_1}" + echo "====================================" + + # Test 1: Check if bot token is valid + echo "" + echo "Test 1: Checking bot token validity..." + BOT_INFO=$(curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getMe") + echo "Bot info response: $BOT_INFO" + + if echo "$BOT_INFO" | grep -q '"ok":true'; then + echo "✓ Bot token is valid!" + BOT_USERNAME=$(echo "$BOT_INFO" | grep -o '"username":"[^"]*"' | cut -d'"' -f4) + echo " Bot username: @${BOT_USERNAME}" + else + echo "✗ Bot token is invalid or there's an API issue" + echo " Please check your TELEGRAM_BOT_TOKEN secret" + exit 1 + fi + + # Test 2: Send a simple text message + echo "" + echo "Test 2: Sending text message..." + TEXT_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" \ + -d "chat_id=${CHAT_ID_1}" \ + -d "text=${{ github.event.inputs.test_message }}" \ + "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage") + + HTTP_CODE=$(echo "$TEXT_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2) + RESPONSE_BODY=$(echo "$TEXT_RESPONSE" | sed '/HTTP_CODE:/d') + + echo "HTTP Status: $HTTP_CODE" + echo "Response: $RESPONSE_BODY" + + if [ "$HTTP_CODE" = "200" ]; then + echo "✓ Text message sent successfully!" + else + echo "✗ Failed to send text message" + echo " Common issues:" + echo " - Chat ID is incorrect (should be negative for groups: -1001234567890)" + echo " - Bot is not a member of the group/channel" + echo " - Bot doesn't have permission to send messages" + exit 1 + fi + + # Test 3: Create and send a test file + echo "" + echo "Test 3: Sending test file..." + echo "This is a test file from Gitea Actions" > test_file.txt + + FILE_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" \ + -F document=@"test_file.txt" \ + -F caption="Test file upload from Gitea Actions" \ + "https://api.telegram.org/bot${BOT_TOKEN}/sendDocument?chat_id=${CHAT_ID_1}") + + HTTP_CODE=$(echo "$FILE_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2) + RESPONSE_BODY=$(echo "$FILE_RESPONSE" | sed '/HTTP_CODE:/d') + + echo "HTTP Status: $HTTP_CODE" + echo "Response: $RESPONSE_BODY" + + if [ "$HTTP_CODE" = "200" ]; then + echo "✓ File sent successfully!" + else + echo "✗ Failed to send file" + exit 1 + fi + + echo "" + echo "=== All tests passed! ==="