If you know the `file_id` of a previously uploaded file, just include it in the data array:
If you know the `file_id` of a previously uploaded file, just use it directly in the data array:
```php
$data=[
...
...
@@ -334,8 +343,18 @@ $data = [
$result=Request::sendPhoto($data);
```
*sendAudio*, *sendDocument*, *sendSticker*, *sendVideo* and *sendVoice* all work in the same way.
See *examples/Commands/ImageCommand.php* for a full example.
To send a remote photo, use the direct URL instead:
```php
$data=[
'chat_id'=>$chat_id,
'photo'=>'https://example.com/path/to/pic.jpg',
];
$result=Request::sendPhoto($data);
```
*sendAudio*, *sendDocument*, *sendSticker*, *sendVideo*, *sendVoice* and *sendVideoNote* all work in the same way, just check the [API documentation](https://core.telegram.org/bots/api#sendphoto) for the exact usage.
See the [*ImageCommand.php*][ImageCommand.php] for a full example.
Retrieve the user photo, see *src/Commands/WhoamiCommand.php* for a full example.
Retrieve the user photo, see [*WhoamiCommand.php*][WhoamiCommand.php] for a full example.
#### getFile and dowloadFile
#### getFile and downloadFile
Get the file path and download it, see *src/Commands/WhoamiCommand.php* for a full example.
Get the file path and download it, see [*WhoamiCommand.php*][WhoamiCommand.php] for a full example.
#### Send message to all active chats
To do this you have to enable the MySQL connection.
Here's an example of use:
Here's an example of use (check [`DB::selectChats()`][DB::selectChats] for parameter usage):
```php
$results=Request::sendToActiveChats(
'sendMessage',// callback function to execute (see Request.php for available methods)
['text'=>'Hey! Check out the new features!!'],// Data to pass to the request
true,// Send to chats (group chat)
true,// Send to chats (super group 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 to
);
'sendMessage',// Callback function to execute (see Request.php methods)
['text'=>'Hey! Check out the new features!!'],// Param to evaluate the request
[
'groups'=>true,
'supergroups'=>true,
'channels'=>false,
'users'=>true,
]
);
```
You can also broadcast a message to users, from the private chat with your bot. Take a look at the [admin commands](#admin-commands) below.
...
...
@@ -374,9 +394,7 @@ You can also broadcast a message to users, from the private chat with your bot.
### MySQL storage (Recommended)
If you want to save messages/users/chats for further usage
in commands, create a new database, import *structure.sql* and enable
MySQL support after object creation and BEFORE handle method:
If you want to save messages/users/chats for further usage in commands, create a new database (`utf8mb4_unicode_520_ci`), import *structure.sql* and enable MySQL support after object creation and BEFORE `handle()` method:
```php
$mysql_credentials=[
...
...
@@ -386,22 +404,25 @@ $mysql_credentials = [
'database'=>'dbname',
];
$telegram->enableMySQL($mysql_credentials);
$telegram->enableMySql($mysql_credentials);
```
You can set a custom prefix to all the tables while you are enabling MySQL: