mirror of
https://github.com/status-im/status-python-sdk.git
synced 2026-08-30 21:51:14 +00:00
bot: Real time contact requests
- Related to https://github.com/status-im/status-python-sdk/issues/32
This commit is contained in:
+21
-1
@@ -519,7 +519,6 @@ Listen for new incoming messages **in real time**. This method yields raw messag
|
||||
|
||||
```python
|
||||
from status_sdk import Account
|
||||
import datetime
|
||||
# For terminal readability only
|
||||
from rich import print as rprint
|
||||
from rich.pretty import Pretty
|
||||
@@ -537,6 +536,27 @@ for msg in account.listen_messages():
|
||||
|
||||
**Note**: If you receive multiple messages at once, `contacts` and `chats` will grow.
|
||||
|
||||
#### `listen_contact_requests()`
|
||||
|
||||
Listen for incoming contact requests **in real time**.
|
||||
|
||||
```python
|
||||
from status_sdk import Account
|
||||
# For terminal readability only
|
||||
from rich import print as rprint
|
||||
from rich.pretty import Pretty
|
||||
|
||||
account = Account()
|
||||
params = {
|
||||
"name": "status-app-bot",
|
||||
"password": "SNTPUMP"
|
||||
}
|
||||
account.login(**params)
|
||||
|
||||
for request in account.listen_contact_requests():
|
||||
rprint(Pretty(request))
|
||||
```
|
||||
|
||||
#### `add_contact(public_key, display_name=None)`
|
||||
|
||||
Send a contact request or approve an existing contact request. The mode depends on how the contact shows up in [`contacts`](./account.md#contacts). Best practice would be to look at the the following [`contacts`](./account.md#contacts) keys:
|
||||
|
||||
@@ -695,6 +695,16 @@ class Account:
|
||||
self.logger.warning(f"Could not delete Message {id}... {error.get('message')}")
|
||||
return not bool(error)
|
||||
|
||||
def listen_contact_requests(self) -> Generator:
|
||||
"""
|
||||
Listen for new contact requests. Can be used for real time processing.
|
||||
"""
|
||||
for message in self.signal.listen("local-notifications"):
|
||||
event: dict = message.get("event", {})
|
||||
category = event.get("category")
|
||||
if category == "contactRequest":
|
||||
yield message
|
||||
|
||||
def listen_messages(self) -> Generator:
|
||||
"""
|
||||
Listen for new **RAW** messages continuously. Can be used for real time processing.
|
||||
|
||||
Reference in New Issue
Block a user