Aggiornare 'Telegram.class.php'
This commit is contained in:
parent
3424680e9b
commit
11e28c717d
|
|
@ -10,7 +10,7 @@ class TelegramBot
|
||||||
#
|
#
|
||||||
# version
|
# version
|
||||||
#
|
#
|
||||||
const Version = '1.2';
|
const Version = '1.3';
|
||||||
|
|
||||||
#
|
#
|
||||||
# limit of http retry
|
# limit of http retry
|
||||||
|
|
@ -92,7 +92,7 @@ class TelegramBot
|
||||||
# set options
|
# set options
|
||||||
#
|
#
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
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_VERBOSE, 0);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
|
@ -148,15 +148,54 @@ class TelegramBot
|
||||||
#
|
#
|
||||||
public function SendMessage($destination, $textMessage)
|
public function SendMessage($destination, $textMessage)
|
||||||
{
|
{
|
||||||
return $this->_httpSend('sendMessage', array(
|
$base = array
|
||||||
|
(
|
||||||
'text' => $textMessage,
|
'text' => $textMessage,
|
||||||
'chat_id' => $destination,
|
'chat_id' => $destination,
|
||||||
'parse_mode'=> 'HTML'
|
'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)
|
public function SendContact($destination, $number, $firstName, $lastName=null)
|
||||||
{
|
{
|
||||||
|
|
@ -253,17 +292,17 @@ class TelegramBot
|
||||||
#
|
#
|
||||||
# do query
|
# do query
|
||||||
#
|
#
|
||||||
$result = file_get_contents($ApiCall);
|
$result = @file_get_contents($ApiCall);
|
||||||
|
|
||||||
#
|
#
|
||||||
# parse response
|
# parse response
|
||||||
#
|
#
|
||||||
$x = json_decode($result);
|
$x = @json_decode($result);
|
||||||
|
|
||||||
#
|
#
|
||||||
# length
|
# length
|
||||||
#
|
#
|
||||||
$count = count((array)$x->result);
|
$count = @count((array)$x->result);
|
||||||
|
|
||||||
if( $count )
|
if( $count )
|
||||||
{
|
{
|
||||||
|
|
@ -308,7 +347,17 @@ class TelegramBot
|
||||||
# debug
|
# debug
|
||||||
#
|
#
|
||||||
if($this->debug) print_r($message);
|
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
|
# iterate actions
|
||||||
#
|
#
|
||||||
|
|
@ -319,11 +368,6 @@ class TelegramBot
|
||||||
#
|
#
|
||||||
$action($message->message, $this);
|
$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;
|
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....
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user