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

Commit

Permalink
Introducing Bot API 3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed May 19, 2017
1 parent 297a12d commit 1c8b909
Show file tree
Hide file tree
Showing 19 changed files with 373 additions and 49 deletions.
2 changes: 1 addition & 1 deletion 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.0.2",
"version": "1.1.0",
"authors": [
{
"name": "Luca Patera",
Expand Down
6 changes: 3 additions & 3 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-December%204%2C%202016-36ade1.svg)](https://core.telegram.org/bots/api)
[![API](https://img.shields.io/badge/Telegram%20Bot%20API-May%2018%2C%202017-blue.svg)](https://core.telegram.org/bots/api)
![PHP](https://img.shields.io/badge/php-%3E%3D5.3-8892bf.svg)
![CURL](https://img.shields.io/badge/cURL-required-green.svg)

Expand All @@ -27,7 +27,7 @@ For the GetUpdates:
Installation
---------

* ###Manual
* #### Manual
Copy **src** folder in your project, rename it and include all classes in your new bot script.

```php
Expand All @@ -36,7 +36,7 @@ Installation
$telegram = new TelegramBot($token);
```

* ###Composer
* #### Composer

`composer require lukasss93/telegrambot-php`

Expand Down
145 changes: 124 additions & 21 deletions src/TelegramBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ public function sendVoice($parameters)
$object=$response->result===null?null:$this->mapper->map($response->result,new Message());
return $object;
}

/**
* As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
* Use this method to send video messages. On success, the sent Message is returned.
* @param array $parameters
* @return Message
*/
public function sendVideoNote($parameters)
{
$response=$this->endpoint("sendVideoNote", $parameters);

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

/**
* Use this method to send point on the map. On success, the sent Message is returned.
Expand Down Expand Up @@ -439,6 +454,27 @@ public function kickChatMember($chat_id, $user_id)
$object=$response->result;
return $object;
}

/**
* Use this method to unban a previously kicked user in a supergroup.
* The user will not return to the group automatically, but will be able to join via link, etc.
* The bot must be an administrator in the group for this to work.
* Returns True on success.
* @param int|string $chat_id
* @param int $user_id
* @return bool
*/
public function unbanChatMember($chat_id, $user_id)
{
$response=$this->endpoint("unbanChatMember", array(
'chat_id'=>$chat_id,
'user_id'=>$user_id
));

/** @var bool $object */
$object=$response->result;
return $object;
}

/**
* Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
Expand All @@ -454,27 +490,6 @@ public function leaveChat($chat_id)
return $object;
}

/**
* Use this method to unban a previously kicked user in a supergroup.
* The user will not return to the group automatically, but will be able to join via link, etc.
* The bot must be an administrator in the group for this to work.
* Returns True on success.
* @param int|string $chat_id
* @param int $user_id
* @return bool
*/
public function unbanChatMember($chat_id, $user_id)
{
$response=$this->endpoint("unbanChatMember", array(
'chat_id'=>$chat_id,
'user_id'=>$user_id
));

/** @var bool $object */
$object=$response->result;
return $object;
}

/**
* Use this method to get up to date information about the chat
* (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
Expand Down Expand Up @@ -637,6 +652,30 @@ public function editMessageReplyMarkup($parameters)
return $object;
}
}

/**
* 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.
* @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
* @return bool
*/
public function deleteMessage($chat_id,$message_id)
{
$response=$this->endpoint("deleteMessage", [
'chat_id'=>$chat_id,
'message_id'=>$message_id
]);

/** @var bool $object */
$object=$response->result;
return $object;
}

//</editor-fold>

Expand All @@ -658,7 +697,71 @@ public function answerInlineQuery($parameters)
}

//</editor-fold>

//<editor-fold desc="PAYMENTS">
/**
* Your bot can accept payments from Telegram users.
* Please see the introduction to payments for more details
* on the process and how to set up payments for your bot.
* Please note that users will need Telegram v.4.0 or
* higher to use payments (released on May 18, 2017).
*/

/**
* Use this method to send invoices.
* On success, the sent Message is returned.
* @param array $parameters
* @return Message
*/
public function sendInvoice($parameters)
{
$data=$this->endpoint('sendInvoice',$parameters);

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

/**
* If you sent an invoice requesting a shipping address and the parameter
* is_flexible was specified, the Bot API will send an Update with a
* shipping_query field to the bot.
* Use this method to reply to shipping queries.
* On success, True is returned.
* @param object[] $parameters
* @return bool
*/
public function answerShippingQuery($parameters)
{
$response=$this->endpoint("answerShippingQuery", $parameters);

/** @var bool $object */
$object=$response->result;
return $object;
}

/**
* Once the user has confirmed their payment and shipping details,
* the Bot API sends the final confirmation in the form of an Update
* with the field pre_checkout_query.
* Use this method to respond to such pre-checkout queries.
* On success, True is returned.
* Note: The Bot API must receive an answer within 10 seconds
* after the pre-checkout query was sent.
* @param object[] $parameters
* @return bool
*/
public function answerPreCheckoutQuery($parameters)
{
$response=$this->endpoint("answerPreCheckoutQuery", $parameters);

/** @var bool $object */
$object=$response->result;
return $object;
}

//</editor-fold>

//<editor-fold desc="GAMES">

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Types/InlineKeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ class InlineKeyboardButton
* NOTE: This type of button must always be the first button in the first row.
*/
public $callback_game;

/**
* @var bool Optional. Specify True, to send a Pay button.
* NOTE: This type of button must always be the first button in the first row.
*/
public $pay;
}
3 changes: 3 additions & 0 deletions src/Types/InlineQueryResultGif.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class InlineQueryResultGif

/** @var int Optional. Height of the GIF */
public $gif_height;

/** @var int Optional. Duration of the GIF */
public $gif_duration;

/** @var string URL of the static thumbnail for the result (jpeg or gif) */
public $thumb_url;
Expand Down
3 changes: 3 additions & 0 deletions src/Types/InlineQueryResultMpeg4Gif.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class InlineQueryResultMpeg4Gif

/** @var int Optional. Video height */
public $mpeg4_height;

/** @var int Optional. Video duration */
public $mpeg4_duration;

/** @var string URL of the static thumbnail (jpeg or gif) for the result */
public $thumb_url;
Expand Down
21 changes: 0 additions & 21 deletions src/Types/InputContactMessageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
*/
class InputContactMessageContent
{
/** @var string Type of the result, must be contact */
public $type;

/** @var string Unique identifier for this result, 1-64 Bytes */
public $id;

/** @var string Contact's phone number */
public $phone_number;

Expand All @@ -22,19 +16,4 @@ class InputContactMessageContent

/** @var string Optional. Contact's last name */
public $last_name;

/** @var InlineKeyboardMarkup Optional. Inline keyboard attached to the message */
public $reply_markup;

/** @var InputTextMessageContent|InputLocationMessageContent|InputVenueMessageContent|InputContactMessageContent Optional. Content of the message to be sent instead of the contact */
public $input_message_content;

/** @var string Optional. Url of the thumbnail for the result */
public $thumb_url;

/** @var int Optional. Thumbnail width */
public $thumb_width;

/** @var int Optional. Thumbnail height */
public $thumb_height;
}
28 changes: 28 additions & 0 deletions src/Types/Invoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace TelegramBot\Types;

/** This object contains basic information about an invoice. */
class Invoice
{
/** @var string Product name */
public $title;

/** @var string Product description */
public $description;

/** @var string Unique bot deep-linking parameter that can be used to generate this invoice */
public $start_parameter;

/** @var string Three-letter ISO 4217 currency code */
public $currency;

/** @var int Total price in the smallest units of the currency
* (integer, not float/double).
* For example, for a price of US$ 1.45 pass amount = 145.
* See the exp parameter in currencies.json
* (https://core.telegram.org/bots/payments/currencies.json),
* it shows the number of digits past the decimal point
* for each currency (2 for the majority of currencies). */
public $total_amount;
}
21 changes: 21 additions & 0 deletions src/Types/LabeledPrice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace TelegramBot\Types;

/** This object represents a portion of the price for goods or services. */
class LabeledPrice
{
/** @var string Portion label */
public $label;

/**
* @var int
* Price of the product in the smallest units of the currency
* (integer, not float/double).
* For example, for a price of US$ 1.45 pass amount = 145.
* See the exp parameter in currencies.json
* (https://core.telegram.org/bots/payments/currencies.json),
* it shows the number of digits past the decimal point for
* each currency (2 for the majority of currencies). */
public $amount;
}
18 changes: 15 additions & 3 deletions src/Types/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class Message

/** @var Voice Optional. Message is a voice message, information about the file */
public $voice;

/** @var VideoNote Optional. Message is a video note, information about the video message */
public $video_note;

/** @var User[] Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members) */
public $new_chat_members;

/** @var string Optional. Caption for the document, photo or video, 0-200 characters */
public $caption;
Expand All @@ -73,9 +79,9 @@ class Message

/** @var Venue Optional. Message is a venue, information about the venue */
public $venue;

/** @var User Optional. A new member was added to the group, information about them (this member may be the bot itself) */
public $new_chat_member;
/** @var User Optional. A new member was added to the group, information about them (this member may be the bot itself) */
public $new_chat_member;

/** @var User Optional. A member was removed from the group, information about them (this member may be the bot itself) */
public $left_chat_member;
Expand Down Expand Up @@ -106,6 +112,12 @@ class Message

/** @var Message Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply */
public $pinned_message;

/** @var Invoice Optional. Message is an invoice for a payment, information about the invoice. */
public $invoice;

/** @var SuccessfulPayment Optional. Message is a service message about a successful payment, information about the payment. */
public $successful_payment;


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

namespace TelegramBot\Types;

/** This object represents information about an order. */
class OrderInfo
{
/** @var string Optional. User name */
public $name;

/** @var string Optional. User's phone number */
public $phone_number;

/** @var string Optional. User email */
public $email;

/** @var ShippingAddress Optional. User shipping address */
public $shipping_address;
}
Loading

0 comments on commit 1c8b909

Please sign in to comment.