Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use add_subscription? #106

Open
decentropy opened this issue Jul 14, 2023 · 6 comments
Open

How to use add_subscription? #106

decentropy opened this issue Jul 14, 2023 · 6 comments

Comments

@decentropy
Copy link

Can I call add_subscription after open_connections, or do I need to do it before like the README example?

Another question... Should I expect to get all old note/events using RelayManager.message_pool.has_event?
I'm having trouble getting any thing, the while-loop just quits. I've even tried simplifying the filter to EventKind.TEXT_NOTE.

@pleb21
Copy link

pleb21 commented Jul 28, 2023

did you make any progress on this. I'm having a hard time working with this -- which is because of my limited understanding & knowledge. But I just don't 'get' what is subscription ID - do I create it? If yes, how. All I've been able to do so far is connect to relays and post a note. I have read and re-read the readme but I still don't get it. Any help would be appreciated.

@decentropy
Copy link
Author

decentropy commented Jul 28, 2023

I wasn't able to figure it out, so I switched to https://github.com/holgern/pynostr

for subscription ID, it can be anything unique
You could import uuid and then subid = uuid.uuid1().hex

@pleb21
Copy link

pleb21 commented Jul 28, 2023

ok, thanks -- bookmarking it.

@earonesty
Copy link

seems to work fine from the examples.

@pleb21
Copy link

pleb21 commented Jul 30, 2023

tbh, I haven't tried it again after the suggestion from @decentropy - will comment here again if I run into issues. Thanks

@franzos
Copy link

franzos commented Aug 1, 2023

Can I call add_subscription after open_connections, or do I need to do it before like the README example?

Just tested this, and seems to work either before or after:

relay_manager.open_connections()
relay_manager.add_subscription(subscription_id, filters)

for subscription ID, it can be anything unique

Yes, that works fine. Here's a complete example:

# Setup filters
filters = Filters([Filter(limit=10)])

# Generate subscription
subscription_id = uuid.uuid1().hex
request = [ClientMessageType.REQUEST, subscription_id]
request.extend(filters.to_json_array())

relay_manager = RelayManager()
relay_manager.add_relay("wss://nostr-pub.wellorder.net")
relay_manager.add_relay("wss://relay.damus.io")
relay_manager.add_relay("wss://nostr.wine")
relay_manager.add_relay("wss://nostr.rocks")
relay_manager.add_subscription(subscription_id, filters)
relay_manager.open_connections()

Should I expect to get all old note/events using RelayManager.message_pool.has_event?

I believe it's whatever the relay returns, based on your filters. So in theory yes - all old events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants