/**
* Send command
*
* @todo Fake response doesn't need json encoding?
*
* @param string $action
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function send($action, array $data = [])
{
self::ensureValidAction($action);
$bot_name = self::$telegram->getBotName();
if (defined('PHPUNIT_TESTSUITE')) {
$fake_response = self::generateGeneralFakeServerResponse($data);
return new ServerResponse($fake_response, $bot_name);
}
self::ensureNonEmptyData($data);
$response = json_decode(self::execute($action, $data), true);
if (null === $response) {
throw new TelegramException('Telegram returned an invalid response! Please review your bot name and API key.');
}
return new ServerResponse($response, $bot_name);
}