1
0
telegram-action/message.py

28 lines
1.0 KiB
Python
Raw Normal View History

2023-10-20 20:00:02 +02:00
import requests
import constant
import environments
class Message:
'''A class that builds and sends messages'''
def __init__(self, envs: environments.Environment):
self.envs = envs
def __build_message(self):
'''Building message from different parts'''
message = f'''[<a href="https://git.cantorgymnasium.de/{self.envs.github_repository}/actions/runs/{self.envs.github_run_id}">{self.envs.github_repository}</a>] {constant.ICON[self.envs.status]} <b>{self.envs.github_workflow}</b>'''
return message
def send_message(self):
'''Sending message to telegram chat'''
message = self.__build_message() if self.envs.custom_message == "" else self.envs.custom_message
parameters = {
'chat_id': self.envs.chat_id,
'text': message,
'parse_mode': 'HTML',
'disable_web_page_preview': True
}
request = requests.get(self.envs.get_link(), params = parameters)
request.raise_for_status()