Starting receive work

This commit is contained in:
2024-04-10 19:32:57 -07:00
parent b07162e059
commit 5463ba385f

View File

@@ -4,7 +4,7 @@ User actions
import aiohttp import aiohttp
import asyncio import asyncio
from datetime import datetime from datetime import datetime, timedelta
from pathlib import Path from pathlib import Path
from pytz import timezone from pytz import timezone
from typing import TYPE_CHECKING, Optional, Union from typing import TYPE_CHECKING, Optional, Union
@@ -35,10 +35,6 @@ ASSETS_DIR = Path(__file__).parent / "assets"
# message: str # message: str
# col_media1: str # col_media1: str
async def api_request(session, params):
async with session.get(API_URL, params=parFams) as response:
return await response.json()
class Session(BaseSession[str, Contact]): class Session(BaseSession[str, Contact]):
def __init__(self, user: GatewayUser): def __init__(self, user: GatewayUser):
self.httpsession = aiohttp.ClientSession() self.httpsession = aiohttp.ClientSession()
@@ -64,9 +60,17 @@ class Session(BaseSession[str, Contact]):
return f"Failure! {json['status']}" return f"Failure! {json['status']}"
async def poll_loop(): async def poll_loop():
f = self.user.registration_form
while True: while True:
pass last_15s = datetime.now() - timedelta(seconds=15)
messages = await get_messages(last_15s)
for message in messages:
if 'col_media1' in message:
self.xmpp.send_file(file_url=message['col1_media'], legacy_message_id=message['id'])
elif 'message' in message:
self.xmpp.send_text(message['message'], legacy_msg_id=message['id'])
await asyncio.sleep(15)
# See this issue for timezone explanation https://github.com/michaelkourlas/voipms-sms-client/issues/35 # See this issue for timezone explanation https://github.com/michaelkourlas/voipms-sms-client/issues/35
async def get_messages(self, from_time: datetime): async def get_messages(self, from_time: datetime):
@@ -89,6 +93,9 @@ class Session(BaseSession[str, Contact]):
else: else:
return json['sms'] return json['sms']
# SMS doesn't care about presence
async def on_presence(resource: str, show, status: str, resources, merged_resource):
pass
async def on_file(self, chat: Contact, url: str, **_kwargs): async def on_file(self, chat: Contact, url: str, **_kwargs):
f = self.user.registration_form f = self.user.registration_form