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
```php
$data=[
$data=[
...
@@ -334,8 +343,18 @@ $data = [
...
@@ -334,8 +343,18 @@ $data = [
$result=Request::sendPhoto($data);
$result=Request::sendPhoto($data);
```
```
*sendAudio*, *sendDocument*, *sendSticker*, *sendVideo* and *sendVoice* all work in the same way.
To send a remote photo, use the direct URL instead:
See *examples/Commands/ImageCommand.php* for a full example.
```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
#### Send message to all active chats
To do this you have to enable the MySQL connection.
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
```php
$results=Request::sendToActiveChats(
$results=Request::sendToActiveChats(
'sendMessage',// callback function to execute (see Request.php for available methods)
'sendMessage',// Callback function to execute (see Request.php methods)
['text'=>'Hey! Check out the new features!!'],// Data to pass to the request
['text'=>'Hey! Check out the new features!!'],// Param to evaluate the request
true,// Send to chats (group chat)
[
true,// Send to chats (super group chat)
'groups'=>true,
true,// Send to users (single chat)
'supergroups'=>true,
null,// 'yyyy-mm-dd hh:mm:ss' date range from
'channels'=>false,
null// 'yyyy-mm-dd hh:mm:ss' date range to
'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.
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.
...
@@ -374,9 +394,7 @@ You can also broadcast a message to users, from the private chat with your bot.
### MySQL storage (Recommended)
### MySQL storage (Recommended)
If you want to save messages/users/chats for further usage
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:
in commands, create a new database, import *structure.sql* and enable
MySQL support after object creation and BEFORE handle method:
```php
```php
$mysql_credentials=[
$mysql_credentials=[
...
@@ -386,22 +404,25 @@ $mysql_credentials = [
...
@@ -386,22 +404,25 @@ $mysql_credentials = [
'database'=>'dbname',
'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:
You can set a custom prefix to all the tables while you are enabling MySQL: