### Install python-pushsafer Source: https://github.com/appzer/python-pushsafer/blob/master/doc/index.md Installation methods using pip or cloning the repository from GitHub. ```bash pip install python-pushsafer ``` ```bash git clone https://github.com/appzer/python-pushsafer.git cd python-pushsafer pip install . ``` -------------------------------- ### Install python-pushsafer from GitHub Source: https://github.com/appzer/python-pushsafer/blob/master/README.rst Install the library directly from the GitHub repository by cloning and then installing. ```bash git clone https://github.com/appzer/python-pushsafer.git cd python-pushsafer pip install . ``` -------------------------------- ### Install python-pushsafer using pip Source: https://github.com/appzer/python-pushsafer/blob/master/README.rst Install the library using pip for easy integration into your Python projects. ```bash pip install python-pushsafer ``` -------------------------------- ### Initialize Pushsafer Client Source: https://context7.com/appzer/python-pushsafer/llms.txt Setup the Client class using a private API key obtained from the Pushsafer dashboard. ```python from pushsafer import Client # Initialize the client with your private key client = Client("your_private_key_here") # The client is now ready to send messages print("Client initialized successfully") ``` -------------------------------- ### Send Notifications with send_message Source: https://context7.com/appzer/python-pushsafer/llms.txt Examples of sending basic, targeted, and advanced notifications using various parameters. ```python from pushsafer import Client client = Client("your_private_key") # Basic message - only the message text is required response = client.send_message("Server backup completed successfully") print(response) # Expected output: {'status': 1, 'success': 'message transmitted'} # Message with title and device targeting response = client.send_message( message="Your order #12345 has been shipped!", title="Order Update", device="a" # Send to all devices, or use specific device ID like "323" ) print(response) # Full-featured notification with all customization options response = client.send_message( message="Critical: Database connection failed", title="Server Alert", device="gs45", # Device or device group ID icon="2", # Icon number (1-176) - see Pushsafer icon list color="#FF0000", # LED/notification color in hex format sound="22", # Sound number (0-62) - see Pushsafer sound list vibration="3", # Vibration pattern (1-3) url="https://server-dashboard.example.com", urltitle="Open Dashboard", time2live="60", # Minutes until message expires (0-43200) priority="2", # Priority: -2 to 2 (-2=lowest, 2=highest) retry="60", # Retry interval in seconds for priority 2 expire="600", # Expiration in seconds for priority 2 confirm="10", # Seconds to wait for confirmation answer="1", # Enable answer feature (1=yes) answeroptions="yes|no|maybe", # Pipe-separated answer options answerforce="1" # Force answer before dismissing (1=yes) ) print(response) # Expected output: {'status': 1, 'success': 'message transmitted', 'available': 999} ``` -------------------------------- ### Send Priority Notifications with Retry and Expiration Source: https://context7.com/appzer/python-pushsafer/llms.txt This example demonstrates sending high-priority notifications (priority=2) that can be retried at intervals and expire after a set duration. Ideal for critical alerts requiring user acknowledgment. ```python from pushsafer import Client client = Client("your_private_key") # Send an emergency notification that repeats until acknowledged response = client.send_message( message="CRITICAL: Server is down! Immediate action required.", title="Emergency Alert", device="a", icon="5", color="#FF0000", sound="25", # Alarm sound vibration="3", # Strong vibration priority="2", # Emergency priority retry="60", # Retry every 60 seconds expire="3600", # Keep retrying for 1 hour confirm="30" # Wait 30 seconds for confirmation ) print(response) # The notification will repeat every 60 seconds until acknowledged or 1 hour passes ``` -------------------------------- ### Send a message using Pushsafer Client Source: https://github.com/appzer/python-pushsafer/blob/master/README.rst Initialize the Pushsafer client with a private key and send a message with various parameters. ```python from pushsafer import Client client = Client("") resp = client.send_message("Message", "Hello", "323", "1", "#FF0000", "4", "2", "https://www.pushsafer.com", "Open Pushsafer", "0", "2", "60", "600", "10", "1", "yes|no|maybe", "1", "", "", "") print(resp) ``` -------------------------------- ### Pushsafer send_message parameters Source: https://github.com/appzer/python-pushsafer/blob/master/README.rst This snippet outlines the parameters available for the send_message method, including message content, device IDs, and advanced options. ```python client.send_message( "Message", "Title", "Device or Device Group ID", "Icon", "Color", "Sound", "Vibration", "URL", "URL Title", "Time2Live", "Priority", "Retry", "Expire", "Confirm", "Answer", "AnswerOptions", "AnswerForce", "Image 1", "Image 2", "Image 3") ``` -------------------------------- ### Send Interactive Notifications with Answer Options Source: https://context7.com/appzer/python-pushsafer/llms.txt This snippet shows how to send interactive notifications that allow users to respond directly from the notification. It includes enabling the answer feature, defining options, and forcing a user response. ```python from pushsafer import Client client = Client("your_private_key") # Send an interactive notification with answer options response = client.send_message( message="Deployment request for production server. Approve?", title="Deployment Approval", device="a", icon="12", color="#0066CC", answer="1", # Enable answer feature answeroptions="Approve|Deny|Defer", # Pipe-separated options answerforce="1" # User must answer before dismissing ) print(response) # User will see buttons: [Approve] [Deny] [Defer] # Response is sent back to your Pushsafer account ``` -------------------------------- ### Send Notifications with Images Source: https://context7.com/appzer/python-pushsafer/llms.txt Attach images to notifications using base64-encoded data or direct image URLs. ```python from pushsafer import Client import base64 client = Client("your_private_key") # Read and encode an image file with open("alert_image.png", "rb") as img_file: image_data = base64.b64encode(img_file.read()).decode("utf-8") # Send notification with an attached image response = client.send_message( message="Security camera detected motion", title="Motion Alert", device="a", icon="48", picture1=f"data:image/png;base64,{image_data}" ) print(response) # Send notification with multiple images using URLs response = client.send_message( message="New photos uploaded to your gallery", title="Photo Upload", device="a", picture1="https://example.com/photo1.jpg", picture2="https://example.com/photo2.jpg", picture3="https://example.com/photo3.jpg" ) print(response) ``` -------------------------------- ### Message Parameter Reference Source: https://github.com/appzer/python-pushsafer/blob/master/doc/index.md Reference for the parameters accepted by the send_message method. ```python client.send_message( "Message", "Title", "Device or Device Group ID", "Icon", "Color", "Sound", "Vibration", "URL", "URL Title", "Time2Live", "Priority", "Retry", "Expire", "Confirm", "Answer", "AnswerOptions", "AnswerForce", "Image 1", "Image 2", "Image 3") ``` -------------------------------- ### POST send_message Source: https://context7.com/appzer/python-pushsafer/llms.txt Sends a push notification to one or more devices with various customization options. ```APIDOC ## POST send_message ### Description Sends a push notification to one or more devices. Supports customization of appearance, behavior, and rich media attachments. ### Method POST ### Parameters #### Request Body - **message** (string) - Required - The notification text content. - **title** (string) - Optional - The notification title. - **device** (string) - Optional - Device or device group ID. - **icon** (string) - Optional - Icon number (1-176). - **color** (string) - Optional - LED/notification color in hex format. - **sound** (string) - Optional - Sound number (0-62). - **vibration** (string) - Optional - Vibration pattern (1-3). - **url** (string) - Optional - Clickable URL. - **urltitle** (string) - Optional - Title for the clickable URL. - **time2live** (string) - Optional - Minutes until message expires (0-43200). - **priority** (string) - Optional - Priority level (-2 to 2). - **retry** (string) - Optional - Retry interval in seconds for priority 2. - **expire** (string) - Optional - Expiration in seconds for priority 2. - **confirm** (string) - Optional - Seconds to wait for confirmation. - **answer** (string) - Optional - Enable answer feature (1=yes). - **answeroptions** (string) - Optional - Pipe-separated answer options. - **answerforce** (string) - Optional - Force answer before dismissing (1=yes). - **picture1** (string) - Optional - Base64 encoded string or URL for the first image. - **picture2** (string) - Optional - Base64 encoded string or URL for the second image. - **picture3** (string) - Optional - Base64 encoded string or URL for the third image. ### Request Example { "message": "Critical: Database connection failed", "title": "Server Alert", "device": "gs45", "priority": "2" } ### Response #### Success Response (200) - **status** (integer) - Status code of the request. - **success** (string) - Confirmation message. - **available** (integer) - Remaining credits or availability status. #### Response Example { "status": 1, "success": "message transmitted", "available": 999 } ``` -------------------------------- ### Handle Pushsafer Message Send Errors Source: https://context7.com/appzer/python-pushsafer/llms.txt Use this snippet to catch and handle specific errors like MessageSendError for invalid parameters or PushSaferError for general API issues. It also includes a catch-all for unexpected exceptions. ```python from pushsafer import Client, MessageSendError, PushSaferError client = Client("your_private_key") try: response = client.send_message( message="Test notification", title="Test", device="invalid_device_id" ) print(f"Message sent successfully: {response}") except MessageSendError as e: print(f"Failed to send message: {e}") # Handle specific send failures (invalid key, device, etc.) except PushSaferError as e: print(f"Pushsafer error occurred: {e}") # Handle general Pushsafer errors except Exception as e: print(f"Unexpected error: {e}") # Handle network errors or other issues ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.