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

Merge pull request #512 from jacklul/api_3.0_basic_changes

Basic API 3.0 changes
parents 195910c5 d21f6e9d
......@@ -7,6 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Added
- 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
- [:exclamation:][unreleased-bc-chats-params-array] `Request::sendToActiveChats` and `DB::selectChats` now accept parameters as an options array.
### Deprecated
......
......@@ -11,22 +11,21 @@
namespace Longman\TelegramBot\Commands\SystemCommands;
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
*/
protected $name = 'Newchatmember';
protected $name = 'Newchatmembers';
/**
* @var string
*/
protected $description = 'New Chat Member';
protected $description = 'New Chat Member(s)';
/**
* @var string
......@@ -41,21 +40,9 @@ class NewchatmemberCommand extends SystemCommand
*/
public function execute()
{
$message = $this->getMessage();
//$message = $this->getMessage();
//$members = $message->getNewChatMembers();
$chat_id = $message->getChat()->getId();
$member = $message->getNewChatMember();
$text = 'Hi there!';
if (!$message->botAddedInChat()) {
$text = 'Hi ' . $member->tryMention() . '!';
}
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
return parent::execute();
}
}
......@@ -357,28 +357,31 @@ class DB
return false;
}
$user_id = $user->getId();
$username = $user->getUsername();
$first_name = $user->getFirstName();
$last_name = $user->getLastName();
$user_id = $user->getId();
$username = $user->getUsername();
$first_name = $user->getFirstName();
$last_name = $user->getLastName();
$language_code = $user->getLanguageCode();
try {
$sth = self::$pdo->prepare('
INSERT INTO `' . TB_USER . '`
(`id`, `username`, `first_name`, `last_name`, `created_at`, `updated_at`)
(`id`, `username`, `first_name`, `last_name`, `language_code`, `created_at`, `updated_at`)
VALUES
(:id, :username, :first_name, :last_name, :created_at, :updated_at)
(:id, :username, :first_name, :last_name, :language_code, :created_at, :updated_at)
ON DUPLICATE KEY UPDATE
`username` = VALUES(`username`),
`first_name` = VALUES(`first_name`),
`last_name` = VALUES(`last_name`),
`updated_at` = VALUES(`updated_at`)
`username` = VALUES(`username`),
`first_name` = VALUES(`first_name`),
`last_name` = VALUES(`last_name`),
`language_code` = VALUES(`language_code`),
`updated_at` = VALUES(`updated_at`)
');
$sth->bindParam(':id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':username', $username, PDO::PARAM_STR, 255);
$sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255);
$sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255);
$sth->bindParam(':language_code', $language_code, PDO::PARAM_STR, 10);
$sth->bindParam(':created_at', $date, PDO::PARAM_STR);
$sth->bindParam(':updated_at', $date, PDO::PARAM_STR);
......@@ -773,9 +776,9 @@ class DB
$forward_from_message_id = $message->getForwardFromMessageId();
$photo = self::entitiesArrayToJson($message->getPhoto(), '');
$entities = self::entitiesArrayToJson($message->getEntities(), null);
$new_chat_member = $message->getNewChatMember();
$new_chat_photo = self::entitiesArrayToJson($message->getNewChatPhoto(), '');
$new_chat_members = $message->getNewChatMembers();
$left_chat_member = $message->getLeftChatMember();
$new_chat_photo = self::entitiesArrayToJson($message->getNewChatPhoto(), '');
$migrate_to_chat_id = $message->getMigrateToChatId();
//Insert chat, update chat id in case it migrated
......@@ -800,10 +803,16 @@ class DB
}
//New and left chat member
if ($new_chat_member instanceof User) {
//Insert the new chat user
self::insertUser($new_chat_member, $date, $chat);
$new_chat_member = $new_chat_member->getId();
if (!empty($new_chat_members)) {
$new_chat_members_ids = [];
foreach ($new_chat_members as $new_chat_member) {
if ($new_chat_member instanceof User) {
//Insert the new chat user
self::insertUser($new_chat_member, $date, $chat);
$new_chat_members_ids[] = $new_chat_member->getId();
}
}
$new_chat_members_ids = implode(',', $new_chat_members_ids);
} elseif ($left_chat_member instanceof User) {
//Insert the left chat user
self::insertUser($left_chat_member, $date, $chat);
......@@ -816,16 +825,16 @@ class DB
(
`id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
`forward_date`, `reply_to_chat`, `reply_to_message`, `text`, `entities`, `audio`, `document`,
`photo`, `sticker`, `video`, `voice`, `caption`, `contact`,
`location`, `venue`, `new_chat_member`, `left_chat_member`,
`photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
`location`, `venue`, `new_chat_members`, `left_chat_member`,
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_chat_created`,
`migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`
) VALUES (
:message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
:forward_date, :reply_to_chat, :reply_to_message, :text, :entities, :audio, :document,
:photo, :sticker, :video, :voice, :caption, :contact,
:location, :venue, :new_chat_member, :left_chat_member,
:photo, :sticker, :video, :voice, :video_note, :caption, :contact,
:location, :venue, :new_chat_members, :left_chat_member,
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
:supergroup_chat_created, :channel_chat_created,
:migrate_from_chat_id, :migrate_to_chat_id, :pinned_message
......@@ -855,6 +864,7 @@ class DB
$sticker = $message->getSticker();
$video = $message->getVideo();
$voice = $message->getVoice();
$video_note = $message->getVideoNote();
$caption = $message->getCaption();
$contact = $message->getContact();
$location = $message->getLocation();
......@@ -892,11 +902,12 @@ class DB
$sth->bindParam(':sticker', $sticker, PDO::PARAM_STR);
$sth->bindParam(':video', $video, PDO::PARAM_STR);
$sth->bindParam(':voice', $voice, PDO::PARAM_STR);
$sth->bindParam(':video_note', $video_note, PDO::PARAM_STR);
$sth->bindParam(':caption', $caption, PDO::PARAM_STR);
$sth->bindParam(':contact', $contact, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':venue', $venue, PDO::PARAM_STR);
$sth->bindParam(':new_chat_member', $new_chat_member, PDO::PARAM_STR);
$sth->bindParam(':new_chat_members', $new_chat_members_ids, PDO::PARAM_STR);
$sth->bindParam(':left_chat_member', $left_chat_member, PDO::PARAM_STR);
$sth->bindParam(':new_chat_title', $new_chat_title, PDO::PARAM_STR);
$sth->bindParam(':new_chat_photo', $new_chat_photo, PDO::PARAM_STR);
......
......@@ -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 int getGifWidth() Optional. Width 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 getTitle() Optional. Title for the result
* @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;
* @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 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 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
......
......@@ -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 int getMpeg4Width() Optional. Video width
* @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 getTitle() Optional. Title for the result
* @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;
* @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 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 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
......
This diff is collapsed.
......@@ -15,15 +15,11 @@ namespace Longman\TelegramBot\Entities;
*
* @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 string getFirstName() User's or bot’s first name
* @method string getLastName() Optional. User's or bot’s last name
* @method string getUsername() Optional. User's or bot’s username
* @method int getId() Unique identifier for this user or bot
* @method string getFirstName() User's or bot’s first name
* @method string getLastName() Optional. User's or bot’s last name
* @method string getUsername() Optional. User's or bot’s username
* @method string getLanguageCode() Optional. User's system language
*/
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
'editMessageCaption',
'editMessageReplyMarkup',
'getWebhookInfo',
'deleteMessage',
];
/**
......@@ -1090,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);
}
}
CREATE TABLE IF NOT EXISTS `user` (
`id` bigint COMMENT 'Unique user identifier',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User\'s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User\'s last name',
`username` CHAR(255) DEFAULT NULL COMMENT 'User\'s username',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s last name',
`username` CHAR(255) 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',
`updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',
......@@ -54,7 +55,7 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Identifier for this result',
`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',
`query` TEXT NOT NULL COMMENT 'The query that was used to obtain the result',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
......@@ -84,19 +85,20 @@ CREATE TABLE IF NOT EXISTS `message` (
`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',
`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',
`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',
`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)',
`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)',
`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 the bot itself)',
`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',
`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',
`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',
`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',
`pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned',
......@@ -106,7 +108,6 @@ CREATE TABLE IF NOT EXISTS `message` (
KEY `forward_from_chat` (`forward_from_chat`),
KEY `reply_to_chat` (`reply_to_chat`),
KEY `reply_to_message` (`reply_to_message`),
KEY `new_chat_member` (`new_chat_member`),
KEY `left_chat_member` (`left_chat_member`),
KEY `migrate_from_chat_id` (`migrate_from_chat_id`),
KEY `migrate_to_chat_id` (`migrate_to_chat_id`),
......@@ -117,7 +118,6 @@ CREATE TABLE IF NOT EXISTS `message` (
FOREIGN KEY (`forward_from_chat`) REFERENCES `chat` (`id`),
FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`),
FOREIGN KEY (`new_chat_member`) REFERENCES `user` (`id`),
FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
......@@ -160,7 +160,7 @@ CREATE TABLE IF NOT EXISTS `edited_message` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
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',
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique inline query identifier',
......
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