-
Notifications
You must be signed in to change notification settings - Fork 63
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
$response = $client->get($this->config->getUrl() . '/v1/about'); | ||
if ($response->getStatusCode() === 200) { | ||
// New style gateway https://gitlab.com/morph027/signal-cli-dbus-rest-api | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}"); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment necessary?