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

Merge branch 'develop' into custom_input_for_getUpdates

parents 27b7a8c0 408cbd42
...@@ -6,10 +6,17 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -6,10 +6,17 @@ 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). - 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).
- First implementations towards Bots API 3.0.
### Changed ### Changed
- [:exclamation:][unreleased-bc-chats-params-array] `Request::sendToActiveChats` and `DB::selectChats` now accept parameters as an options array.
### 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
- ID fields are now typed with `PARAM_STR` PDO data type, to allow huge numbers.
- Message type data type for PDO corrected.
- Indexed table columns now have a fitting length.
- Take `custom_input` into account when using getUpdates method (mainly for testing). - Take `custom_input` into account when using getUpdates method (mainly for testing).
### Security ### Security
...@@ -26,7 +33,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -26,7 +33,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
...@@ -101,3 +108,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -101,3 +108,7 @@ 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-chats-params-array]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[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
...@@ -35,7 +35,7 @@ class ChatsCommand extends AdminCommand ...@@ -35,7 +35,7 @@ class ChatsCommand extends AdminCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.1.0'; protected $version = '1.2.0';
/** /**
* @var bool * @var bool
...@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand ...@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
...@@ -55,19 +55,18 @@ class ChatsCommand extends AdminCommand ...@@ -55,19 +55,18 @@ class ChatsCommand extends AdminCommand
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = trim($message->getText(true)); $text = trim($message->getText(true));
$results = DB::selectChats( $results = DB::selectChats([
true, //Select groups (group chat) 'groups' => true,
true, //Select supergroups (super group chat) 'supergroups' => true,
true, //Select users (single chat) 'channels' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range from 'users' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range to 'text' => ($text === '' || $text === '*') ? null : $text //Text to search in user/group name
null, //Specific chat_id to select ]);
($text === '' || $text === '*') ? null : $text //Text to search in user/group name
);
$user_chats = 0; $user_chats = 0;
$group_chats = 0; $group_chats = 0;
$super_group_chats = 0; $supergroup_chats = 0;
$channel_chats = 0;
if ($text === '') { if ($text === '') {
$text_back = ''; $text_back = '';
...@@ -100,24 +99,31 @@ class ChatsCommand extends AdminCommand ...@@ -100,24 +99,31 @@ class ChatsCommand extends AdminCommand
$text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL; $text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
} }
++$super_group_chats; ++$supergroup_chats;
} elseif ($chat->isGroupChat()) { } elseif ($chat->isGroupChat()) {
if ($text !== '') { if ($text !== '') {
$text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL; $text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
} }
++$group_chats; ++$group_chats;
} elseif ($chat->isChannel()) {
if ($text !== '') {
$text_back .= '- C ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$channel_chats;
} }
} }
} }
if (($user_chats + $group_chats + $super_group_chats) === 0) { if (($user_chats + $group_chats + $supergroup_chats) === 0) {
$text_back = 'No chats found..'; $text_back = 'No chats found..';
} else { } else {
$text_back .= PHP_EOL . 'Private Chats: ' . $user_chats; $text_back .= PHP_EOL . 'Private Chats: ' . $user_chats;
$text_back .= PHP_EOL . 'Groups: ' . $group_chats; $text_back .= PHP_EOL . 'Groups: ' . $group_chats;
$text_back .= PHP_EOL . 'Super Groups: ' . $super_group_chats; $text_back .= PHP_EOL . 'Super Groups: ' . $supergroup_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $super_group_chats); $text_back .= PHP_EOL . 'Channels: ' . $channel_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $supergroup_chats);
if ($text === '') { if ($text === '') {
$text_back .= PHP_EOL . PHP_EOL . 'List all chats: /' . $this->name . ' *' . PHP_EOL . 'Search for chats: /' . $this->name . ' <search string>'; $text_back .= PHP_EOL . PHP_EOL . 'List all chats: /' . $this->name . ' *' . PHP_EOL . 'Search for chats: /' . $this->name . ' <search string>';
......
...@@ -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:*';
......
...@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand ...@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.3.0'; protected $version = '1.4.0';
/** /**
* @var bool * @var bool
...@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand ...@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand
/** /**
* Execute command * Execute command
* *
* @return boolean * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
...@@ -64,11 +64,12 @@ class SendtoallCommand extends AdminCommand ...@@ -64,11 +64,12 @@ class SendtoallCommand extends AdminCommand
$results = Request::sendToActiveChats( $results = Request::sendToActiveChats(
'sendMessage', //callback function to execute (see Request.php methods) 'sendMessage', //callback function to execute (see Request.php methods)
['text' => $text], //Param to evaluate the request ['text' => $text], //Param to evaluate the request
true, //Send to groups (group chat) [
true, //Send to super groups 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,
]
); );
$total = 0; $total = 0;
......
...@@ -42,7 +42,7 @@ class WhoisCommand extends AdminCommand ...@@ -42,7 +42,7 @@ class WhoisCommand extends AdminCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.2.0'; protected $version = '1.3.0';
/** /**
* @var bool * @var bool
...@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand ...@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
...@@ -89,28 +89,25 @@ class WhoisCommand extends AdminCommand ...@@ -89,28 +89,25 @@ class WhoisCommand extends AdminCommand
$result = null; $result = null;
if (is_numeric($text)) { if (is_numeric($text)) {
$results = DB::selectChats( $results = DB::selectChats([
true, //Select groups (group chat) 'groups' => true,
true, //Select supergroups (super group chat) 'supergroups' => true,
true, //Select users (single chat) 'channels' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range from 'users' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range to 'chat_id' => $user_id, //Specific chat_id to select
$user_id //Specific chat_id to select ]);
);
if (!empty($results)) { if (!empty($results)) {
$result = reset($results); $result = reset($results);
} }
} else { } else {
$results = DB::selectChats( $results = DB::selectChats([
true, //Select groups (group chat) 'groups' => true,
true, //Select supergroups (super group chat) 'supergroups' => true,
true, //Select users (single chat) 'channels' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range from 'users' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range to 'text' => $text //Text to search in user/group name
null, //Specific chat_id to select ]);
$text //Text to search in user/group name
);
if (is_array($results) && count($results) === 1) { if (is_array($results) && count($results) === 1) {
$result = reset($results); $result = reset($results);
...@@ -119,6 +116,7 @@ class WhoisCommand extends AdminCommand ...@@ -119,6 +116,7 @@ class WhoisCommand extends AdminCommand
if (is_array($result)) { if (is_array($result)) {
$result['id'] = $result['chat_id']; $result['id'] = $result['chat_id'];
$result['username'] = $result['chat_username'];
$chat = new Chat($result); $chat = new Chat($result);
$user_id = $result['id']; $user_id = $result['id'];
......
...@@ -11,22 +11,21 @@ ...@@ -11,22 +11,21 @@
namespace Longman\TelegramBot\Commands\SystemCommands; namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/** /**
* New chat member command * New chat members command
*/ */
class NewchatmemberCommand extends SystemCommand class NewchatmembersCommand extends SystemCommand
{ {
/** /**
* @var string * @var string
*/ */
protected $name = 'Newchatmember'; protected $name = 'Newchatmembers';
/** /**
* @var string * @var string
*/ */
protected $description = 'New Chat Member'; protected $description = 'New Chat Member(s)';
/** /**
* @var string * @var string
...@@ -41,21 +40,9 @@ class NewchatmemberCommand extends SystemCommand ...@@ -41,21 +40,9 @@ class NewchatmemberCommand extends SystemCommand
*/ */
public function execute() public function execute()
{ {
$message = $this->getMessage(); //$message = $this->getMessage();
//$members = $message->getNewChatMembers();
$chat_id = $message->getChat()->getId(); return parent::execute();
$member = $message->getNewChatMember();
$text = 'Hi there!';
if (!$message->botAddedInChat()) {
$text = 'Hi ' . $member->tryMention() . '!';
}
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
} }
} }
This diff is collapsed.
...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method string getGifUrl() A valid URL for the GIF file. File size must not exceed 1MB * @method string getGifUrl() A valid URL for the GIF file. File size must not exceed 1MB
* @method int getGifWidth() Optional. Width of the GIF * @method int getGifWidth() Optional. Width of the GIF
* @method int getGifHeight() Optional. Height of the GIF * @method int getGifHeight() Optional. Height of the GIF
* @method int getGifDuration() Optional. Duration of the GIF
* @method string getThumbUrl() URL of the static thumbnail for the result (jpeg or gif) * @method string getThumbUrl() URL of the static thumbnail for the result (jpeg or gif)
* @method string getTitle() Optional. Title for the result * @method string getTitle() Optional. Title for the result
* @method string getCaption() Optional. Caption of the GIF file to be sent, 0-200 characters * @method string getCaption() Optional. Caption of the GIF file to be sent, 0-200 characters
...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method $this setGifUrl(string $gif_url) A valid URL for the GIF file. File size must not exceed 1MB * @method $this setGifUrl(string $gif_url) A valid URL for the GIF file. File size must not exceed 1MB
* @method $this setGifWidth(int $gif_width) Optional. Width of the GIF * @method $this setGifWidth(int $gif_width) Optional. Width of the GIF
* @method $this setGifHeight(int $gif_height) Optional. Height of the GIF * @method $this setGifHeight(int $gif_height) Optional. Height of the GIF
* @method $this setGifDuration(int $gif_duration) Optional. Duration of the GIF
* @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail for the result (jpeg or gif) * @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail for the result (jpeg or gif)
* @method $this setTitle(string $title) Optional. Title for the result * @method $this setTitle(string $title) Optional. Title for the result
* @method $this setCaption(string $caption) Optional. Caption of the GIF file to be sent, 0-200 characters * @method $this setCaption(string $caption) Optional. Caption of the GIF file to be sent, 0-200 characters
......
...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method string getMpeg4Url() A valid URL for the MP4 file. File size must not exceed 1MB * @method string getMpeg4Url() A valid URL for the MP4 file. File size must not exceed 1MB
* @method int getMpeg4Width() Optional. Video width * @method int getMpeg4Width() Optional. Video width
* @method int getMpeg4Height() Optional. Video height * @method int getMpeg4Height() Optional. Video height
* @method int getMpeg4Duration() Optional. Video duration
* @method string getThumbUrl() URL of the static thumbnail (jpeg or gif) for the result * @method string getThumbUrl() URL of the static thumbnail (jpeg or gif) for the result
* @method string getTitle() Optional. Title for the result * @method string getTitle() Optional. Title for the result
* @method string getCaption() Optional. Caption of the MPEG-4 file to be sent, 0-200 characters * @method string getCaption() Optional. Caption of the MPEG-4 file to be sent, 0-200 characters
...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method $this setMpeg4Url(string $mpeg4_url) A valid URL for the MP4 file. File size must not exceed 1MB * @method $this setMpeg4Url(string $mpeg4_url) A valid URL for the MP4 file. File size must not exceed 1MB
* @method $this setMpeg4Width(int $mpeg4_width) Optional. Video width * @method $this setMpeg4Width(int $mpeg4_width) Optional. Video width
* @method $this setMpeg4Height(int $mpeg4_height) Optional. Video height * @method $this setMpeg4Height(int $mpeg4_height) Optional. Video height
* @method $this setMpeg4Duration(int $mpeg4_duration) Optional. Video duration
* @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail (jpeg or gif) for the result * @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail (jpeg or gif) for the result
* @method $this setTitle(string $title) Optional. Title for the result * @method $this setTitle(string $title) Optional. Title for the result
* @method $this setCaption(string $caption) Optional. Caption of the MPEG-4 file to be sent, 0-200 characters * @method $this setCaption(string $caption) Optional. Caption of the MPEG-4 file to be sent, 0-200 characters
......
...@@ -30,11 +30,11 @@ namespace Longman\TelegramBot\Entities; ...@@ -30,11 +30,11 @@ namespace Longman\TelegramBot\Entities;
* @method Sticker getSticker() Optional. Message is a sticker, information about the sticker * @method Sticker getSticker() Optional. Message is a sticker, information about the sticker
* @method Video getVideo() Optional. Message is a video, information about the video * @method Video getVideo() Optional. Message is a video, information about the video
* @method Voice getVoice() Optional. Message is a voice message, information about the file * @method Voice getVoice() Optional. Message is a voice message, information about the file
* @method Video Note getVideoNote() Optional. Message is a video note message, information about the video
* @method string getCaption() Optional. Caption for the document, photo or video, 0-200 characters * @method string getCaption() Optional. Caption for the document, photo or video, 0-200 characters
* @method Contact getContact() Optional. Message is a shared contact, information about the contact * @method Contact getContact() Optional. Message is a shared contact, information about the contact
* @method Location getLocation() Optional. Message is a shared location, information about the location * @method Location getLocation() Optional. Message is a shared location, information about the location
* @method Venue getVenue() Optional. Message is a venue, information about the venue * @method Venue getVenue() Optional. Message is a venue, information about the venue
* @method User getNewChatMember() Optional. A new member was added to the group, information about them (this member may be the bot itself)
* @method User getLeftChatMember() Optional. A member was removed from the group, information about them (this member may be the bot itself) * @method User getLeftChatMember() Optional. A member was removed from the group, information about them (this member may be the bot itself)
* @method string getNewChatTitle() Optional. A chat title was changed to this value * @method string getNewChatTitle() Optional. A chat title was changed to this value
* @method bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted * @method bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted
...@@ -65,10 +65,11 @@ class Message extends Entity ...@@ -65,10 +65,11 @@ class Message extends Entity
'sticker' => Sticker::class, 'sticker' => Sticker::class,
'video' => Video::class, 'video' => Video::class,
'voice' => Voice::class, 'voice' => Voice::class,
'video_note' => VideoNote::class,
'contact' => Contact::class, 'contact' => Contact::class,
'location' => Location::class, 'location' => Location::class,
'venue' => Venue::class, 'venue' => Venue::class,
'new_chat_member' => User::class, 'new_chat_members' => User::class,
'left_chat_member' => User::class, 'left_chat_member' => User::class,
'new_chat_photo' => PhotoSize::class, 'new_chat_photo' => PhotoSize::class,
'pinned_message' => Message::class, 'pinned_message' => Message::class,
...@@ -85,16 +86,6 @@ class Message extends Entity ...@@ -85,16 +86,6 @@ class Message extends Entity
*/ */
public function __construct(array $data, $bot_username = '') public function __construct(array $data, $bot_username = '')
{ {
//Retro-compatibility
if (isset($data['new_chat_participant'])) {
$data['new_chat_member'] = $data['new_chat_participant'];
unset($data['new_chat_participant']);
}
if (isset($data['left_chat_participant'])) {
$data['left_chat_member'] = $data['left_chat_participant'];
unset($data['left_chat_participant']);
}
parent::__construct($data, $bot_username); parent::__construct($data, $bot_username);
} }
...@@ -128,6 +119,21 @@ class Message extends Entity ...@@ -128,6 +119,21 @@ class Message extends Entity
return empty($pretty_array) ? null : $pretty_array; return empty($pretty_array) ? null : $pretty_array;
} }
/**
* Optional. A new member(s) was added to the group, information about them (one of this members may be the bot itself)
*
* This method overrides the default getNewChatMembers method
* and returns a nice array of User objects.
*
* @return null|User[]
*/
public function getNewChatMembers()
{
$pretty_array = $this->makePrettyObjectArray(User::class, 'new_chat_members');
return empty($pretty_array) ? null : $pretty_array;
}
/** /**
* Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
* *
...@@ -221,12 +227,17 @@ class Message extends Entity ...@@ -221,12 +227,17 @@ class Message extends Entity
* Bot added in chat * Bot added in chat
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function botAddedInChat() public function botAddedInChat()
{ {
$member = $this->getNewChatMember(); foreach ($this->getNewChatMembers() as $member) {
if ($member instanceof User && $member->getUsername() === $this->getBotUsername()) {
return true;
}
}
return $member !== null && $member->getUsername() === $this->getBotUsername(); return false;
} }
/** /**
...@@ -247,7 +258,7 @@ class Message extends Entity ...@@ -247,7 +258,7 @@ class Message extends Entity
'contact', 'contact',
'location', 'location',
'venue', 'venue',
'new_chat_member', 'new_chat_members',
'left_chat_member', 'left_chat_member',
'new_chat_title', 'new_chat_title',
'new_chat_photo', 'new_chat_photo',
......
...@@ -15,15 +15,11 @@ namespace Longman\TelegramBot\Entities; ...@@ -15,15 +15,11 @@ namespace Longman\TelegramBot\Entities;
* *
* @link https://core.telegram.org/bots/api#user * @link https://core.telegram.org/bots/api#user
* *
* @property int $id Unique identifier for this user or bot
* @property string $first_name User's or bot’s first name
* @property string $last_name Optional. User's or bot’s last name
* @property string $username Optional. User's or bot’s username
*
* @method int getId() Unique identifier for this user or bot * @method int getId() Unique identifier for this user or bot
* @method string getFirstName() User's or bot’s first name * @method string getFirstName() User's or bot’s first name
* @method string getLastName() Optional. User's or bot’s last name * @method string getLastName() Optional. User's or bot’s last name
* @method string getUsername() Optional. User's or bot’s username * @method string getUsername() Optional. User's or bot’s username
* @method string getLanguageCode() Optional. User's system language
*/ */
class User extends Entity class User extends Entity
{ {
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
/**
* Class VideoNote
*
* @link https://core.telegram.org/bots/api#videonote
*
* @method string getFileId() Unique identifier for this file
* @method int getLength() Video width and height as defined by sender
* @method int getDuration() Duration of the audio in seconds as defined by sender
* @method PhotoSize getThumb() Optional. Video thumbnail as defined by sender
* @method int getFileSize() Optional. File size
*/
class VideoNote extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities()
{
return [
'thumb' => PhotoSize::class,
];
}
}
...@@ -97,6 +97,7 @@ class Request ...@@ -97,6 +97,7 @@ class Request
'editMessageCaption', 'editMessageCaption',
'editMessageReplyMarkup', 'editMessageReplyMarkup',
'getWebhookInfo', 'getWebhookInfo',
'deleteMessage',
]; ];
/** /**
...@@ -104,16 +105,32 @@ class Request ...@@ -104,16 +105,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;
} }
/** /**
...@@ -262,8 +279,12 @@ class Request ...@@ -262,8 +279,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.
...@@ -943,36 +964,28 @@ class Request ...@@ -943,36 +964,28 @@ class Request
* *
* @param string $callback_function * @param string $callback_function
* @param array $data * @param array $data
* @param boolean $send_groups * @param array $select_chats_params
* @param boolean $send_super_groups
* @param boolean $send_users
* @param string $date_from
* @param string $date_to
* *
* @return array * @return array
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function sendToActiveChats( public static function sendToActiveChats(
$callback_function, $callback_function,
array $data, array $data,
$send_groups = true, array $select_chats_params
$send_super_groups = true,
$send_users = true,
$date_from = null,
$date_to = null
) { ) {
$callback_path = __NAMESPACE__ . '\Request'; $callback_path = __NAMESPACE__ . '\Request';
if (!method_exists($callback_path, $callback_function)) { if (!method_exists($callback_path, $callback_function)) {
throw new TelegramException('Method "' . $callback_function . '" not found in class Request.'); throw new TelegramException('Method "' . $callback_function . '" not found in class Request.');
} }
$chats = DB::selectChats($send_groups, $send_super_groups, $send_users, $date_from, $date_to); $chats = DB::selectChats($select_chats_params);
$results = []; $results = [];
if (is_array($chats)) { if (is_array($chats)) {
foreach ($chats as $row) { foreach ($chats as $row) {
$data['chat_id'] = $row['chat_id']; $data['chat_id'] = $row['chat_id'];
$results[] = call_user_func_array($callback_path . '::' . $callback_function, [$data]); $results[] = call_user_func($callback_path . '::' . $callback_function, $data);
} }
} }
...@@ -1078,4 +1091,39 @@ class Request ...@@ -1078,4 +1091,39 @@ class Request
} }
} }
} }
/**
* Use this method to delete either bot's messages or messages of other users if the bot is admin of the group.
*
* On success, true is returned.
*
* @link https://core.telegram.org/bots/api#deletemessage
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function deleteMessage(array $data)
{
return self::send('deleteMessage', $data);
}
/**
* Use this method to send video notes. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendvideonote
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendVideoNote(array $data, $file = null)
{
self::assignEncodedFile($data, 'video_note', $file);
return self::send('sendVideoNote', $data);
}
} }
...@@ -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');
......
CREATE TABLE IF NOT EXISTS `user` ( CREATE TABLE IF NOT EXISTS `user` (
`id` bigint COMMENT 'Unique user identifier', `id` bigint COMMENT 'Unique user identifier',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User\'s first name', `first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User\'s last name', `last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s last name',
`username` CHAR(255) DEFAULT NULL COMMENT 'User\'s username', `username` CHAR(191) DEFAULT NULL COMMENT 'User''s username',
`language_code` CHAR(10) DEFAULT NULL COMMENT 'User''s system language',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
`updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update', `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',
...@@ -30,10 +31,8 @@ CREATE TABLE IF NOT EXISTS `user_chat` ( ...@@ -30,10 +31,8 @@ CREATE TABLE IF NOT EXISTS `user_chat` (
PRIMARY KEY (`user_id`, `chat_id`), PRIMARY KEY (`user_id`, `chat_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `inline_query` ( CREATE TABLE IF NOT EXISTS `inline_query` (
...@@ -54,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` ( ...@@ -54,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry', `id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Identifier for this result', `result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Identifier for this result',
`user_id` bigint NULL COMMENT 'Unique user identifier', `user_id` bigint NULL COMMENT 'Unique user identifier',
`location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location object, user\'s location', `location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location object, user''s location',
`inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the sent inline message', `inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the sent inline message',
`query` TEXT NOT NULL COMMENT 'The query that was used to obtain the result', `query` TEXT NOT NULL COMMENT 'The query that was used to obtain the result',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
...@@ -84,19 +83,20 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -84,19 +83,20 @@ CREATE TABLE IF NOT EXISTS `message` (
`sticker` TEXT COMMENT 'Sticker object. Message is a sticker, information about the sticker', `sticker` TEXT COMMENT 'Sticker object. Message is a sticker, information about the sticker',
`video` TEXT COMMENT 'Video object. Message is a video, information about the video', `video` TEXT COMMENT 'Video object. Message is a video, information about the video',
`voice` TEXT COMMENT 'Voice Object. Message is a Voice, information about the Voice', `voice` TEXT COMMENT 'Voice Object. Message is a Voice, information about the Voice',
`video_note` TEXT COMMENT 'VoiceNote Object. Message is a Video Note, information about the Video Note',
`contact` TEXT COMMENT 'Contact object. Message is a shared contact, information about the contact', `contact` TEXT COMMENT 'Contact object. Message is a shared contact, information about the contact',
`location` TEXT COMMENT 'Location object. Message is a shared location, information about the location', `location` TEXT COMMENT 'Location object. Message is a shared location, information about the location',
`venue` TEXT COMMENT 'Venue object. Message is a Venue, information about the Venue', `venue` TEXT COMMENT 'Venue object. Message is a Venue, information about the Venue',
`caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption', `caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
`new_chat_member` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, a new member was added to the group, information about them (this member may be bot itself)', `new_chat_members` TEXT COMMENT 'List of unique user identifiers, new member(s) were added to the group, information about them (one of these members may be the bot itself)',
`left_chat_member` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, a member was removed from the group, information about them (this member may be bot itself)', `left_chat_member` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, a member was removed from the group, information about them (this member may be the bot itself)',
`new_chat_title` CHAR(255) DEFAULT NULL COMMENT 'A chat title was changed to this value', `new_chat_title` CHAR(255) DEFAULT NULL COMMENT 'A chat title was changed to this value',
`new_chat_photo` TEXT COMMENT 'Array of PhotoSize objects. A chat photo was change to this value', `new_chat_photo` TEXT COMMENT 'Array of PhotoSize objects. A chat photo was change to this value',
`delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the chat photo was deleted', `delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the chat photo was deleted',
`group_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group has been created', `group_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group has been created',
`supergroup_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the supergroup has been created', `supergroup_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the supergroup has been created',
`channel_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the channel chat has been created', `channel_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the channel chat has been created',
`migrate_to_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate to chat identifier. The group has been migrated to a supergroup with the specified identifie', `migrate_to_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate to chat identifier. The group has been migrated to a supergroup with the specified identifier',
`migrate_from_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate from chat identifier. The supergroup has been migrated from a group with the specified identifier', `migrate_from_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate from chat identifier. The supergroup has been migrated from a group with the specified identifier',
`pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned', `pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned',
...@@ -106,7 +106,6 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -106,7 +106,6 @@ CREATE TABLE IF NOT EXISTS `message` (
KEY `forward_from_chat` (`forward_from_chat`), KEY `forward_from_chat` (`forward_from_chat`),
KEY `reply_to_chat` (`reply_to_chat`), KEY `reply_to_chat` (`reply_to_chat`),
KEY `reply_to_message` (`reply_to_message`), KEY `reply_to_message` (`reply_to_message`),
KEY `new_chat_member` (`new_chat_member`),
KEY `left_chat_member` (`left_chat_member`), KEY `left_chat_member` (`left_chat_member`),
KEY `migrate_from_chat_id` (`migrate_from_chat_id`), KEY `migrate_from_chat_id` (`migrate_from_chat_id`),
KEY `migrate_to_chat_id` (`migrate_to_chat_id`), KEY `migrate_to_chat_id` (`migrate_to_chat_id`),
...@@ -117,7 +116,6 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -117,7 +116,6 @@ CREATE TABLE IF NOT EXISTS `message` (
FOREIGN KEY (`forward_from_chat`) REFERENCES `chat` (`id`), FOREIGN KEY (`forward_from_chat`) REFERENCES `chat` (`id`),
FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES `message` (`chat_id`, `id`), FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`), FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`),
FOREIGN KEY (`new_chat_member`) REFERENCES `user` (`id`),
FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`) FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
...@@ -160,7 +158,7 @@ CREATE TABLE IF NOT EXISTS `edited_message` ( ...@@ -160,7 +158,7 @@ CREATE TABLE IF NOT EXISTS `edited_message` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `telegram_update` ( CREATE TABLE IF NOT EXISTS `telegram_update` (
`id` bigint UNSIGNED COMMENT 'Update\'s unique identifier', `id` bigint UNSIGNED COMMENT 'Update''s unique identifier',
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier', `chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier', `message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique inline query identifier', `inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique inline query identifier',
...@@ -221,4 +219,4 @@ CREATE TABLE IF NOT EXISTS `request_limiter` ( ...@@ -221,4 +219,4 @@ CREATE TABLE IF NOT EXISTS `request_limiter` (
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT charSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
ALTER TABLE `message` ADD COLUMN `new_chat_members` TEXT COMMENT 'List of unique user identifiers, new member(s) were added to the group, information about them (one of these members may be the bot itself)' AFTER `new_chat_member`;
UPDATE `message` SET `new_chat_members` = `new_chat_member`;
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