Skip to content

Commit

Permalink
feat: validate required parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
HaKkaz committed Nov 16, 2024
1 parent ea22184 commit bc69eb3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions providers/src/airflow/providers/telegram/hooks/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def send_message(self, api_params: dict) -> None:
stop=tenacity.stop_after_attempt(5),
wait=tenacity.wait_fixed(1),
)
def send_file(self, file: str, **api_params) -> None:
def send_file(self, api_params: dict) -> None:
"""
Send the file to a telegram channel or chat.
Expand All @@ -176,7 +176,13 @@ def send_file(self, file: str, **api_params) -> None:
kwargs["chat_id"] = self.chat_id
kwargs.update(api_params)

kwargs["document"] = file
if "file" not in kwargs or kwargs["file"] is None:
raise AirflowException("'file' must be provided for telegram document message")

kwargs["document"] = kwargs.pop("file") # rename 'file' to 'document'

if kwargs.get("chat_id") is None:
raise AirflowException("'chat_id' must be provided for telegram document message")

response = asyncio.run(self.connection.send_document(**kwargs))
self.log.debug(response)

0 comments on commit bc69eb3

Please sign in to comment.