Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
Updated to Bot API 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Apr 14, 2019
1 parent 93c573a commit bd713d1
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 68 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
trim_trailing_whitespace = false
27 changes: 2 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

#other
/vendor/
composer.lock
/test/
vendor/
test/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.6.12]
### Changed
- Updated to Telegram Bot API 4.2

## [1.6.11]
### Added
- Added custom method: `clearUpdates()`. It's an alias for `$this->getUpdates(-1);`
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Framework for Telegram Bot API",
"license": "MIT",
"type": "project",
"version": "1.6.11",
"version": "1.6.12",
"authors": [
{
"name": "Luca Patera",
Expand All @@ -17,7 +17,7 @@
"ext-curl":"*",
"ext-fileinfo":"*",
"ext-json":"*",
"netresearch/jsonmapper": ">=v1.1.0"
"netresearch/jsonmapper": "v1.4.*"
},
"autoload": {
"psr-4": {
Expand Down
66 changes: 66 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TelegramBot-PHP

[![API](https://img.shields.io/badge/Telegram%20Bot%20API-v4.1%20--%20August%2027%2C%202018-blue.svg)](https://core.telegram.org/bots/api)
[![API](https://img.shields.io/badge/Telegram%20Bot%20API-4.2%20--%20April%2014%2C%202019-blue.svg)](https://core.telegram.org/bots/api)
![PHP](https://img.shields.io/badge/php-%3E%3D5.6-8892bf.svg)
![CURL](https://img.shields.io/badge/cURL-required-green.svg)

Expand Down Expand Up @@ -238,13 +238,6 @@ Changelog
All notable changes to this project will be documented [here](https://github.com/Lukasss93/telegrambot-php/blob/master/CHANGELOG.md).

### Recent changes
## [1.6.11]
### Added
- Added custom method: `clearUpdates()`. It's an alias for `$this->getUpdates(-1);`
- Added `TelegramLimits` class constants to get the download/upload file limit.
## [1.6.12]
### Changed
- Updated to __Telegram Bot API 4.1__
- You can now get the string argument at the array index position with the `getArgs()` method. Pass:
- True to get an array of strings;
- False to get a string;
- Integer to get the string at the array index position.
- Updated to Telegram Bot API 4.2
91 changes: 64 additions & 27 deletions src/TelegramBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@
* @package TelegramBot
*/
class TelegramBot {
#region CONFIG

//region PROPERTIES
/** @var string $token Bot token */
/** @var string Bot token */
private $token;

/** @var bool $splitLongMessage Automatic split message */
/** @var bool Automatic split message*/
public $splitLongMessage = false;

/** @var JsonMapper $mapper Json mapper */
private $mapper;
#endregion

/** @var Update $webhookData Webhook update */
public $webhookData;
//region PROPERTIES

/** @var Update[] $updatesData GetUpdates data */
public $updatesData;
/** @var JsonMapper */
private $mapper;

/** @var Update Webhook update */
public $webhookData;

/** @var Update[] GetUpdates data */
public $updatesData;

//endregion

/**
Expand Down Expand Up @@ -496,6 +501,19 @@ public function sendContact($parameters) {
return $object;
}

/**
* Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned.
* @param array $parameters
* @return Message
*/
public function sendPoll($parameters) {
$response = $this->endpoint("sendPoll", $parameters);

/** @var Message $object */
$object = $this->mapper->map($response->result, new Message());
return $object;
}

/**
* Use this method when you need to tell the user that something is happening on the bot's side.
* The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing
Expand Down Expand Up @@ -957,28 +975,25 @@ public function editMessageText($parameters) {
public function editMessageCaption($parameters) {
$response = $this->endpoint('editMessageCaption', $parameters);

if(is_bool($response->result)) {
if (is_bool($response->result)) {
/** @var bool $object */
$object = $response->result;
return $object;
}
else {
} else {
/** @var Message $object */
$object = $this->mapper->map($response->result, new Message());
return $object;
}
}

/**
* Use this method to edit audio, document, photo, or video messages. If a message is a part of a message album,
* then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When
* inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a
* URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is
* returned.
* @param $parameters
* Use this method to edit animation, audio, document, photo, or video messages.
* If a message is a part of a message album, then it can be edited only to a photo or a video.
* Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded.
* Use previously uploaded file via its file_id or specify a URL.
* On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
* @param array $parameters
* @return bool|Message
* @throws TelegramException
* @throws \JsonMapper_Exception
*/
public function editMessageMedia($parameters) {
$response = $this->endpoint('editMessageMedia', $parameters);
Expand Down Expand Up @@ -1019,13 +1034,35 @@ public function editMessageReplyMarkup($parameters) {
}

/**
* Use this method to delete a message. A message can only be deleted if it was sent less than 48 hours ago.
* Any such recently sent outgoing message may be deleted. Additionally, if the bot is an administrator in a
* group chat, it can delete any message.
* If the bot is an administrator in a supergroup, it can delete messages from any other user
* and service messages about people joining or leaving the group (other types of service messages may
* only be removed by the group creator).
* In channels, bots can only remove their own messages. Returns True on success.
* Use this method to stop a poll which was sent by the bot.
* On success, the stopped Poll with the final results is returned.
* @param array $parameters
* @return bool|Message
*/
public function stopPoll($parameters) {
$response = $this->endpoint('stopPoll', $parameters);

if (is_bool($response->result)) {
/** @var bool $object */
$object = $response->result;
return $object;
} else {
/** @var Message $object */
$object = $this->mapper->map($response->result, new Message());
return $object;
}
}

/**
* Use this method to delete a message, including service messages, with the following limitations:
* - A message can only be deleted if it was sent less than 48 hours ago.
* - Bots can delete outgoing messages in private chats, groups, and supergroups.
* - Bots can delete incoming messages in private chats.
* - Bots granted can_post_messages permissions can delete outgoing messages in channels.
* - If the bot is an administrator of a group, it can delete any message there.
* - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
*
* Returns True on success.
* @param $chat_id int|string Unique identifier for the target chat or username of the target channel (in the
* format @channelusername)
* @param $message_id int Identifier of the message to delete
Expand Down
5 changes: 4 additions & 1 deletion src/Types/ChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ChatMember {
/** @var string The member's status in the chat. Can be “creator”, “administrator”, “member”, “left” or “kicked” */
public $status;

/** @var int Optional. Restictred and kicked only. Date when restrictions will be lifted for this user, unix time */
/** @var int Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time */
public $until_date;

/** @var bool Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user */
Expand Down Expand Up @@ -40,6 +40,9 @@ class ChatMember {
/** @var bool Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user) */
public $can_promote_members;

/** @var bool Optional. Restricted only. True, if the user is a member of the chat at the moment of the request */
public $is_member;

/** @var bool Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues */
public $can_send_messages;

Expand Down
3 changes: 3 additions & 0 deletions src/Types/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Message {
/** @var string Optional. Signature of the post author for messages forwarded from channels */
public $forward_signature;

/** @var string Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages */
public $forward_sender_name;

/** @var int Optional. For forwarded messages, date the original message was sent in Unix time */
public $forward_date;

Expand Down
21 changes: 21 additions & 0 deletions src/Types/Poll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace TelegramBot\Types;

/**
* This object contains information about a poll.
* @package TelegramBot\Types
*/
class Poll {
/** @var string Unique poll identifier */
public $id;

/** @var string Poll question, 1-255 characters */
public $question;

/** @var PollOption[] List of poll options */
public $options;

/** @var bool True, if the poll is closed */
public $is_closed;
}
15 changes: 15 additions & 0 deletions src/Types/PollOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace TelegramBot\Types;

/**
* This object contains information about one answer option in a poll.
* @package TelegramBot\Types
*/
class PollOption {
/** @var string Option text, 1-100 characters */
public $text;

/** @var int Number of users that voted for this option */
public $voter_count;
}
7 changes: 4 additions & 3 deletions src/Types/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
use TelegramBot\Constants\UpdateTypes;

/**
* This object represents an incoming update.
* At most one of the optional parameters can be present in any given update.
* This object represents an incoming update. At most one of the optional parameters can be present in any given update.
* @package TelegramBot\Types
* @link https://core.telegram.org/bots/api#update
*/
class Update {
/**
Expand Down Expand Up @@ -67,6 +65,9 @@ class Update {
*/
public $pre_checkout_query;

/** @var Poll Optional. New poll state. Bots receive only updates about polls, which are sent or stopped by the bot */
public $poll;

/**
* Return the current update type
* You can use the UpdateTypes enum class
Expand Down

0 comments on commit bd713d1

Please sign in to comment.