main: send stuff
This commit is contained in:
parent
b76741fb54
commit
864714db6d
@ -65,6 +65,14 @@ class UpdateGroupResult(BaseModel):
|
|||||||
members_added: List[str]
|
members_added: List[str]
|
||||||
members_removed: List[str]
|
members_removed: List[str]
|
||||||
|
|
||||||
|
class SendMessageSimple(BaseModel):
|
||||||
|
message: str
|
||||||
|
base64_attachments: List[str] = []
|
||||||
|
recipients: List[str]
|
||||||
|
|
||||||
|
class SendMessageResponse(BaseModel):
|
||||||
|
timestamp: str
|
||||||
|
|
||||||
def test_reaction_message():
|
def test_reaction_message():
|
||||||
data = """{
|
data = """{
|
||||||
"envelope": {
|
"envelope": {
|
||||||
|
45
main.py
45
main.py
@ -158,6 +158,17 @@ class SignalAPI:
|
|||||||
except websockets.exceptions.ConnectionClosed:
|
except websockets.exceptions.ConnectionClosed:
|
||||||
print("Websockets connection closed. Reestablishing connection.")
|
print("Websockets connection closed. Reestablishing connection.")
|
||||||
|
|
||||||
|
def send_message(self, message: SendMessageSimple) -> Result[SendMessageResponse, str]:
|
||||||
|
data = message.model_dump()
|
||||||
|
data['number'] = self.number
|
||||||
|
r = requests.post(f"{self.apiurl}/v2/send", json=data)
|
||||||
|
|
||||||
|
if r.status_code == 201:
|
||||||
|
return parse_response(SendMessageResponse, r.text)
|
||||||
|
else:
|
||||||
|
print("Failed to send message")
|
||||||
|
print(r.text)
|
||||||
|
|
||||||
|
|
||||||
class LabCleaningBot:
|
class LabCleaningBot:
|
||||||
|
|
||||||
@ -203,6 +214,10 @@ class LabCleaningBot:
|
|||||||
session.commit()
|
session.commit()
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
|
|
||||||
|
def send_to_base_group(self, message: str) -> Result[None, str]:
|
||||||
|
message = SendMessageSimple(message=message, recipients=[self.base_group])
|
||||||
|
return self.api.send_message(message)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
@ -219,9 +234,39 @@ if __name__ == "__main__":
|
|||||||
while True:
|
while True:
|
||||||
sync_result = bot.sync_members_as_active_users(session)
|
sync_result = bot.sync_members_as_active_users(session)
|
||||||
|
|
||||||
|
bot.api.update_group_members(bot.base_group, ["+4915773232355"])
|
||||||
|
|
||||||
if is_err(sync_result):
|
if is_err(sync_result):
|
||||||
print(sync_result.unwrap_err())
|
print(sync_result.unwrap_err())
|
||||||
|
|
||||||
|
for task in get_active_tasks(session, utc_now()):
|
||||||
|
reqs = task.create_additional_requests(utc_now(), session)
|
||||||
|
|
||||||
|
if is_err(reqs):
|
||||||
|
res = bot.send_to_base_group("Could not fulfill task: " + task.name)
|
||||||
|
|
||||||
|
if is_err(res):
|
||||||
|
print(res.unwrap_err())
|
||||||
|
else:
|
||||||
|
print(res.unwrap())
|
||||||
|
|
||||||
|
reqs = reqs.unwrap_err()
|
||||||
|
else:
|
||||||
|
reqs = reqs.unwrap()
|
||||||
|
|
||||||
|
for request in reqs:
|
||||||
|
message = SendMessageSimple(message=task.name, recipients=[request.user.name])
|
||||||
|
res = api.send_message(message)
|
||||||
|
|
||||||
|
if is_ok(res):
|
||||||
|
timestamp = datetime.datetime.fromtimestamp(int(res.unwrap().timestamp)/1000)
|
||||||
|
request.requested_at = timestamp
|
||||||
|
else:
|
||||||
|
print(res.unwrap_err())
|
||||||
|
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
res = bot.api.update_group_members("group.TTlKelhpUW1sUVJSU2Z2NDJpdjVWcllMTW93MTBNN2tseEtGaFkzQ1VsZz0=", groupinfo.members)
|
res = bot.api.update_group_members("group.TTlKelhpUW1sUVJSU2Z2NDJpdjVWcllMTW93MTBNN2tseEtGaFkzQ1VsZz0=", groupinfo.members)
|
||||||
|
Loading…
Reference in New Issue
Block a user