Continue AI features and improve protocol support
This commit is contained in:
@@ -5,7 +5,6 @@ import aiohttp
|
||||
import orjson
|
||||
import requests
|
||||
from django.conf import settings
|
||||
from requests.exceptions import RequestException
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
@@ -57,12 +56,12 @@ async def download_and_encode_base64(file_url, filename, content_type):
|
||||
f"data:{content_type};filename={filename};base64,{base64_encoded}"
|
||||
)
|
||||
|
||||
except aiohttp.ClientError as e:
|
||||
except aiohttp.ClientError:
|
||||
# log.error(f"Failed to download file: {file_url}, error: {e}")
|
||||
return None
|
||||
|
||||
|
||||
async def send_message_raw(recipient_uuid, text=None, attachments=[]):
|
||||
async def send_message_raw(recipient_uuid, text=None, attachments=None):
|
||||
"""
|
||||
Sends a message using the Signal REST API, ensuring attachment links are not included in the text body.
|
||||
|
||||
@@ -84,6 +83,7 @@ async def send_message_raw(recipient_uuid, text=None, attachments=[]):
|
||||
}
|
||||
|
||||
# Asynchronously download and encode all attachments
|
||||
attachments = attachments or []
|
||||
tasks = [
|
||||
download_and_encode_base64(att["url"], att["filename"], att["content_type"])
|
||||
for att in attachments
|
||||
@@ -182,12 +182,12 @@ def download_and_encode_base64_sync(file_url, filename, content_type):
|
||||
|
||||
# Format according to Signal's expected structure
|
||||
return f"data:{content_type};filename={filename};base64,{base64_encoded}"
|
||||
except requests.RequestException as e:
|
||||
except requests.RequestException:
|
||||
# log.error(f"Failed to download file: {file_url}, error: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def send_message_raw_sync(recipient_uuid, text=None, attachments=[]):
|
||||
def send_message_raw_sync(recipient_uuid, text=None, attachments=None):
|
||||
"""
|
||||
Sends a message using the Signal REST API, ensuring attachment links are not included in the text body.
|
||||
|
||||
@@ -199,13 +199,16 @@ def send_message_raw_sync(recipient_uuid, text=None, attachments=[]):
|
||||
Returns:
|
||||
int | bool: Timestamp if successful, False otherwise.
|
||||
"""
|
||||
url = "http://signal:8080/v2/send"
|
||||
base = getattr(settings, "SIGNAL_HTTP_URL", "http://signal:8080").rstrip("/")
|
||||
url = f"{base}/v2/send"
|
||||
data = {
|
||||
"recipients": [recipient_uuid],
|
||||
"number": settings.SIGNAL_NUMBER,
|
||||
"base64_attachments": [],
|
||||
}
|
||||
|
||||
attachments = attachments or []
|
||||
|
||||
# Convert attachments to Base64
|
||||
for att in attachments:
|
||||
base64_data = download_and_encode_base64_sync(
|
||||
@@ -225,7 +228,7 @@ def send_message_raw_sync(recipient_uuid, text=None, attachments=[]):
|
||||
try:
|
||||
response = requests.post(url, json=data, timeout=10)
|
||||
response.raise_for_status()
|
||||
except requests.RequestException as e:
|
||||
except requests.RequestException:
|
||||
# log.error(f"Failed to send Signal message: {e}")
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user