Aggiornare 'Telegram.class.php'

This commit is contained in:
Daniele Callari 2020-01-15 09:31:47 +01:00
parent 3424680e9b
commit 11e28c717d

View File

@ -10,7 +10,7 @@ class TelegramBot
#
# version
#
const Version = '1.2';
const Version = '1.3';
#
# limit of http retry
@ -92,7 +92,7 @@ class TelegramBot
# set options
#
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data) );
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -148,15 +148,54 @@ class TelegramBot
#
public function SendMessage($destination, $textMessage)
{
return $this->_httpSend('sendMessage', array(
$base = array
(
'text' => $textMessage,
'chat_id' => $destination,
'parse_mode'=> 'HTML'
));
);
return $this->_httpSend('sendMessage', $base);
}
#
# https://core.telegram.org/bots/api#sendcontact
# 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
#
public function SendContact($destination, $number, $firstName, $lastName=null)
{
@ -253,17 +292,17 @@ class TelegramBot
#
# do query
#
$result = file_get_contents($ApiCall);
$result = @file_get_contents($ApiCall);
#
# parse response
#
$x = json_decode($result);
$x = @json_decode($result);
#
# length
#
$count = count((array)$x->result);
$count = @count((array)$x->result);
if( $count )
{
@ -309,6 +348,16 @@ class TelegramBot
#
if($this->debug) print_r($message);
#
# update offset 4 next http call - we comunicate at api.telegram that we have readed the message
#
$offset = $message->update_id+1;
#
# discard old messages
#
if( (time() - $message->message->date) > 10*60 ) continue;
#
# iterate actions
#
@ -319,11 +368,6 @@ class TelegramBot
#
$action($message->message, $this);
}
#
# update offset 4 next http call - we comunicate at api.telegram that we have readed the message
#
$offset = $message->update_id+1;
}
}
}
@ -345,6 +389,24 @@ 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....
];
}
}
?>