Skip to content

Conversation

@kriptonix
Copy link
Contributor

@kriptonix kriptonix commented Jun 11, 2024

This code adds basic functionality to read events from Nostr relay. Send request to relay, get response and close WebSocket connection. For continuous WebSocket connection code needs to be additionally upgraded.

Create new subscription and set subscription ID. I use simple code to generate random 64 character ID for subscription:

$subscription = new Subscription();
$subscriptionId = $subscription->setId();

Define as many filters as you like:

$filter1 = new Filter();
$filter1->setAuthors(<array of pubkeys>);
$filter1->setKinds(<array of kinds>);
$filter1->setLimit(<integer>);
$filter1->setSince(<timestamp integer>);
$filter1->setUntil(<timestamp integer>);
$filter1->setETag(<array of #e tags>);
$filter1->setPTag(<array of #p tags>]);
$filter2 = new Filter();
$filter2->setKinds([1]);
$filter2->setLimit(3);

Combine all filters into one array:
$filters = [$filter1, $filter2];

Create request message:
$requestMessage = new RequestMessage($subscriptionId, $filters);

Create request and send it to relay:

$request = new Request($relayUrl, $requestMessage);
$result = $request->send();

@Sebastix Sebastix self-assigned this Jun 11, 2024
@Sebastix Sebastix self-requested a review June 17, 2024 18:32
Copy link
Member

@Sebastix Sebastix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR!
My review on this is work in progress, but here are my first comments @kriptonix

This was referenced Jun 18, 2024
…f setPTag method to setLowercasePTags, changed name of setETags method to setLowercaseETags
@Sebastix Sebastix changed the base branch from main to feat/read_from_relay June 18, 2024 09:48
@Sebastix Sebastix merged commit f2713d5 into nostrver-se:feat/read_from_relay Jun 18, 2024
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

Successfully merging this pull request may close these issues.

2 participants