Skip to content
Permalink
Browse files

add function sendAlbum

  • Loading branch information...
Anisan committed Nov 28, 2018
1 parent fc618d3 commit 8cc11a500e5d65d56b80fd0972515bea0682eb0a
Showing with 102 additions and 2 deletions.
  1. +44 −1 modules/telegram/Telegram.php
  2. +58 −1 modules/telegram/telegram.class.php
@@ -648,7 +648,50 @@ public function sendLocation(array $content)
{
return $this->endpoint('sendLocation', $content);
}
/// Send Media Group
/**
* Use this method to send a group of photos or videos as an album. On success, an array of the sent <a href="https://core.telegram.org/bots/api#message">Messages</a> is returned.<br/>Values inside $content:<br/>
* <table>
* <tr>
* <td><strong>Parameters</strong></td>
* <td><strong>Type</strong></td>
* <td><strong>Required</strong></td>
* <td><strong>Description</strong></td>
* </tr>
* <tr>
* <td>chat_id</td>
* <td>Integer or String</td>
* <td>Yes</td>
* <td>Unique identifier for the target chat or username of the target channel (in the format \c \@channelusername)</td>
* </tr>
* <tr>
* <td>media</td>
* <td>Array of <a href="https://core.telegram.org/bots/api#inputmedia">InputMedia</a></td>
* <td>Yes</td>
* <td>A JSON-serialized array describing photos and videos to be sent, must include 2–10 items</td>
* </tr>
* <tr>
* <td>disable_notification</td>
* <td>Boolean</td>
* <td>Optional</td>
* <td>Sends the messages <a href="https://telegram.org/blog/channels-2-0#silent-messages">silently</a>. Users will receive a notification with no sound.</td>
* </tr>
* <tr>
* <td>reply_to_message_id</td>
* <td>Integer</td>
* <td>Optional</td>
* <td>If the messages are a reply, ID of the original message</td>
* </tr>
* </table>
* \param $content the request parameters as array
* \return the JSON Telegram's reply.
*/
public function sendMediaGroup(array $content)
{
return $this->endpoint('sendMediaGroup', $content);
}
/// Send Venue
/**
@@ -782,7 +782,64 @@ function sendVideoToAdmin($video_path, $message = '', $key = NULL) {
function sendVideoToAll($video_path, $message = '', $key = NULL) {
$this->sendVideoTo("", $video_path, $message, $key);
}
///send album
function sendAlbum($user_id, $image_paths, $message = '', $keyboard = '') {
if (count($image_paths) == 1)
{
$this->sendImage($user_id, $image_paths[0], $message, $keyboard);
return;
}
$photos = array();
$content = array(
'chat_id' => $user_id
);
foreach($image_paths as $image) {
$img = curl_file_create($image, 'image/png');
$photo = array();
$photo['caption'] = $message;
$photo['type'] = 'photo';
$photo['parse_mode'] = 'HTML';
$photo['media'] = 'attach://'.basename($image);//$img;
$photos[]=$photo;
$content[basename($image)]=$img;
}
$content['media'] = json_encode($photos,true);
$res = $this->telegramBot->sendMediaGroup($content);
$this->debug($res);
return $res;
}
function sendAlbumTo($where, $image_paths, $message = '', array $key = NULL) {
$photos = array();
$content = array();
foreach($image_paths as $image) {
$img = curl_file_create($image, 'image/png');
$photo = array();
$photo['caption'] = $message;
$photo['type'] = 'photo';
$photo['parse_mode'] = 'HTML';
$photo['media'] = 'attach://'.basename($image);
$photos[]=$photo;
$content[basename($image)]=$img;
}
$content['media'] = json_encode($photos,true);
$users = $this->getUsers($where);
foreach($users as $user) {
$user_id = $user['USER_ID'];
$content['chat_id'] = $user_id;
$res = $this->telegramBot->sendMediaGroup($content);
$this->debug($res);
}
}
function sendAlbumToUser($user_id, $image_paths, $message = '', $key = NULL) {
$this->sendAlbumTo('(USER_ID="' . DBSafe($user_id) . '" OR NAME LIKE "' . DBSafe($user_id) . '")', $image_paths, $message, $key);
}
function sendAlbumToAdmin($image_paths, $message = '', $key = NULL) {
$this->sendAlbumTo("ADMIN=1", $image_paths, $message, $key);
}
function sendAlbumToAll($image_paths, $message = '', $key = NULL) {
$this->sendAlbumTo("", $image_paths, $message, $key);
}
//
function sendFile($user_id, $file_path, $message = '', $keyboard = '') {
$file = curl_file_create($file_path);
$content = array(

0 comments on commit 8cc11a5

Please sign in to comment.
You can’t perform that action at this time.