Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F627827
Request.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
2 KB
Referenced Files
None
Subscribers
None
Request.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.
*/
namespace
Longman
\
TelegramBot
;
use
Longman
\
TelegramBot
\
Exception
\
TelegramException
;
class
Request
{
private
static
$telegram
;
private
static
$input
;
private
static
$methods
=
array
(
'getMe'
,
'sendMessage'
,
'forwardMessage'
,
'sendPhoto'
,
'sendAudio'
,
'sendDocument'
,
'sendSticker'
,
'sendVideo'
,
'sendLocation'
,
'sendChatAction'
,
'getUserProfilePhotos'
,
'getUpdates'
,
'setWebhook'
,
)
;
public
static
function
initialize
(
Telegram
$telegram
)
{
self
::
$telegram
=
$telegram
;
}
public
static
function
getInput
(
)
{
if
(
$update
=
self
::
$telegram
->
getCustomUpdate
(
)
)
{
self
::
$input
=
$update
;
}
else
{
self
::
$input
=
file_get_contents
(
'php://input'
)
;
}
self
::
log
(
)
;
return
self
::
$input
;
}
private
static
function
log
(
)
{
if
(
!
self
::
$telegram
->
getLogRequests
(
)
)
{
return
false
;
}
$path
=
self
::
$telegram
->
getLogPath
(
)
;
if
(
!
$path
)
{
return
false
;
}
$status
=
file_put_contents
(
$path
,
self
::
$input
.
"\n"
,
FILE_APPEND
)
;
return
$status
;
}
public
static
function
send
(
$action
,
array
$data
=
null
)
{
if
(
defined
(
'PHPUNIT_TESTSUITE'
)
)
{
return
$data
;
}
$ch
=
curl_init
(
)
;
$curlConfig
=
array
(
CURLOPT_URL
=>
'https://api.telegram.org/bot'
.
self
::
$telegram
->
getApiKey
(
)
.
'/'
.
$action
,
CURLOPT_POST
=>
true
,
CURLOPT_RETURNTRANSFER
=>
true
)
;
if
(
!
empty
(
$data
)
)
{
if
(
!
empty
(
$data
[
'text'
]
)
&&
substr
(
$data
[
'text'
]
,
0
,
1
)
===
'@'
)
{
$data
[
'text'
]
=
' '
.
$data
[
'text'
]
;
}
$curlConfig
[
CURLOPT_POSTFIELDS
]
=
$data
;
}
curl_setopt_array
(
$ch
,
$curlConfig
)
;
$result
=
curl_exec
(
$ch
)
;
curl_close
(
$ch
)
;
return
!
empty
(
$result
)
?
json_decode
(
$result
,
true
)
:
false
;
}
public
static
function
sendMessage
(
array
$data
)
{
if
(
empty
(
$data
)
)
{
throw
new
TelegramException
(
'Data is empty!'
)
;
}
$result
=
self
::
send
(
'sendMessage'
,
$data
)
;
return
$result
;
}
public
static
function
getMe
(
)
{
$result
=
self
::
send
(
'getMe'
)
;
return
$result
;
}
public
static
function
setWebhook
(
$url
)
{
$result
=
self
::
send
(
'setWebhook'
,
array
(
'url'
=>
$url
)
)
;
return
$result
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 15, 2:48 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
127779
Default Alt Text
Request.php (2 KB)
Attached To
Mode
R123 php-telegram-bot
Attached
Detach File
Event Timeline