Skip to content

Commit d3e8a0d

Browse files
committed
Add multipart/form-data option
1 parent 0ddaa1f commit d3e8a0d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Telegram/Bot.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ public function downloadFile(string $path, string $destination, $timeout = 10) {
124124
* @param string $method The method to call.
125125
* @param array|object|null $arguments The arguments for the method.
126126
* @param int $timeout The request timeout.
127+
* @param bool $multipart Pass true to use 'multipart/form-data', false to use 'application/json'.
127128
*
128129
* @return TelegramResponse The response from the Telegram API or null on RequestException.
129130
*
130131
* @throws TelegramException If an error occurs during the request.
131132
*/
132-
protected function sendRequest(string $method, array|object|null $arguments = null, $timeout = 10): TelegramResponse
133+
protected function sendRequest(string $method, array|object|null $arguments = null, $timeout = 10, bool $multipart = false): TelegramResponse
133134
{
134135
$telegramUrl = $this->apiURL . 'bot' . $this->token . "/$method";
135136
$client = new GuzzleClient(['timeout' => $timeout]);
@@ -138,7 +139,7 @@ protected function sendRequest(string $method, array|object|null $arguments = nu
138139
$options = [];
139140

140141
if (!empty($arguments)) {
141-
$options['json'] = $arguments;
142+
$options[$multipart ? 'multipart' : 'json'] = $arguments;
142143
}
143144

144145
$response = $client->post($telegramUrl, $options);

0 commit comments

Comments
 (0)