nostrver-se / nostr-php

PHP helper library for Nostr https://nostr-php.dev
https://nostr-php.dev
MIT License
53 stars 15 forks source link

Add publish method to interact with a single relay #9

Closed eko2one closed 1 year ago

eko2one commented 1 year ago

In accordance with nostr-tools https://github.com/nbd-wtf/nostr-tools#interacting-with-a-relay We could implement methods to interact with a relay. For websocket connection it could be used: https://github.com/Textalk/websocket-php

swentel commented 1 year ago

Totally fine with using textalk/websocket - that's currently a dependency in the Drupal module, but would love to get rid of it.

Fwiw, this is the code in the module - the check on the response should be cleaned up totally though :)

      $client = new Client($relay);
      $client->send($message);
      $response = json_decode($client->receive());
      $success = TRUE;
      $failure = '';
      if (!empty($response[3])) {
        $success = FALSE;
        $failure = $response[3];
      }
eko2one commented 1 year ago

Aight! I am on it ;)

swentel commented 1 year ago

The response from a release, once decoded, has 4 possible values, e.g, for success:

[0] => OK [1] => abf48fb42fcde52fd25bb485e084b52d600618fd56ef74ab46ee5b88dd1dcb1a [2] => 1 [3] =>

In case of failures, the error message will be in the third key, and 2 will be empty then.

eko2one commented 1 year ago

Added publish method in https://github.com/swentel/nostr-php/pull/13

swentel commented 1 year ago

Renamed the issue title, otherwise we could just go on forever in this one :)