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

Add read from relay feature #55

Merged
merged 2 commits into from
Jun 18, 2024

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

src/Request/Request.php Outdated Show resolved Hide resolved
src/Filter/Filter.php Show resolved Hide resolved
src/Filter/Filter.php Outdated Show resolved Hide resolved
src/Filter/Filter.php Outdated Show resolved Hide resolved
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.

None yet

2 participants