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

Use signal-cli-dbus-rest-api over abandoned signal-web-gateway. #481

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions lib/Service/Gateway/Signal/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,41 @@ public function __construct(IClientService $clientService,
*/
public function send(IUser $user, string $identifier, string $message) {
$client = $this->clientService->newClient();
$response = $client->post(
$this->config->getUrl(),
[
'body' => [
'to' => $identifier,
'message' => $message,
],
]
);
$body = $response->getBody();
$json = json_decode($body, true);
// determine type of gateway
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment necessary?

$response = $client->get($this->config->getUrl() . '/v1/about');
if ($response->getStatusCode() === 200) {
// New style gateway https://gitlab.com/morph027/signal-cli-dbus-rest-api
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment necessary?

$response = $client->post(
$this->config->getUrl() . '/v1/send/' . $identifier,
[
'json' => [ 'message' => $message ],
]
);
$body = $response->getBody();
$json = json_decode($body, true);
if ($response->getStatusCode() !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) {
$status = $response->getStatusCode();
throw new SmsTransmissionException("error reported by Signal gateway, status=$status, body=$body}");
}
} else {
// Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment necessary?

$response = $client->post(
$this->config->getUrl() . '/v1/send/' . $identifier,
[
'body' => [
'to' => $identifier,
'message' => $message,
],
'json' => [ 'message' => $message ],
]
);
$body = $response->getBody();
$json = json_decode($body, true);

if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) {
$status = $response->getStatusCode();
throw new SmsTransmissionException("error reported by Signal gateway, status=$status, body=$body}");
if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) {
$status = $response->getStatusCode();
throw new SmsTransmissionException("error reported by Signal gateway, status=$status, body=$body}");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/SetupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function startSetup(IUser $user, string $gatewayName, string $identifier)
try {
$gateway->send($user, $identifier, "$verificationNumber is your Nextcloud verification code.");
} catch (SmsTransmissionException $ex) {
throw new VerificationTransmissionException('could not send verification code');
throw new VerificationTransmissionException('could not send verification code', $ex->getCode(), $ex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Have a place of code using the 2th and 3th argument?

}

return $this->stateStorage->persist(
Expand Down