From dc3ea8e3ddeb16c3fc9cfe99032c57c9e83bf1ca Mon Sep 17 00:00:00 2001 From: Daniele Callari Date: Mon, 28 Sep 2020 09:41:14 +0200 Subject: [PATCH] ReplyMarkup implementation --- Telegram.class.php | 84 +++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 61 deletions(-) diff --git a/Telegram.class.php b/Telegram.class.php index e0171cb..4863213 100644 --- a/Telegram.class.php +++ b/Telegram.class.php @@ -10,7 +10,7 @@ class TelegramBot # # version # - const Version = '1.3.2.0'; + const Version = '1.4.0.0'; # # limit of http retry @@ -126,6 +126,7 @@ class TelegramBot # # output if debug # + if($this->debug) print_r($data); if($this->debug) print_r($j); # @@ -148,54 +149,18 @@ class TelegramBot # # https://core.telegram.org/bots/api#sendMessage # - public function SendMessage($destination, $textMessage) + public function SendMessage($destination, $textMessage, $replyMarkup=null) { - $base = array - ( + $base = [ 'text' => $textMessage, 'chat_id' => $destination, 'parse_mode'=> 'HTML' - ); - - + ]; + if($replyMarkup!==null) $base['reply_markup'] = ($replyMarkup); return $this->_httpSend('sendMessage', $base); } - # - # ReplyKeyboardMarkup - # - public function ReplyKeyboardMarkup($destination, $textMessage, $keyboard, $resize = false, $oneTime = false, $selective = false) - { - return $this->_httpSend('sendMessage', - [ - 'text' => $textMessage, - 'chat_id' => $destination, - 'parse_mode' => 'HTML', - 'reply_markup' => json_encode( - [ - 'keyboard' => $keyboard, - 'resize_keyboard' => $resize, - 'one_time_keyboard' => $oneTime, - 'selective' => $selective - ]) - ]); - } - - # - # InlineKeyboardMarkup - # - public function InlineKeyboardMarkup($destination, $textMessage, $keyboard) - { - return $this->_httpSend('sendMessage', - [ - 'text' => $textMessage, - 'chat_id' => $destination, - 'parse_mode' => 'HTML', - 'reply_markup' => json_encode(['inline_keyboard' => $keyboard]) - ]); - } - # # Send a contact # @@ -285,7 +250,15 @@ class TelegramBot { $this->actions[] = $x; } - + + # + # markup + # + public static function ReplyMarkup($KeyboardMarkupType, $p) + { + return json_encode([$KeyboardMarkupType => [$p]]); + } + # # listen recevied messages 4 bot # @@ -409,25 +382,14 @@ class TelegramBot { return strpos( strtolower($y), strtolower($x) ) !== false; } - - public static function KeyboardButton($text, $requestContact = false, $requestLocation = false) - { - return [ - 'text' => $text, - 'request_contact' => $requestContact, - 'request_location' => $requestLocation, - - ]; - } - - public static function InlineKeyboardButton($text) - { - return [ - 'text' => $text - // todo.... - ]; - } - +} + +class KeyboardMarkupType +{ + const InlineKeyboard = 'inline_keyboard'; + const ReplyKeyboard = 'reply_keyboard'; + const ReplyKeyboardRemove = 'remove_keyboard'; + const ForceReply = 'force_reply'; } ?> \ No newline at end of file