Merge pull request #79 from PR0M3TH3AN/codex/fix-nostr-related-test-failures

Add support for Nostr direct messages
This commit is contained in:
thePR0M3TH3AN
2025-07-01 08:50:41 -04:00
committed by GitHub

View File

@@ -88,19 +88,23 @@ class NostrClient:
def publish_json_to_nostr( def publish_json_to_nostr(
self, encrypted_json: bytes, to_pubkey: str | None = None self, encrypted_json: bytes, to_pubkey: str | None = None
) -> bool: ) -> bool:
"""Builds and publishes a Kind 1 text note to the configured relays.""" """Builds and publishes a Kind 1 text note or direct message."""
try: try:
content = base64.b64encode(encrypted_json).decode("utf-8") content = base64.b64encode(encrypted_json).decode("utf-8")
# Use the EventBuilder to create and sign the event if to_pubkey:
event = ( receiver = PublicKey.parse(to_pubkey)
EventBuilder.text_note(content) event_output = self.client.send_private_msg_to(
.build(self.keys.public_key()) self.relays, receiver, content
.sign_with_keys(self.keys) )
) else:
event = (
EventBuilder.text_note(content)
.build(self.keys.public_key())
.sign_with_keys(self.keys)
)
event_output = self.publish_event(event)
# Send the event using the client
event_output = self.publish_event(event)
event_id_hex = ( event_id_hex = (
event_output.id.to_hex() event_output.id.to_hex()
if hasattr(event_output, "id") if hasattr(event_output, "id")