ReplyMarkup implementation

This commit is contained in:
Daniele Callari 2020-09-28 09:41:14 +02:00
parent 81acae2437
commit dc3ea8e3dd

View File

@ -10,7 +10,7 @@ class TelegramBot
# #
# version # version
# #
const Version = '1.3.2.0'; const Version = '1.4.0.0';
# #
# limit of http retry # limit of http retry
@ -126,6 +126,7 @@ class TelegramBot
# #
# output if debug # output if debug
# #
if($this->debug) print_r($data);
if($this->debug) print_r($j); if($this->debug) print_r($j);
# #
@ -148,54 +149,18 @@ class TelegramBot
# #
# https://core.telegram.org/bots/api#sendMessage # https://core.telegram.org/bots/api#sendMessage
# #
public function SendMessage($destination, $textMessage) public function SendMessage($destination, $textMessage, $replyMarkup=null)
{ {
$base = array $base = [
(
'text' => $textMessage, 'text' => $textMessage,
'chat_id' => $destination, 'chat_id' => $destination,
'parse_mode'=> 'HTML' 'parse_mode'=> 'HTML'
); ];
if($replyMarkup!==null) $base['reply_markup'] = ($replyMarkup);
return $this->_httpSend('sendMessage', $base); 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 # Send a contact
# #
@ -285,7 +250,15 @@ class TelegramBot
{ {
$this->actions[] = $x; $this->actions[] = $x;
} }
#
# markup
#
public static function ReplyMarkup($KeyboardMarkupType, $p)
{
return json_encode([$KeyboardMarkupType => [$p]]);
}
# #
# listen recevied messages 4 bot # listen recevied messages 4 bot
# #
@ -409,25 +382,14 @@ class TelegramBot
{ {
return strpos( strtolower($y), strtolower($x) ) !== false; return strpos( strtolower($y), strtolower($x) ) !== false;
} }
}
public static function KeyboardButton($text, $requestContact = false, $requestLocation = false)
{ class KeyboardMarkupType
return [ {
'text' => $text, const InlineKeyboard = 'inline_keyboard';
'request_contact' => $requestContact, const ReplyKeyboard = 'reply_keyboard';
'request_location' => $requestLocation, const ReplyKeyboardRemove = 'remove_keyboard';
const ForceReply = 'force_reply';
];
}
public static function InlineKeyboardButton($text)
{
return [
'text' => $text
// todo....
];
}
} }
?> ?>