Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F621970
WhoamiCommand.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
WhoamiCommand.php
View Options
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Written by Marco Boretto <marco.bore@gmail.com>
*/
namespace
Longman
\
TelegramBot
\
Commands
\
UserCommands
;
use
Longman
\
TelegramBot
\
Commands
\
UserCommand
;
use
Longman
\
TelegramBot
\
Entities
\
File
;
use
Longman
\
TelegramBot
\
Entities
\
PhotoSize
;
use
Longman
\
TelegramBot
\
Entities
\
UserProfilePhotos
;
use
Longman
\
TelegramBot
\
Request
;
/**
* User "/whoami" command
*/
class
WhoamiCommand
extends
UserCommand
{
/**
* @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.1.0'
;
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
execute
(
)
{
$message
=
$this
->
getMessage
(
)
;
$from
=
$message
->
getFrom
(
)
;
$user_id
=
$from
->
getId
(
)
;
$chat_id
=
$message
->
getChat
(
)
->
getId
(
)
;
$message_id
=
$message
->
getMessageId
(
)
;
$data
=
[
'chat_id'
=>
$chat_id
,
'reply_to_message_id'
=>
$message_id
,
]
;
//Send chat action
Request
::
sendChatAction
(
[
'chat_id'
=>
$chat_id
,
'action'
=>
'typing'
,
]
)
;
$caption
=
sprintf
(
'Your Id: %d'
.
PHP_EOL
.
'Name: %s %s'
.
PHP_EOL
.
'Username: %s'
,
$user_id
,
$from
->
getFirstName
(
)
,
$from
->
getLastName
(
)
,
$from
->
getUsername
(
)
)
;
//Fetch user profile photo
$limit
=
10
;
$offset
=
null
;
$response
=
Request
::
getUserProfilePhotos
(
[
'user_id'
=>
$user_id
,
'limit'
=>
$limit
,
'offset'
=>
$offset
,
]
)
;
if
(
$response
->
isOk
(
)
)
{
/** @var UserProfilePhotos $user_profile_photos */
$user_profile_photos
=
$response
->
getResult
(
)
;
if
(
$user_profile_photos
->
getTotalCount
(
)
>
0
)
{
$photos
=
$user_profile_photos
->
getPhotos
(
)
;
/** @var PhotoSize $photo */
$photo
=
$photos
[
0
]
[
2
]
;
$file_id
=
$photo
->
getFileId
(
)
;
$data
[
'photo'
]
=
$file_id
;
$data
[
'caption'
]
=
$caption
;
$result
=
Request
::
sendPhoto
(
$data
)
;
//Download the photo after send message response to speedup response
$response2
=
Request
::
getFile
(
[
'file_id'
=>
$file_id
]
)
;
if
(
$response2
->
isOk
(
)
)
{
/** @var File $photo_file */
$photo_file
=
$response2
->
getResult
(
)
;
Request
::
downloadFile
(
$photo_file
)
;
}
return
$result
;
}
}
//No Photo just send text
$data
[
'text'
]
=
$caption
;
return
Request
::
sendMessage
(
$data
)
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 14, 7:41 PM (21 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
139003
Default Alt Text
WhoamiCommand.php (3 KB)
Attached To
Mode
R123 php-telegram-bot
Attached
Detach File
Event Timeline