public static function execute($action, array $data = [])
{
//Fix so that the keyboard markup is a string, not an object
if (isset($data['reply_markup'])) {
$data['reply_markup'] = (string) $data['reply_markup'];
}
$request_params = self::setUpRequestParams($data);
$debug_handle = TelegramLog::getDebugLogTempStream();
$request_params['debug'] = $debug_handle;
try {
$response = self::$client->post('/bot' . self::$telegram->getApiKey() . '/' . $action, $request_params);
$result = (string) $response->getBody();
//Logging getUpdates Update
if ($action === 'getUpdates') {
TelegramLog::update($result);
}
} catch (RequestException $e) {
$result = (string) $e->getResponse()->getBody();
} finally {
//Logging verbose debug output
TelegramLog::endDebugLogTempStream("Verbose HTTP Request output:\n%s\n");
}
return $result;
}