Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
38becee6
Unverified
Commit
38becee6
authored
Aug 27, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Smaller refactorings and DocBlock adjustments.
parent
12f46a2b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
+24
-15
Request.php
src/Request.php
+24
-15
No files found.
src/Request.php
View file @
38becee6
...
@@ -87,6 +87,7 @@ class Request
...
@@ -87,6 +87,7 @@ class Request
* Initialize
* Initialize
*
*
* @param \Longman\TelegramBot\Telegram $telegram
* @param \Longman\TelegramBot\Telegram $telegram
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
static
function
initialize
(
Telegram
$telegram
)
public
static
function
initialize
(
Telegram
$telegram
)
...
@@ -120,6 +121,7 @@ class Request
...
@@ -120,6 +121,7 @@ class Request
}
}
TelegramLog
::
update
(
self
::
$input
);
TelegramLog
::
update
(
self
::
$input
);
return
self
::
$input
;
return
self
::
$input
;
}
}
...
@@ -140,7 +142,7 @@ class Request
...
@@ -140,7 +142,7 @@ class Request
$fake_response
=
[
'ok'
=>
true
];
// :)
$fake_response
=
[
'ok'
=>
true
];
// :)
if
(
!
isset
(
$data
)
)
{
if
(
$data
===
null
)
{
$fake_response
[
'result'
]
=
true
;
$fake_response
[
'result'
]
=
true
;
}
}
...
@@ -176,7 +178,7 @@ class Request
...
@@ -176,7 +178,7 @@ class Request
//Fix so that the keyboard markup is a string, not an object
//Fix so that the keyboard markup is a string, not an object
if
(
isset
(
$data
[
'reply_markup'
])
&&
!
is_string
(
$data
[
'reply_markup'
]))
{
if
(
isset
(
$data
[
'reply_markup'
])
&&
!
is_string
(
$data
[
'reply_markup'
]))
{
$data
[
'reply_markup'
]
=
(
string
)
$data
[
'reply_markup'
];
$data
[
'reply_markup'
]
=
(
string
)
$data
[
'reply_markup'
];
}
}
$request_params
=
[
'debug'
=>
$debug_handle
];
$request_params
=
[
'debug'
=>
$debug_handle
];
...
@@ -193,17 +195,18 @@ class Request
...
@@ -193,17 +195,18 @@ class Request
//Reformat data array in multipart way
//Reformat data array in multipart way
if
(
$contains_resource
)
{
if
(
$contains_resource
)
{
foreach
(
$data
as
$key
=>
$item
)
{
foreach
(
$data
as
$key
=>
$item
)
{
$request_params
[
'multipart'
][]
=
array
(
'name'
=>
$key
,
'contents'
=>
$item
)
;
$request_params
[
'multipart'
][]
=
[
'name'
=>
$key
,
'contents'
=>
$item
]
;
}
}
}
else
{
}
else
{
$request_params
[
'form_params'
]
=
$data
;
$request_params
[
'form_params'
]
=
$data
;
}
}
$result
=
''
;
try
{
try
{
$res
ponse
=
self
::
$client
->
post
(
$res
ult
=
(
string
)
self
::
$client
->
post
(
'/bot'
.
self
::
$telegram
->
getApiKey
()
.
'/'
.
$action
,
'/bot'
.
self
::
$telegram
->
getApiKey
()
.
'/'
.
$action
,
$request_params
$request_params
);
)
->
getBody
()
;
}
catch
(
RequestException
$e
)
{
}
catch
(
RequestException
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
throw
new
TelegramException
(
$e
->
getMessage
());
}
finally
{
}
finally
{
...
@@ -211,8 +214,6 @@ class Request
...
@@ -211,8 +214,6 @@ class Request
TelegramLog
::
endDebugLogTempStream
(
"Verbose HTTP Request output:
\n
%s
\n
"
);
TelegramLog
::
endDebugLogTempStream
(
"Verbose HTTP Request output:
\n
%s
\n
"
);
}
}
$result
=
$response
->
getBody
();
//Logging getUpdates Update
//Logging getUpdates Update
if
(
$action
===
'getUpdates'
)
{
if
(
$action
===
'getUpdates'
)
{
TelegramLog
::
update
(
$result
);
TelegramLog
::
update
(
$result
);
...
@@ -224,7 +225,7 @@ class Request
...
@@ -224,7 +225,7 @@ class Request
/**
/**
* Download file
* Download file
*
*
* @param Entities\File $file
* @param
\Longman\TelegramBot\
Entities\File $file
*
*
* @return boolean
* @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
...
@@ -244,7 +245,7 @@ class Request
...
@@ -244,7 +245,7 @@ class Request
$debug_handle
=
TelegramLog
::
getDebugLogTempStream
();
$debug_handle
=
TelegramLog
::
getDebugLogTempStream
();
try
{
try
{
$response
=
self
::
$client
->
get
(
self
::
$client
->
get
(
'/file/bot'
.
self
::
$telegram
->
getApiKey
()
.
'/'
.
$path
,
'/file/bot'
.
self
::
$telegram
->
getApiKey
()
.
'/'
.
$path
,
[
'debug'
=>
$debug_handle
,
'sink'
=>
$loc_path
]
[
'debug'
=>
$debug_handle
,
'sink'
=>
$loc_path
]
);
);
...
@@ -272,6 +273,7 @@ class Request
...
@@ -272,6 +273,7 @@ class Request
if
(
$fp
===
false
)
{
if
(
$fp
===
false
)
{
throw
new
TelegramException
(
'Cannot open '
.
$file
.
' for reading'
);
throw
new
TelegramException
(
'Cannot open '
.
$file
.
' for reading'
);
}
}
return
$fp
;
return
$fp
;
}
}
...
@@ -294,6 +296,7 @@ class Request
...
@@ -294,6 +296,7 @@ class Request
if
(
defined
(
'PHPUNIT_TESTSUITE'
))
{
if
(
defined
(
'PHPUNIT_TESTSUITE'
))
{
$fake_response
=
self
::
generateGeneralFakeServerResponse
(
$data
);
$fake_response
=
self
::
generateGeneralFakeServerResponse
(
$data
);
return
new
ServerResponse
(
$fake_response
,
$bot_name
);
return
new
ServerResponse
(
$fake_response
,
$bot_name
);
}
}
...
@@ -301,8 +304,8 @@ class Request
...
@@ -301,8 +304,8 @@ class Request
$response
=
json_decode
(
self
::
execute
(
$action
,
$data
),
true
);
$response
=
json_decode
(
self
::
execute
(
$action
,
$data
),
true
);
if
(
is_null
(
$response
)
)
{
if
(
null
===
$response
)
{
throw
new
TelegramException
(
'Telegram returned an invalid response! Please
your bot name and api token
.'
);
throw
new
TelegramException
(
'Telegram returned an invalid response! Please
review your bot name and API key
.'
);
}
}
return
new
ServerResponse
(
$response
,
$bot_name
);
return
new
ServerResponse
(
$response
,
$bot_name
);
...
@@ -356,6 +359,7 @@ class Request
...
@@ -356,6 +359,7 @@ class Request
* Get me
* Get me
*
*
* @return mixed
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
static
function
getMe
()
public
static
function
getMe
()
{
{
...
@@ -573,6 +577,7 @@ class Request
...
@@ -573,6 +577,7 @@ class Request
* @param array $data
* @param array $data
*
*
* @return mixed
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
static
function
getUpdates
(
array
$data
)
public
static
function
getUpdates
(
array
$data
)
{
{
...
@@ -586,6 +591,7 @@ class Request
...
@@ -586,6 +591,7 @@ class Request
* @param string $file
* @param string $file
*
*
* @return mixed
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
static
function
setWebhook
(
$url
=
''
,
$file
=
null
)
public
static
function
setWebhook
(
$url
=
''
,
$file
=
null
)
{
{
...
@@ -779,7 +785,8 @@ class Request
...
@@ -779,7 +785,8 @@ class Request
* No request to telegram are sent, this function is used in commands that
* No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution
* don't need to fire a message after execution
*
*
* @return Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
static
function
emptyResponse
()
public
static
function
emptyResponse
()
{
{
...
@@ -817,9 +824,11 @@ class Request
...
@@ -817,9 +824,11 @@ class Request
$chats
=
DB
::
selectChats
(
$send_groups
,
$send_super_groups
,
$send_users
,
$date_from
,
$date_to
);
$chats
=
DB
::
selectChats
(
$send_groups
,
$send_super_groups
,
$send_users
,
$date_from
,
$date_to
);
$results
=
[];
$results
=
[];
foreach
(
$chats
as
$row
)
{
if
(
is_array
(
$chats
))
{
$data
[
'chat_id'
]
=
$row
[
'chat_id'
];
foreach
(
$chats
as
$row
)
{
$results
[]
=
call_user_func_array
(
$callback_path
.
'::'
.
$callback_function
,
[
$data
]);
$data
[
'chat_id'
]
=
$row
[
'chat_id'
];
$results
[]
=
call_user_func_array
(
$callback_path
.
'::'
.
$callback_function
,
[
$data
]);
}
}
}
return
$results
;
return
$results
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment