@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | 'name' => 'Signal', |
34 | 34 | 'instructions' => 'The gateway can send authentication to your Signal mobile and deskop app.', |
35 | 35 | 'fields' => [ |
36 | - ['field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000'], |
|
37 | - ['field' => 'account', 'prompt' => 'Please enter the account (phone-number) of the sending signal account (leave blank if a phone-number is not required):', 'default' => ''], |
|
36 | + [ 'field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000' ], |
|
37 | + [ 'field' => 'account', 'prompt' => 'Please enter the account (phone-number) of the sending signal account (leave blank if a phone-number is not required):', 'default' => '' ], |
|
38 | 38 | ], |
39 | 39 | ]; |
40 | 40 | |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | parent::__construct($appConfig); |
48 | 48 | } |
49 | 49 | |
50 | - #[\Override] |
|
51 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
50 | + #[\Override ] |
|
51 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
52 | 52 | $client = $this->clientService->newClient(); |
53 | 53 | // determine type of gateway |
54 | 54 | |
55 | 55 | // test for native signal-cli JSON RPC. |
56 | 56 | $response = $client->post( |
57 | - $this->getUrl() . '/api/v1/rpc', |
|
57 | + $this->getUrl().'/api/v1/rpc', |
|
58 | 58 | [ |
59 | 59 | 'http_errors' => false, |
60 | 60 | 'json' => [ |
61 | 61 | 'jsonrpc' => '2.0', |
62 | 62 | 'method' => 'version', |
63 | - 'id' => 'version_' . $this->timeFactory->getTime(), |
|
63 | + 'id' => 'version_'.$this->timeFactory->getTime(), |
|
64 | 64 | ], |
65 | 65 | ]); |
66 | 66 | if ($response->getStatusCode() === 200 || $response->getStatusCode() === 201) { |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | 'account' => $this->getAccount(), // mandatory for native RPC API |
77 | 77 | ]; |
78 | 78 | $response = $response = $client->post( |
79 | - $this->getUrl() . '/api/v1/rpc', |
|
79 | + $this->getUrl().'/api/v1/rpc', |
|
80 | 80 | [ |
81 | 81 | 'json' => [ |
82 | 82 | 'jsonrpc' => '2.0', |
83 | 83 | 'method' => 'send', |
84 | - 'id' => 'code_' . $this->timeFactory->getTime(), |
|
84 | + 'id' => 'code_'.$this->timeFactory->getTime(), |
|
85 | 85 | 'params' => $params, |
86 | 86 | ], |
87 | 87 | ]); |
@@ -89,19 +89,19 @@ discard block |
||
89 | 89 | $json = json_decode($body, true); |
90 | 90 | $statusCode = $response->getStatusCode(); |
91 | 91 | // The 201 "created" is probably a bug. |
92 | - if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json['jsonrpc'] ?? null) != '2.0' || !isset($json['result']['timestamp'])) { |
|
92 | + if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json[ 'jsonrpc' ] ?? null) != '2.0' || !isset($json[ 'result' ][ 'timestamp' ])) { |
|
93 | 93 | throw new MessageTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}"); |
94 | 94 | } |
95 | 95 | } else { |
96 | 96 | // Try gateway in the style of https://gitlab.com/morph027/signal-cli-dbus-rest-api |
97 | - $response = $client->get($this->getUrl() . '/v1/about'); |
|
97 | + $response = $client->get($this->getUrl().'/v1/about'); |
|
98 | 98 | if ($response->getStatusCode() === 200) { |
99 | 99 | // Not so "ńew style" gateway, see |
100 | 100 | // https://gitlab.com/morph027/signal-cli-dbus-rest-api |
101 | 101 | // https://gitlab.com/morph027/python-signal-cli-rest-api |
102 | 102 | // https://github.com/bbernhard/signal-cli-rest-api |
103 | 103 | $response = $client->post( |
104 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
104 | + $this->getUrl().'/v1/send/'.$identifier, |
|
105 | 105 | [ |
106 | 106 | 'json' => [ 'message' => $message ], |
107 | 107 | ] |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | $body = (string)$response->getBody(); |
110 | 110 | $json = json_decode($body, true); |
111 | 111 | $status = $response->getStatusCode(); |
112 | - if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) { |
|
112 | + if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) { |
|
113 | 113 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
114 | 114 | } |
115 | 115 | } else { |
116 | 116 | // Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway |
117 | 117 | $response = $client->post( |
118 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
118 | + $this->getUrl().'/v1/send/'.$identifier, |
|
119 | 119 | [ |
120 | 120 | 'body' => [ |
121 | 121 | 'to' => $identifier, |
@@ -128,23 +128,23 @@ discard block |
||
128 | 128 | $json = json_decode($body, true); |
129 | 129 | |
130 | 130 | $status = $response->getStatusCode(); |
131 | - if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) { |
|
131 | + if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) { |
|
132 | 132 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - #[\Override] |
|
138 | + #[\Override ] |
|
139 | 139 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
140 | 140 | $helper = new QuestionHelper(); |
141 | - $urlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'], self::SCHEMA['fields'][0]['default']); |
|
141 | + $urlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 0 ][ 'default' ]); |
|
142 | 142 | $url = $helper->ask($input, $output, $urlQuestion); |
143 | 143 | $output->writeln("Using $url."); |
144 | 144 | |
145 | 145 | $this->setUrl($url); |
146 | 146 | |
147 | - $accountQuestion = new Question(self::SCHEMA['fields'][1]['prompt'], self::SCHEMA['fields'][1]['default']); |
|
147 | + $accountQuestion = new Question(self::SCHEMA[ 'fields' ][ 1 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 1 ][ 'default' ]); |
|
148 | 148 | $account = $helper->ask($input, $output, $accountQuestion); |
149 | 149 | if ($account == '') { |
150 | 150 | $account = SignalConfig::ACCOUNT_UNNECESSARY; |