41 lines
2.0 KiB
Plaintext
41 lines
2.0 KiB
Plaintext
It appears that SqliteStore is no longer available directly in matrix-nio's recent versions, which means the documentation might not reflect current capabilities accurately. Here’s an alternative approach to set up a persistence layer using DefaultCryptoStore in matrix-nio for handling encryption without relying on SqliteStore.
|
||
|
||
Here’s how to set it up:
|
||
|
||
Install the Required E2E Encryption Dependencies: Make sure the encryption dependencies are installed:
|
||
|
||
bash
|
||
|
||
pip install 'matrix-nio[e2e]'
|
||
|
||
Configure DefaultCryptoStore: The DefaultCryptoStore can be used to persist encryption keys, allowing your bot to retain its encryption state across restarts. Here’s a code snippet to configure it:
|
||
|
||
python
|
||
|
||
from nio import AsyncClient, DefaultCryptoStore
|
||
import os
|
||
|
||
# Set up your bot's storage directory
|
||
store_path = "store" # Ensure this directory exists
|
||
|
||
# Initialize the AsyncClient with the DefaultCryptoStore for E2E encryption
|
||
client = AsyncClient(
|
||
"https://your.matrix.server",
|
||
"your_bot_username",
|
||
store_path=store_path
|
||
)
|
||
|
||
# Configure the client to use the default crypto store
|
||
client.crypto_store = DefaultCryptoStore(
|
||
client.user_id,
|
||
client.device_id,
|
||
store_path
|
||
)
|
||
|
||
# Now your client will store encryption keys under `store_path`
|
||
|
||
Sync and Persist Keys: After setting up, the bot should automatically save keys during communication. Make sure your store_path directory is persistent across reboots, as the stored data within it allows the bot to pick up encrypted chats seamlessly on restart.
|
||
|
||
Run the Client and Sync: To maintain encrypted communication, call client.sync_forever() or client.sync() in your main loop as usual. The DefaultCryptoStore will manage loading and saving encryption keys without needing SqliteStore.
|
||
|
||
This setup should persist encryption keys across sessions. Let me know if you encounter further issues, and I can guide you through additional configuration steps if necessary. |