Files
vbev.dev/.gitea/actions/telegram-message-escape/action.yaml
T
vbevdev 0dd86c53dd
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
deploy-workflow: create docker compose file
2026-07-04 01:44:33 +03:00

49 lines
1.3 KiB
YAML

name: '🧼 Telegram message escape'
description: 'Automatically escapes dots, dashes, and exclamation marks for Telegram MarkdownV2'
inputs:
message:
description: 'The raw text string to escape'
required: true
outputs:
escaped_message:
description: 'The safely escaped string ready for Telegram'
value: ${{ steps.escape.outputs.result }}
runs:
using: 'composite'
steps:
- id: escape
shell: python
env:
RAW_MESSAGE: ${{ inputs.message }}
ESCAPED_MESSAGE: $GITHUB_OUTPUT
run: |
import os
raw_text = os.environ.get("RAW_MESSAGE", "")
output_file = os.environ.get("ESCAPED_MESSAGE")
def escape_text(text):
escape_chars = ["-", ".", "!"]
for char in escape_chars:
text = text.replace(char, f"\\{char}")
return text
parts = raw_text.split("`")
processed_parts = []
for i, part in enumerate(parts):
if i % 2 == 0:
processed_parts.append(escape_text(part))
else:
processed_parts.append(f"\\`{part}\\`")
escaped_text = "".join(processed_parts)
with open(output_file, "a", encoding="utf-8") as f:
f.write("result<<EOF\n")
f.write(f"{escaped_text}\n")
f.write("EOF\n")