Commit 84cd8f50 authored by Avtandil Kikabidze's avatar Avtandil Kikabidze

Improved code and doc-blocks in admin and user commands

parent e986a12d
......@@ -10,9 +10,6 @@
namespace Longman\TelegramBot\Commands;
/**
* Abstract Admin Command Class
*/
abstract class AdminCommand extends Command
{
......
......@@ -15,30 +15,44 @@ use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Request;
/**
* Admin "/chats" command
*/
class ChatsCommand extends AdminCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'chats';
/**
* @var string
*/
protected $description = 'List or search all chats stored by the bot';
/**
* @var string
*/
protected $usage = '/chats, /chats * or /chats <search string>';
/**
* @var string
*/
protected $version = '1.0.2';
/**
* @var bool
*/
protected $need_mysql = true;
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = trim($message->getText(true));
$text = trim($message->getText(true));
$results = DB::selectChats(
true, //Select groups (group chat)
......@@ -50,8 +64,8 @@ class ChatsCommand extends AdminCommand
($text === '' || $text == '*') ? null : $text //Text to search in user/group name
);
$user_chats = 0;
$group_chats = 0;
$user_chats = 0;
$group_chats = 0;
$super_group_chats = 0;
if ($text === '') {
......@@ -65,11 +79,12 @@ class ChatsCommand extends AdminCommand
foreach ($results as $result) {
//Initialize a chat object
$result['id'] = $result['chat_id'];
$chat = new Chat($result);
$chat = new Chat($result);
$whois = $chat->getId();
if ($this->telegram->getCommandObject('whois')) {
$whois = '/whois' . str_replace('-', 'g', $chat->getId()); //We can't use '-' in command because part of it will become unclickable
$whois = '/whois' . str_replace('-', 'g',
$chat->getId()); //We can't use '-' in command because part of it will become unclickable
}
if ($chat->isPrivateChat()) {
......@@ -102,7 +117,7 @@ class ChatsCommand extends AdminCommand
$text_back .= "\n" . 'Total: ' . ($user_chats + $group_chats + $super_group_chats);
if ($text === '') {
$text_back .= "\n\n" . 'List all chats: /' . $this->name .' *' . "\n" . 'Search for chats: /' . $this->name .' <search string>';
$text_back .= "\n\n" . 'List all chats: /' . $this->name . ' *' . "\n" . 'Search for chats: /' . $this->name . ' <search string>';
}
}
......
......@@ -18,15 +18,30 @@ use Longman\TelegramBot\Request;
*/
class SendtoallCommand extends AdminCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'sendtoall';
/**
* @var string
*/
protected $description = 'Send the message to all the user\'s bot';
/**
* @var string
*/
protected $usage = '/sendtoall <message to send>';
/**
* @var string
*/
protected $version = '1.2.1';
/**
* @var bool
*/
protected $need_mysql = true;
/**#@-*/
/**
* Execute command
......@@ -38,7 +53,7 @@ class SendtoallCommand extends AdminCommand
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$text = $message->getText(true);
if ($text === '') {
$text = 'Write the message to send: /sendtoall <message>';
......@@ -53,18 +68,18 @@ class SendtoallCommand extends AdminCommand
null //'yyyy-mm-dd hh:mm:ss' date range to
);
$tot = 0;
$tot = 0;
$fail = 0;
$text = 'Message sent to:' . "\n";
foreach ($results as $result) {
$status = '';
$type = '';
$type = '';
if ($result->isOk()) {
$status = '✔️';
$ServerResponse = $result->getResult();
$chat = $ServerResponse->getChat();
$chat = $ServerResponse->getChat();
if ($chat->isPrivateChat()) {
$name = $chat->getFirstName();
$type = 'user';
......
......@@ -22,18 +22,35 @@ use Longman\TelegramBot\Request;
*/
class WhoisCommand extends AdminCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'whois';
/**
* @var string
*/
protected $description = 'Lookup user or group info';
/**
* @var string
*/
protected $usage = '/whois <id> or /whois <search string>';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
......@@ -41,9 +58,9 @@ class WhoisCommand extends AdminCommand
$chat_id = $message->getChat()->getId();
$command = $message->getCommand();
$text = trim($message->getText(true));
$text = trim($message->getText(true));
$data = [ 'chat_id' => $chat_id ];
$data = ['chat_id' => $chat_id];
//No point in replying to messages in private chats
if (!$message->getChat()->isPrivateChat()) {
......@@ -93,12 +110,12 @@ class WhoisCommand extends AdminCommand
if (is_array($result)) {
$result['id'] = $result['chat_id'];
$chat = new Chat($result);
$chat = new Chat($result);
$user_id = $result['id'];
$user_id = $result['id'];
$created_at = $result['chat_created_at'];
$updated_at = $result['chat_updated_at'];
$old_id = $result['old_id'];
$old_id = $result['old_id'];
}
if ($chat != null) {
......@@ -114,33 +131,33 @@ class WhoisCommand extends AdminCommand
$text .= 'Last activity: ' . $updated_at . "\n";
//Code from Whoami command
$limit = 10;
$offset = null;
$limit = 10;
$offset = null;
$ServerResponse = Request::getUserProfilePhotos([
'user_id' => $user_id ,
'limit' => $limit,
'offset' => $offset,
]);
'user_id' => $user_id,
'limit' => $limit,
'offset' => $offset,
]);
if ($ServerResponse->isOk()) {
$UserProfilePhoto = $ServerResponse->getResult();
$totalcount = $UserProfilePhoto->getTotalCount();
$totalcount = $UserProfilePhoto->getTotalCount();
} else {
$totalcount = 0;
}
if ($totalcount > 0) {
$photos = $UserProfilePhoto->getPhotos();
$photo = $photos[0][2];
$photos = $UserProfilePhoto->getPhotos();
$photo = $photos[0][2];
$file_id = $photo->getFileId();
$data['photo'] = $file_id;
$data['photo'] = $file_id;
$data['caption'] = $text;
return Request::sendPhoto($data);
}
} elseif ($chat->isGroupChat()) {
$text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: '.$old_id.')' : ''). "\n";
$text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: ' . $old_id . ')' : '') . "\n";
$text .= 'Type: ' . ucfirst($chat->getType()) . "\n";
$text .= 'Title: ' . $chat->getTitle() . "\n";
$text .= 'First time added to group: ' . $created_at . "\n";
......
......@@ -15,9 +15,6 @@ use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Entities\Update;
/**
* Abstract Command Class
*/
abstract class Command
{
/**
......@@ -93,7 +90,7 @@ abstract class Command
/**
* Constructor
*
* @param Telegram $telegram
* @param Telegram $telegram
* @param \Longman\TelegramBot\Entities\Update $update
*/
public function __construct(Telegram $telegram, Update $update = null)
......@@ -112,7 +109,7 @@ abstract class Command
public function setUpdate(Update $update = null)
{
if (!empty($update)) {
$this->update = $update;
$this->update = $update;
$this->message = $this->update->getMessage();
}
return $this;
......
......@@ -12,9 +12,6 @@ namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Request;
/**
* Abstract System Command Class
*/
abstract class SystemCommand extends Command
{
/**
......@@ -23,7 +20,7 @@ abstract class SystemCommand extends Command
* Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality.
*
* @return Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function execute()
{
......
......@@ -10,9 +10,6 @@
namespace Longman\TelegramBot\Commands;
/**
* Abstract User Command Class
*/
abstract class UserCommand extends Command
{
......
......@@ -24,18 +24,35 @@ use Longman\TelegramBot\Request;
*/
class CancelCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'cancel';
/**
* @var string
*/
protected $description = 'Cancel the currently active conversation';
/**
* @var string
*/
protected $usage = '/cancel';
/**
* @var string
*/
protected $version = '0.1.1';
/**
* @var bool
*/
protected $need_mysql = true;
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function execute()
{
......@@ -56,7 +73,9 @@ class CancelCommand extends UserCommand
}
/**
* {@inheritdoc}
* Execute no db
*
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function executeNoDb()
{
......@@ -72,10 +91,12 @@ class CancelCommand extends UserCommand
*/
private function hideKeyboard($text)
{
return Request::sendMessage([
'reply_markup' => new ReplyKeyboardHide(['selective' => true]),
'chat_id' => $this->getMessage()->getChat()->getId(),
'text' => $text,
]);
return Request::sendMessage(
[
'reply_markup' => new ReplyKeyboardHide(['selective' => true]),
'chat_id' => $this->getMessage()->getChat()->getId(),
'text' => $text,
]
);
}
}
......@@ -21,14 +21,25 @@ use Longman\TelegramBot\Request;
*/
class DateCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'date';
/**
* @var string
*/
protected $description = 'Show date/time by location';
/**
* @var string
*/
protected $usage = '/date <location>';
/**
* @var string
*/
protected $version = '1.3.0';
/**#@-*/
/**
* Guzzle Client object
......@@ -64,10 +75,11 @@ class DateCommand extends UserCommand
* @param string $location
*
* @return array|boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private function getCoordinates($location)
{
$path = 'geocode/json';
$path = 'geocode/json';
$query = ['address' => urlencode($location)];
if ($this->google_api_key !== null) {
......@@ -85,10 +97,10 @@ class DateCommand extends UserCommand
}
$result = $result['results'][0];
$lat = $result['geometry']['location']['lat'];
$lng = $result['geometry']['location']['lng'];
$acc = $result['geometry']['location_type'];
$types = $result['types'];
$lat = $result['geometry']['location']['lat'];
$lng = $result['geometry']['location']['lng'];
$acc = $result['geometry']['location_type'];
$types = $result['types'];
return [$lat, $lng, $acc, $types];
}
......@@ -100,12 +112,13 @@ class DateCommand extends UserCommand
* @param string $lng
*
* @return array|boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private function getDate($lat, $lng)
{
$path = 'timezone/json';
$date_utc = new \DateTime(null, new \DateTimeZone('UTC'));
$date_utc = new \DateTime(null, new \DateTimeZone('UTC'));
$timestamp = $date_utc->format('U');
$query = [
......@@ -184,7 +197,9 @@ class DateCommand extends UserCommand
}
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
......@@ -196,7 +211,7 @@ class DateCommand extends UserCommand
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$chat_id = $message->getChat()->getId();
$location = $message->getText(true);
if (empty($location)) {
......
......@@ -18,23 +18,36 @@ use Longman\TelegramBot\Request;
*/
class EchoCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'echo';
/**
* @var string
*/
protected $description = 'Show text';
/**
* @var string
*/
protected $usage = '/echo <text>';
/**
* @var string
*/
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = trim($message->getText(true));
$text = trim($message->getText(true));
if ($text === '') {
$text = 'Command usage: ' . $this->getUsage();
......
......@@ -18,17 +18,30 @@ use Longman\TelegramBot\Request;
*/
class HelpCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'help';
/**
* @var string
*/
protected $description = 'Show bot commands help';
/**
* @var string
*/
protected $usage = '/help or /help <command>';
/**
* @var string
*/
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
......@@ -36,7 +49,7 @@ class HelpCommand extends UserCommand
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$command = trim($message->getText(true));
$command = trim($message->getText(true));
//Only get enabled Admin and User commands
$commands = array_filter($this->telegram->getCommandsList(), function ($command) {
......@@ -56,7 +69,7 @@ class HelpCommand extends UserCommand
$command = str_replace('/', '', $command);
if (isset($commands[$command])) {
$command = $commands[$command];
$text = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n";
$text = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n";
$text .= 'Description: ' . $command->getDescription() . "\n";
$text .= 'Usage: ' . $command->getUsage();
} else {
......
......@@ -18,25 +18,38 @@ use Longman\TelegramBot\Request;
*/
class SlapCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'slap';
/**
* @var string
*/
protected $description = 'Slap someone with their username';
/**
* @var string
*/
protected $usage = '/slap <@user>';
/**
* @var string
*/
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
$text = $message->getText(true);
$sender = '@' . $message->getFrom()->getUsername();
......
......@@ -22,15 +22,30 @@ use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
*/
class SurveyCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'survey';
/**
* @var string
*/
protected $description = 'Survery for bot users';
/**
* @var string
*/
protected $usage = '/survey';
/**
* @var string
*/
protected $version = '0.2.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**#@-*/
/**
* Conversation Object
......@@ -40,7 +55,9 @@ class SurveyCommand extends UserCommand
protected $conversation;
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
......@@ -58,7 +75,7 @@ class SurveyCommand extends UserCommand
if ($chat->isGroupChat() || $chat->isSuperGroup()) {
//reply to message id is applied by default
//Force reply is applied by default to so can work with privacy on
$data['reply_markup'] = new ForceReply([ 'selective' => true]);
$data['reply_markup'] = new ForceReply(['selective' => true]);
}
$data['chat_id'] = $chat_id;
......@@ -80,29 +97,29 @@ class SurveyCommand extends UserCommand
if (empty($text)) {
$this->conversation->notes['state'] = 0;
$this->conversation->update();
$data['text'] = 'Type your name:';
$data['text'] = 'Type your name:';
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
$result = Request::sendMessage($data);
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['name'] = $text;
$text = '';
// no break
$text = '';
// no break
case 1:
if (empty($text)) {
$this->conversation->notes['state'] = 1;
$this->conversation->update();
$data['text'] = 'Type your surname:';
$result = Request::sendMessage($data);
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['surname'] = $text;
++$state;
$text = '';
// no break
// no break
case 2:
if (empty($text) || !is_numeric($text)) {
$this->conversation->notes['state'] = 2;
......@@ -116,25 +133,25 @@ class SurveyCommand extends UserCommand
break;
}
$this->conversation->notes['age'] = $text;
$text = '';
$text = '';
// no break
// no break
case 3:
if (empty($text) || !($text == 'M' || $text == 'F')) {
$this->conversation->notes['state'] = 3;
$this->conversation->update();
$keyboard = [['M','F']];
$keyboard = [['M', 'F']];
$reply_keyboard_markup = new ReplyKeyboardMarkup(
[
'keyboard' => $keyboard ,
'resize_keyboard' => true,
'keyboard' => $keyboard,
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true
'selective' => true
]
);
$data['reply_markup'] = $reply_keyboard_markup;
$data['text'] = 'Select your gender:';
$data['reply_markup'] = $reply_keyboard_markup;
$data['text'] = 'Select your gender:';
if (!empty($text) && !($text == 'M' || $text == 'F')) {
$data['text'] = 'Select your gender, choose a keyboard option:';
}
......@@ -142,74 +159,88 @@ class SurveyCommand extends UserCommand
break;
}
$this->conversation->notes['gender'] = $text;
$text = '';
// no break
$text = '';
// no break
case 4:
if (is_null($message->getLocation())) {
$this->conversation->notes['state'] = 4;
$this->conversation->update();
$data['reply_markup'] = new ReplyKeyboardMarkup([
'keyboard' => [[
[ 'text' => 'Share Location', 'request_location' => true ],
]],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true,
]);
$data['text'] = 'Share your location:';
$result = Request::sendMessage($data);
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => [
[
[
'text' => 'Share Location',
'request_location' => true
],
]
],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true,
]
);
$data['text'] = 'Share your location:';
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['longitude'] = $message->getLocation()->getLongitude();
$this->conversation->notes['latitude'] = $message->getLocation()->getLatitude();
$this->conversation->notes['latitude'] = $message->getLocation()->getLatitude();
// no break
// no break
case 5:
if (is_null($message->getPhoto())) {
$this->conversation->notes['state'] = 5;
$this->conversation->update();
$data['text'] = 'Insert your picture:';
$data['text'] = 'Insert your picture:';
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
$result = Request::sendMessage($data);
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['photo_id'] = $message->getPhoto()[0]->getFileId();
// no break
// no break
case 6:
if (is_null($message->getContact())) {
$this->conversation->notes['state'] = 6;
$this->conversation->update();
$data['text'] = 'Share your contact information:';
$data['reply_markup'] = new ReplyKeyboardMarkup([
'keyboard' => [[
[ 'text' => 'Share Contact', 'request_contact' => true ],
]],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true,
]);
$result = Request::sendMessage($data);
$data['text'] = 'Share your contact information:';
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => [
[
[
'text' => 'Share Contact',
'request_contact' => true
],
]
],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true,
]
);
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['phone_number'] = $message->getContact()->getPhoneNumber();
// no break
// no break
case 7:
$this->conversation->update();
$out_text = '/Survey result:' . "\n";
unset($this->conversation->notes['state']);
foreach ($this->conversation->notes as $k => $v) {
$out_text .= "\n" . ucfirst($k).': ' . $v;
$out_text .= "\n" . ucfirst($k) . ': ' . $v;
}
$data['photo'] = $this->conversation->notes['photo_id'];
$data['photo'] = $this->conversation->notes['photo_id'];
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
$data['caption'] = $out_text;
$data['caption'] = $out_text;
$this->conversation->stop();
$result = Request::sendPhoto($data);
break;
......
......@@ -21,14 +21,25 @@ use Longman\TelegramBot\Request;
*/
class WeatherCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'weather';
/**
* @var string
*/
protected $description = 'Show weather by location';
/**
* @var string
*/
protected $usage = '/weather <location>';
/**
* @var string
*/
protected $version = '1.1.0';
/**#@-*/
/**
* Base URI for OpenWeatherMap API
......@@ -43,12 +54,13 @@ class WeatherCommand extends UserCommand
* @param string $location
*
* @return string
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private function getWeatherData($location)
{
$client = new Client(['base_uri' => $this->owm_api_base_uri]);
$path = 'weather';
$query = [
$path = 'weather';
$query = [
'q' => $location,
'units' => 'metric',
'APPID' => trim($this->getConfig('owm_api_key')),
......@@ -60,7 +72,7 @@ class WeatherCommand extends UserCommand
throw new TelegramException($e->getMessage());
}
return (string) $response->getBody();
return (string)$response->getBody();
}
/**
......@@ -78,7 +90,7 @@ class WeatherCommand extends UserCommand
}
//http://openweathermap.org/weather-conditions
$conditions = [
$conditions = [
'clear' => ' ☀️',
'clouds' => ' ☁️',
'rain' => ' ☔',
......@@ -103,13 +115,15 @@ class WeatherCommand extends UserCommand
}
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = '';
$text = '';
if (trim($this->getConfig('owm_api_key'))) {
if ($location = trim($message->getText(true))) {
......
......@@ -21,49 +21,66 @@ use Longman\TelegramBot\Request;
*/
class WhoamiCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'whoami';
/**
* @var string
*/
protected $description = 'Show your id, name and username';
/**
* @var string
*/
protected $usage = '/whoami';
/**
* @var string
*/
protected $version = '1.0.1';
/**
* @var bool
*/
protected $public = true;
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$message = $this->getMessage();
$user_id = $message->getFrom()->getId();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
$text = $message->getText(true);
//Send chat action
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
$caption = 'Your Id: ' . $user_id . "\n";
$caption .= 'Name: ' . $message->getFrom()->getFirstName()
. ' ' . $message->getFrom()->getLastName() . "\n";
. ' ' . $message->getFrom()->getLastName() . "\n";
$caption .= 'Username: ' . $message->getFrom()->getUsername();
//Fetch user profile photo
$limit = 10;
$offset = null;
$limit = 10;
$offset = null;
$ServerResponse = Request::getUserProfilePhotos([
'user_id' => $user_id ,
'limit' => $limit,
'offset' => $offset,
]);
'user_id' => $user_id,
'limit' => $limit,
'offset' => $offset,
]);
//Check if the request isOK
if ($ServerResponse->isOk()) {
$UserProfilePhoto = $ServerResponse->getResult();
$totalcount = $UserProfilePhoto->getTotalCount();
$totalcount = $UserProfilePhoto->getTotalCount();
} else {
$totalcount = 0;
}
......@@ -76,17 +93,17 @@ class WhoamiCommand extends UserCommand
if ($totalcount > 0) {
$photos = $UserProfilePhoto->getPhotos();
//I pick the latest photo with the hight definition
$photo = $photos[0][2];
$photo = $photos[0][2];
$file_id = $photo->getFileId();
$data['photo'] = $file_id;
$data['photo'] = $file_id;
$data['caption'] = $caption;
$result = Request::sendPhoto($data);
//Download the image pictures
//Download after send message response to speedup response
$file_id = $photo->getFileId();
$file_id = $photo->getFileId();
$ServerResponse = Request::getFile(['file_id' => $file_id]);
if ($ServerResponse->isOk()) {
Request::downloadFile($ServerResponse->getResult());
......@@ -94,7 +111,7 @@ class WhoamiCommand extends UserCommand
} else {
//No Photo just send text
$data['text'] = $caption;
$result = Request::sendMessage($data);
$result = Request::sendMessage($data);
}
return $result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment