diff --git a/src/ViberDriver.php b/src/ViberDriver.php index 2b9b577..0e47782 100644 --- a/src/ViberDriver.php +++ b/src/ViberDriver.php @@ -2,6 +2,7 @@ namespace TheArdent\Drivers\Viber; +use GuzzleHttp\Client; use JsonSerializable; use BotMan\BotMan\Interfaces\DriverEventInterface; use Illuminate\Support\Collection; @@ -199,8 +200,8 @@ protected function convertQuestion(Question $question): array $keyboard = new KeyboardTemplate($question->getText()); foreach ($actions as $action) { $text = $action['text']; - $actionType = $action['additional']['url'] ? 'open-url' : 'reply'; - $actionBody = $action['additional']['url'] ?? $action['value'] ?? $action['text']; + $actionType = optional($action['additional'])['url'] ? 'open-url' : 'reply'; + $actionBody = optional($action['additional'])['url'] ?? $action['value'] ?? $action['text']; $silent = isset($action['additional']['url']); $keyboard->addButton($text, $actionType, $actionBody, 'regular', null, 6, $silent); } @@ -317,12 +318,18 @@ public function getUser(IncomingMessage $matchingMessage): User $user = null; - $response = $this->sendRequest( - self::API_ENDPOINT . 'get_user_details', - ['id' => $personId], - $matchingMessage - ); - $responseData = json_decode($response->getContent(), true); + $client = new Client(); + + $response = $client->request('POST',self::API_ENDPOINT . 'get_user_details', [ + 'headers' => [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'X-Viber-Auth-Token' => $this->config->get('token'), + ], + 'json' => ['id' => $personId] + ]); + + $responseData = json_decode($response->getBody()->getContents(), true); if (($responseData['status'] ?? null) === 0 && ($responseData['user'] ?? null)) { $user = $responseData['user']; @@ -338,7 +345,7 @@ public function getUser(IncomingMessage $matchingMessage): User $nameArray[0] ?? '', $nameArray[1] ?? '', $name, - $user + $responseData ); }