-
Notifications
You must be signed in to change notification settings - Fork 0
/
teleconnect.py
47 lines (36 loc) · 1.25 KB
/
teleconnect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
from nostr.event import Event, EventKind
from nostr.key import PrivateKey
from nostr.relay_manager import RelayManager
from config import nostr_privkey
def send_nostrtext(channel_text):
# Your private key (hex string)
private_key_hex = nostr_privkey
priv_key = PrivateKey.from_hex(private_key_hex)
# Your public key (hex string)
public_key_hex = priv_key.public_key.hex()
# Relay URL
relay_url = "wss://relay.damus.io"
# Create a relay manager and add a relay
relay_manager = RelayManager()
relay_manager.add_relay(relay_url)
# Connect to the relay
relay_manager.open_connections()
time.sleep(1.25) # allow time for connection to open
# Define the content of your message
# message_content = "Hello, Nostr from Python!"
# Create an event
event = Event(
public_key=public_key_hex,
content=channel_text,
created_at=int(time.time()),
kind=EventKind.TEXT_NOTE,
)
# Sign the event
event.sign(priv_key.hex())
# Publish the event
relay_manager.publish_event(event)
# Allow time for message to be sent
time.sleep(1.25)
# Close the connection
relay_manager.close_connections()