import os
import requests
# Telegram configuration
chat_id = os.getenv('CHAT_ID')
if chat_id == "" or chat_id is None:
raise SystemExit('Variable chat_id is required. Exit.')
token = os.getenv('TOKEN')
if token == "" or token is None:
raise SystemExit('Variable token is required. Exit.')
status = os.getenv('STATUS')
# Gitea environment variables
github_workflow = os.getenv('WORKFLOW')
github_repository = os.getenv('REPOSITORY')
github_run_number = os.getenv('RUN_NUMBER')
ICON = {
"failure": "❌",
"cancelled": "⚪",
"success": "✅",
}
def get_link():
return f'https://api.telegram.org/bot{token}/sendMessage'
def send_message():
message = f'''[{github_repository}] {ICON[status]} {github_workflow}'''
parameters = {
'chat_id': chat_id,
'text': message,
'parse_mode': 'HTML',
'disable_web_page_preview': True
}
request = requests.get(get_link(), params = parameters)
request.raise_for_status()
send_message()