dmf.alerts.send_message#

dmf.alerts.send_message(text: str = '', attachment: str | Path | None = None, scheduled_time: int | datetime | timedelta | None = None) None[source]#

Sends a message using the appropriate backend, encapsulating the logic of retrieving the backend and handling attachments and scheduling.

Parameters:
  • text – The message text to send. This can be any string that you want to send as the body of the message. If no text is provided, an empty message will be sent.

  • attachment – Optional; Path to the file to attach. If provided, the file located at this path will be sent as an attachment with the message. The path can be specified as a string or a Path object.

  • scheduled_time – Optional; Time when the message should be sent. This can be specified as a datetime object or a timedelta object. If a timedelta is provided, it will be added to the current time to calculate the scheduled send time. Note that scheduled messages may not be supported by all backends.

Raises:

AlertException – If there is an error sending the message.

Examples:

Sending a simple text message:

send_message(text="Hello, this is a test message!")

Sending a message with an attachment:

send_message(text="Please see the attached document.", attachment="/path/to/document.pdf")

Scheduling a message to be sent in the future (using timedelta):

from datetime import timedelta
send_message(text="This is a scheduled message.", scheduled_time=timedelta(hours=1))