Starting receive work
This commit is contained in:
21
session.py
21
session.py
@@ -4,7 +4,7 @@ User actions
|
||||
|
||||
import aiohttp
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from pytz import timezone
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
@@ -35,10 +35,6 @@ ASSETS_DIR = Path(__file__).parent / "assets"
|
||||
# message: 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]):
|
||||
def __init__(self, user: GatewayUser):
|
||||
self.httpsession = aiohttp.ClientSession()
|
||||
@@ -64,9 +60,17 @@ class Session(BaseSession[str, Contact]):
|
||||
return f"Failure! {json['status']}"
|
||||
|
||||
async def poll_loop():
|
||||
f = self.user.registration_form
|
||||
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
|
||||
async def get_messages(self, from_time: datetime):
|
||||
@@ -89,6 +93,9 @@ class Session(BaseSession[str, Contact]):
|
||||
else:
|
||||
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):
|
||||
f = self.user.registration_form
|
||||
|
||||
Reference in New Issue
Block a user