ReplyMarkup implementation
This commit is contained in:
parent
81acae2437
commit
dc3ea8e3dd
|
|
@ -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
|
||||
#
|
||||
|
|
@ -286,6 +251,14 @@ 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';
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user