import base64 from pathlib import Path import requests from menus import MenuMessageFormatter, Menus class SignalMessager: def __init__(self, api_url: str, user_number: str): self.api_url = api_url self.user_number = user_number @staticmethod def create_headers() -> dict[str, str]: return {"Content-Type": "application/json"} @staticmethod def create_attachment(pdf: Path): return base64.b64encode(pdf.read_bytes()) def send_message(self, message: str, pdf_file: Path, recipients: list[str]): headers = self.create_headers() attachment = self.create_attachment(pdf_file) body = { "message": message, "text_mode": "styled", "number": self.user_number, "recipients": recipients, "base64_attachments": [ f"data:application/pdf;filename=menu.pdf;base64,{attachment.decode()}" ], } requests.post(self.api_url, headers=headers, json=body)