Commit f3948f36 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge branch 'develop' into patch-1

parents 1e887c8f 80e7e5d5
...@@ -5,9 +5,12 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -5,9 +5,12 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased] ## [Unreleased]
### Added ### Added
- Documents can be sent by providing its contents via Psr7 stream (as opposed to passing a file path).
- Allow setting a custom Guzzle HTTP Client for requests (#511).
### Changed ### Changed
### Deprecated ### Deprecated
### Removed ### Removed
- [:exclamation:][unreleased-bc-up-download-directory] Upload and download directories are not set any more by default and must be set manually.
### Fixed ### Fixed
### Security ### Security
...@@ -24,7 +27,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -24,7 +27,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Removed ### Removed
- All examples have been moved to a [dedicated repository](https://github.com/php-telegram-bot/example-bot). - All examples have been moved to a [dedicated repository](https://github.com/php-telegram-bot/example-bot).
### Fixed ### Fixed
- [:exclamation:](https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#0440) Format of Update content type using `$update->getUpdateContent()`. - [:exclamation:][0.44.0-bc-update-content-type] Format of Update content type using `$update->getUpdateContent()`.
## [0.43.0] - 2017-04-17 ## [0.43.0] - 2017-04-17
### Added ### Added
...@@ -99,3 +102,6 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -99,3 +102,6 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Logging improvements to Botan integration. - Logging improvements to Botan integration.
### Deprecated ### Deprecated
- Move `hideKeyboard` to `removeKeyboard`. - Move `hideKeyboard` to `removeKeyboard`.
[unreleased-bc-up-download-directory]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[0.44.0-bc-update-content-type]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#update-getupdatecontent
...@@ -364,7 +364,7 @@ $results = Request::sendToActiveChats( ...@@ -364,7 +364,7 @@ $results = Request::sendToActiveChats(
true, // Send to chats (super group chat) true, // Send to chats (super group chat)
true, // Send to users (single chat) true, // Send to users (single chat)
null, // 'yyyy-mm-dd hh:mm:ss' date range from null, // 'yyyy-mm-dd hh:mm:ss' date range from
null, // 'yyyy-mm-dd hh:mm:ss' date range to null // 'yyyy-mm-dd hh:mm:ss' date range to
); );
``` ```
......
...@@ -63,8 +63,8 @@ class DebugCommand extends AdminCommand ...@@ -63,8 +63,8 @@ class DebugCommand extends AdminCommand
$debug_info = []; $debug_info = [];
$debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion()); $debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath()); $debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath() ?: '`_Not set_`');
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath()); $debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath() ?: '`_Not set_`');
// Commands paths. // Commands paths.
$debug_info[] = '*Commands paths:*'; $debug_info[] = '*Commands paths:*';
......
...@@ -104,16 +104,32 @@ class Request ...@@ -104,16 +104,32 @@ class Request
* *
* @param \Longman\TelegramBot\Telegram $telegram * @param \Longman\TelegramBot\Telegram $telegram
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function initialize(Telegram $telegram) public static function initialize(Telegram $telegram)
{ {
if (is_object($telegram)) { if (!($telegram instanceof Telegram)) {
throw new TelegramException('Invalid Telegram pointer!');
}
self::$telegram = $telegram; self::$telegram = $telegram;
self::$client = new Client(['base_uri' => self::$api_base_uri]); self::setClient(new Client(['base_uri' => self::$api_base_uri]));
} else { }
throw new TelegramException('Telegram pointer is empty!');
/**
* Set a custom Guzzle HTTP Client object
*
* @param Client $client
*
* @throws TelegramException
*/
public static function setClient(Client $client)
{
if (!($client instanceof Client)) {
throw new TelegramException('Invalid GuzzleHttp\Client pointer!');
} }
self::$client = $client;
} }
/** /**
...@@ -201,7 +217,7 @@ class Request ...@@ -201,7 +217,7 @@ class Request
//Reformat data array in multipart way if it contains a resource //Reformat data array in multipart way if it contains a resource
foreach ($data as $key => $item) { foreach ($data as $key => $item) {
$has_resource |= is_resource($item); $has_resource |= (is_resource($item) || $item instanceof \GuzzleHttp\Psr7\Stream);
$multipart[] = ['name' => $key, 'contents' => $item]; $multipart[] = ['name' => $key, 'contents' => $item];
} }
if ($has_resource) { if ($has_resource) {
...@@ -262,8 +278,12 @@ class Request ...@@ -262,8 +278,12 @@ class Request
*/ */
public static function downloadFile(File $file) public static function downloadFile(File $file)
{ {
if (empty($download_path = self::$telegram->getDownloadPath())) {
throw new TelegramException('Download path not set!');
}
$tg_file_path = $file->getFilePath(); $tg_file_path = $file->getFilePath();
$file_path = self::$telegram->getDownloadPath() . '/' . $tg_file_path; $file_path = $download_path . '/' . $tg_file_path;
$file_dir = dirname($file_path); $file_dir = dirname($file_path);
//For safety reasons, first try to create the directory, then check that it exists. //For safety reasons, first try to create the directory, then check that it exists.
......
...@@ -161,10 +161,6 @@ class Telegram ...@@ -161,10 +161,6 @@ class Telegram
$this->bot_username = $bot_username; $this->bot_username = $bot_username;
} }
//Set default download and upload path
$this->setDownloadPath(BASE_PATH . '/../Download');
$this->setUploadPath(BASE_PATH . '/../Upload');
//Add default system commands path //Add default system commands path
$this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands'); $this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment