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
b0e9f7b5
Unverified
Commit
b0e9f7b5
authored
Apr 21, 2018
by
Avtandil Kikabidze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce console kernel class and handle cli update requests
parent
a2f6ee78
Changes
16
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
221 additions
and
161 deletions
+221
-161
ChatsCommand.php
src/Commands/AdminCommands/ChatsCommand.php
+1
-1
CleanupCommand.php
src/Commands/AdminCommands/CleanupCommand.php
+2
-2
SendtoallCommand.php
src/Commands/AdminCommands/SendtoallCommand.php
+3
-3
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+2
-2
WhoisCommand.php
src/Commands/AdminCommands/WhoisCommand.php
+1
-1
Command.php
src/Commands/Command.php
+5
-5
SystemCommand.php
src/Commands/SystemCommand.php
+1
-1
GenericmessageCommand.php
src/Commands/SystemCommands/GenericmessageCommand.php
+2
-2
Kernel.php
src/Console/Kernel.php
+113
-0
PreCheckoutQuery.php
src/Entities/Payments/PreCheckoutQuery.php
+1
-1
ShippingQuery.php
src/Entities/Payments/ShippingQuery.php
+1
-1
Client.php
src/Http/Client.php
+62
-62
Kernel.php
src/Http/Kernel.php
+2
-2
Response.php
src/Http/Response.php
+1
-1
Telegram.php
src/Telegram.php
+13
-66
ServerResponseTest.php
tests/unit/Entities/ServerResponseTest.php
+11
-11
No files found.
src/Commands/AdminCommands/ChatsCommand.php
View file @
b0e9f7b5
...
@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand
...
@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand
/**
/**
* Command execute method
* Command execute method
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
execute
()
public
function
execute
()
...
...
src/Commands/AdminCommands/CleanupCommand.php
View file @
b0e9f7b5
...
@@ -326,7 +326,7 @@ class CleanupCommand extends AdminCommand
...
@@ -326,7 +326,7 @@ class CleanupCommand extends AdminCommand
/**
/**
* Execution if MySQL is required but not available
* Execution if MySQL is required but not available
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
executeNoDb
()
public
function
executeNoDb
()
{
{
...
@@ -345,7 +345,7 @@ class CleanupCommand extends AdminCommand
...
@@ -345,7 +345,7 @@ class CleanupCommand extends AdminCommand
/**
/**
* Command execute method
* Command execute method
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
execute
()
public
function
execute
()
...
...
src/Commands/AdminCommands/SendtoallCommand.php
View file @
b0e9f7b5
...
@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
...
@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use
Longman\TelegramBot\Commands\AdminCommand
;
use
Longman\TelegramBot\Commands\AdminCommand
;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Http\
Server
Response
;
use
Longman\TelegramBot\Http\Response
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Client
;
/**
/**
...
@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand
...
@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand
/**
/**
* Execute command
* Execute command
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
execute
()
public
function
execute
()
...
@@ -59,7 +59,7 @@ class SendtoallCommand extends AdminCommand
...
@@ -59,7 +59,7 @@ class SendtoallCommand extends AdminCommand
return
$this
->
replyToChat
(
'Usage: '
.
$this
->
getUsage
());
return
$this
->
replyToChat
(
'Usage: '
.
$this
->
getUsage
());
}
}
/** @var
Server
Response[] $results */
/** @var Response[] $results */
$results
=
Client
::
sendToActiveChats
(
$results
=
Client
::
sendToActiveChats
(
'sendMessage'
,
//callback function to execute (see Request.php methods)
'sendMessage'
,
//callback function to execute (see Request.php methods)
[
'text'
=>
$text
],
//Param to evaluate the request
[
'text'
=>
$text
],
//Param to evaluate the request
...
...
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
b0e9f7b5
...
@@ -54,7 +54,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -54,7 +54,7 @@ class SendtochannelCommand extends AdminCommand
/**
/**
* Command execute method
* Command execute method
*
*
* @return \Longman\TelegramBot\Http\
Server
Response|mixed
* @return \Longman\TelegramBot\Http\Response|mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
execute
()
public
function
execute
()
...
@@ -275,7 +275,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -275,7 +275,7 @@ class SendtochannelCommand extends AdminCommand
* @param \Longman\TelegramBot\Entities\Message $message
* @param \Longman\TelegramBot\Entities\Message $message
* @param array $data
* @param array $data
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
protected
function
sendBack
(
Message
$message
,
array
$data
)
protected
function
sendBack
(
Message
$message
,
array
$data
)
...
...
src/Commands/AdminCommands/WhoisCommand.php
View file @
b0e9f7b5
...
@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand
...
@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand
/**
/**
* Command execute method
* Command execute method
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
execute
()
public
function
execute
()
...
...
src/Commands/Command.php
View file @
b0e9f7b5
...
@@ -143,7 +143,7 @@ abstract class Command
...
@@ -143,7 +143,7 @@ abstract class Command
/**
/**
* Pre-execute command
* Pre-execute command
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
preExecute
()
public
function
preExecute
()
...
@@ -176,7 +176,7 @@ abstract class Command
...
@@ -176,7 +176,7 @@ abstract class Command
/**
/**
* Execute command
* Execute command
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
abstract
public
function
execute
();
abstract
public
function
execute
();
...
@@ -184,7 +184,7 @@ abstract class Command
...
@@ -184,7 +184,7 @@ abstract class Command
/**
/**
* Execution if MySQL is required but not available
* Execution if MySQL is required but not available
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
executeNoDb
()
public
function
executeNoDb
()
...
@@ -393,7 +393,7 @@ abstract class Command
...
@@ -393,7 +393,7 @@ abstract class Command
* @param string $text
* @param string $text
* @param array $data
* @param array $data
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
replyToChat
(
$text
,
array
$data
=
[])
public
function
replyToChat
(
$text
,
array
$data
=
[])
{
{
...
@@ -413,7 +413,7 @@ abstract class Command
...
@@ -413,7 +413,7 @@ abstract class Command
* @param string $text
* @param string $text
* @param array $data
* @param array $data
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
replyToUser
(
$text
,
array
$data
=
[])
public
function
replyToUser
(
$text
,
array
$data
=
[])
{
{
...
...
src/Commands/SystemCommand.php
View file @
b0e9f7b5
...
@@ -20,7 +20,7 @@ abstract class SystemCommand extends Command
...
@@ -20,7 +20,7 @@ abstract class SystemCommand extends Command
* Although system commands should just work and return a successful ServerResponse,
* Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality.
* each system command can override this method to add custom functionality.
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
...
src/Commands/SystemCommands/GenericmessageCommand.php
View file @
b0e9f7b5
...
@@ -42,7 +42,7 @@ class GenericmessageCommand extends SystemCommand
...
@@ -42,7 +42,7 @@ class GenericmessageCommand extends SystemCommand
/**
/**
* Execution if MySQL is required but not available
* Execution if MySQL is required but not available
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
executeNoDb
()
public
function
executeNoDb
()
{
{
...
@@ -53,7 +53,7 @@ class GenericmessageCommand extends SystemCommand
...
@@ -53,7 +53,7 @@ class GenericmessageCommand extends SystemCommand
/**
/**
* Execute command
* Execute command
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
execute
()
public
function
execute
()
...
...
src/Console/Kernel.php
0 → 100644
View file @
b0e9f7b5
<?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\Console
;
use
Longman\TelegramBot\DB
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Request
;
use
Longman\TelegramBot\Http\Response
;
use
Longman\TelegramBot\Telegram
;
class
Kernel
{
/**
* The application implementation.
*
* @var \Longman\TelegramBot\Telegram
*/
protected
$app
;
/**
* Create a new HTTP kernel instance.
*
* @param \Longman\TelegramBot\Telegram $app
*
* @return void
*/
public
function
__construct
(
Telegram
$app
)
{
$this
->
app
=
$app
;
}
/**
* Handle an incoming HTTP request.
*
* @param \Longman\TelegramBot\Http\Request $request
*
* @param null $limit
* @param null $timeout
* @return \Longman\TelegramBot\Http\Response
*
*/
public
function
handle
(
Request
$request
,
$limit
=
null
,
$timeout
=
null
)
{
if
(
!
DB
::
isDbConnected
()
&&
!
$this
->
app
->
getupdates_without_database
)
{
return
new
Response
(
[
'ok'
=>
false
,
'description'
=>
'getUpdates needs MySQL connection! (This can be overridden - see documentation)'
,
],
$this
->
bot_username
);
}
$offset
=
0
;
//Take custom input into account.
if
(
$custom_input
=
$this
->
app
->
getCustomInput
())
{
$response
=
new
Response
(
json_decode
(
$custom_input
,
true
),
$this
->
app
->
getBotUsername
());
}
else
{
if
(
DB
::
isDbConnected
())
{
//Get last update id from the database
$last_update
=
DB
::
selectTelegramUpdate
(
1
);
$last_update
=
reset
(
$last_update
);
$this
->
app
->
last_update_id
=
isset
(
$last_update
[
'id'
])
?
$last_update
[
'id'
]
:
null
;
}
if
(
$this
->
app
->
last_update_id
!==
null
)
{
$offset
=
$this
->
app
->
last_update_id
+
1
;
//As explained in the telegram bot API documentation
}
$response
=
Client
::
getUpdates
(
[
'offset'
=>
$offset
,
'limit'
=>
$limit
,
'timeout'
=>
$timeout
,
]
);
}
if
(
$response
->
isOk
())
{
$results
=
$response
->
getResult
();
//Process all updates
/** @var Update $result */
foreach
(
$results
as
$result
)
{
$this
->
app
->
processUpdate
(
$result
);
}
if
(
!
DB
::
isDbConnected
()
&&
!
$custom_input
&&
$this
->
app
->
last_update_id
!==
null
&&
$offset
===
0
)
{
//Mark update(s) as read after handling
Client
::
getUpdates
(
[
'offset'
=>
$this
->
app
->
last_update_id
+
1
,
'limit'
=>
1
,
'timeout'
=>
$timeout
,
]
);
}
}
return
$response
;
}
}
src/Entities/Payments/PreCheckoutQuery.php
View file @
b0e9f7b5
...
@@ -48,7 +48,7 @@ class PreCheckoutQuery extends Entity
...
@@ -48,7 +48,7 @@ class PreCheckoutQuery extends Entity
* @param bool $ok
* @param bool $ok
* @param array $data
* @param array $data
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
answer
(
$ok
,
array
$data
=
[])
public
function
answer
(
$ok
,
array
$data
=
[])
{
{
...
...
src/Entities/Payments/ShippingQuery.php
View file @
b0e9f7b5
...
@@ -45,7 +45,7 @@ class ShippingQuery extends Entity
...
@@ -45,7 +45,7 @@ class ShippingQuery extends Entity
* @param bool $ok
* @param bool $ok
* @param array $data
* @param array $data
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
answer
(
$ok
,
array
$data
=
[])
public
function
answer
(
$ok
,
array
$data
=
[])
{
{
...
...
src/Http/Client.php
View file @
b0e9f7b5
This diff is collapsed.
Click to expand it.
src/Http/Kernel.php
View file @
b0e9f7b5
...
@@ -37,9 +37,9 @@ class Kernel
...
@@ -37,9 +37,9 @@ class Kernel
/**
/**
* Handle an incoming HTTP request.
* Handle an incoming HTTP request.
*
*
* @param \Longman\TelegramBot\
Request2
$request
* @param \Longman\TelegramBot\
Http\Request
$request
*
*
* @return \Longman\TelegramBot\Response
* @return \Longman\TelegramBot\
Http\
Response
*
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
...
...
src/Http/
Server
Response.php
→
src/Http/Response.php
View file @
b0e9f7b5
...
@@ -24,7 +24,7 @@ use Longman\TelegramBot\Entities\WebhookInfo;
...
@@ -24,7 +24,7 @@ use Longman\TelegramBot\Entities\WebhookInfo;
*
*
* @todo method ResponseParameters getParameters() Field which can help to automatically handle the error
* @todo method ResponseParameters getParameters() Field which can help to automatically handle the error
*/
*/
class
Server
Response
class
Response
{
{
/**
/**
* ServerResponse constructor.
* ServerResponse constructor.
...
...
src/Telegram.php
View file @
b0e9f7b5
...
@@ -16,12 +16,12 @@ defined('TB_BASE_COMMANDS_PATH') || define('TB_BASE_COMMANDS_PATH', TB_BASE_PATH
...
@@ -16,12 +16,12 @@ defined('TB_BASE_COMMANDS_PATH') || define('TB_BASE_COMMANDS_PATH', TB_BASE_PATH
use
Exception
;
use
Exception
;
use
Illuminate\Container\Container
;
use
Illuminate\Container\Container
;
use
Longman\TelegramBot\Commands\Command
;
use
Longman\TelegramBot\Commands\Command
;
use
Longman\TelegramBot\Console\Kernel
as
ConsoleKernel
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Exception\TelegramException
;
use
Longman\TelegramBot\Exception\TelegramException
;
use
Longman\TelegramBot\Http\Kernel
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Kernel
;
use
Longman\TelegramBot\Http\Request
;
use
Longman\TelegramBot\Http\Request
;
use
Longman\TelegramBot\Http\ServerResponse
;
use
PDO
;
use
PDO
;
use
RecursiveDirectoryIterator
;
use
RecursiveDirectoryIterator
;
use
RecursiveIteratorIterator
;
use
RecursiveIteratorIterator
;
...
@@ -130,7 +130,7 @@ class Telegram extends Container
...
@@ -130,7 +130,7 @@ class Telegram extends Container
/**
/**
* ServerResponse of the last Command execution
* ServerResponse of the last Command execution
*
*
* @var \Longman\TelegramBot\Http\
Server
Response
* @var \Longman\TelegramBot\Http\Response
*/
*/
protected
$last_command_response
;
protected
$last_command_response
;
...
@@ -153,7 +153,7 @@ class Telegram extends Container
...
@@ -153,7 +153,7 @@ class Telegram extends Container
*
*
* @var bool
* @var bool
*/
*/
p
rotected
$getupdates_without_database
=
false
;
p
ublic
$getupdates_without_database
=
false
;
/**
/**
* Last update ID
* Last update ID
...
@@ -161,7 +161,7 @@ class Telegram extends Container
...
@@ -161,7 +161,7 @@ class Telegram extends Container
*
*
* @var integer
* @var integer
*/
*/
p
rotected
$last_update_id
=
null
;
p
ublic
$last_update_id
=
null
;
/**
/**
* Telegram constructor.
* Telegram constructor.
...
@@ -340,7 +340,7 @@ class Telegram extends Container
...
@@ -340,7 +340,7 @@ class Telegram extends Container
/**
/**
* Get the ServerResponse of the last Command execution
* Get the ServerResponse of the last Command execution
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
*/
*/
public
function
getLastCommandResponse
()
public
function
getLastCommandResponse
()
{
{
...
@@ -353,7 +353,7 @@ class Telegram extends Container
...
@@ -353,7 +353,7 @@ class Telegram extends Container
* @param int|null $limit
* @param int|null $limit
* @param int|null $timeout
* @param int|null $timeout
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
handleGetUpdates
(
$limit
=
null
,
$timeout
=
null
)
public
function
handleGetUpdates
(
$limit
=
null
,
$timeout
=
null
)
...
@@ -362,63 +362,10 @@ class Telegram extends Container
...
@@ -362,63 +362,10 @@ class Telegram extends Container
throw
new
TelegramException
(
'Bot Username is not defined!'
);
throw
new
TelegramException
(
'Bot Username is not defined!'
);
}
}
if
(
!
DB
::
isDbConnected
()
&&
!
$this
->
getupdates_without_database
)
{
/** @var \Longman\TelegramBot\Console\Kernel $kernel */
return
new
ServerResponse
(
$kernel
=
$this
->
make
(
ConsoleKernel
::
class
);
[
'ok'
=>
false
,
'description'
=>
'getUpdates needs MySQL connection! (This can be overridden - see documentation)'
,
],
$this
->
bot_username
);
}
$offset
=
0
;
//Take custom input into account.
if
(
$custom_input
=
$this
->
getCustomInput
())
{
$response
=
new
ServerResponse
(
json_decode
(
$custom_input
,
true
),
$this
->
bot_username
);
}
else
{
if
(
DB
::
isDbConnected
())
{
//Get last update id from the database
$last_update
=
DB
::
selectTelegramUpdate
(
1
);
$last_update
=
reset
(
$last_update
);
$this
->
last_update_id
=
isset
(
$last_update
[
'id'
])
?
$last_update
[
'id'
]
:
null
;
}
if
(
$this
->
last_update_id
!==
null
)
{
$offset
=
$this
->
last_update_id
+
1
;
//As explained in the telegram bot API documentation
}
$response
=
Client
::
getUpdates
(
[
'offset'
=>
$offset
,
'limit'
=>
$limit
,
'timeout'
=>
$timeout
,
]
);
}
if
(
$response
->
isOk
())
{
$results
=
$response
->
getResult
();
//Process all updates
$response
=
$kernel
->
handle
(
Request
::
capture
(),
$limit
,
$timeout
);
/** @var Update $result */
foreach
(
$results
as
$result
)
{
$this
->
processUpdate
(
$result
);
}
if
(
!
DB
::
isDbConnected
()
&&
!
$custom_input
&&
$this
->
last_update_id
!==
null
&&
$offset
===
0
)
{
//Mark update(s) as read after handling
Client
::
getUpdates
(
[
'offset'
=>
$this
->
last_update_id
+
1
,
'limit'
=>
1
,
'timeout'
=>
$timeout
,
]
);
}
}
return
$response
;
return
$response
;
}
}
...
@@ -461,7 +408,7 @@ class Telegram extends Container
...
@@ -461,7 +408,7 @@ class Telegram extends Container
*
*
* @param \Longman\TelegramBot\Entities\Update $update
* @param \Longman\TelegramBot\Entities\Update $update
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
processUpdate
(
Update
$update
)
public
function
processUpdate
(
Update
$update
)
...
@@ -833,7 +780,7 @@ class Telegram extends Container
...
@@ -833,7 +780,7 @@ class Telegram extends Container
*/
*/
public
function
getVersion
()
public
function
getVersion
()
{
{
return
$this
->
version
;
return
self
::
VERSION
;
}
}
/**
/**
...
@@ -842,7 +789,7 @@ class Telegram extends Container
...
@@ -842,7 +789,7 @@ class Telegram extends Container
* @param string $url
* @param string $url
* @param array $data Optional parameters.
* @param array $data Optional parameters.
*
*
* @return \Longman\TelegramBot\Http\
Server
Response
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
setWebhook
(
$url
,
array
$data
=
[])
public
function
setWebhook
(
$url
,
array
$data
=
[])
...
...
tests/unit/Entities/ServerResponseTest.php
View file @
b0e9f7b5
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
namespace
Longman\TelegramBot\Tests\Unit
;
namespace
Longman\TelegramBot\Tests\Unit
;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Http\
Server
Response
;
use
Longman\TelegramBot\Http\Response
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Client
;
/**
/**
...
@@ -42,7 +42,7 @@ class ServerResponseTest extends TestCase
...
@@ -42,7 +42,7 @@ class ServerResponseTest extends TestCase
public
function
testSendMessageOk
()
public
function
testSendMessageOk
()
{
{
$result
=
$this
->
sendMessageOk
();
$result
=
$this
->
sendMessageOk
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server_result
=
$server
->
getResult
();
$server_result
=
$server
->
getResult
();
self
::
assertTrue
(
$server
->
isOk
());
self
::
assertTrue
(
$server
->
isOk
());
...
@@ -76,7 +76,7 @@ class ServerResponseTest extends TestCase
...
@@ -76,7 +76,7 @@ class ServerResponseTest extends TestCase
public
function
testSendMessageFail
()
public
function
testSendMessageFail
()
{
{
$result
=
$this
->
sendMessageFail
();
$result
=
$this
->
sendMessageFail
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
self
::
assertFalse
(
$server
->
isOk
());
self
::
assertFalse
(
$server
->
isOk
());
self
::
assertNull
(
$server
->
getResult
());
self
::
assertNull
(
$server
->
getResult
());
...
@@ -92,7 +92,7 @@ class ServerResponseTest extends TestCase
...
@@ -92,7 +92,7 @@ class ServerResponseTest extends TestCase
public
function
testSetWebhookOk
()
public
function
testSetWebhookOk
()
{
{
$result
=
$this
->
setWebhookOk
();
$result
=
$this
->
setWebhookOk
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
self
::
assertTrue
(
$server
->
isOk
());
self
::
assertTrue
(
$server
->
isOk
());
self
::
assertTrue
(
$server
->
getResult
());
self
::
assertTrue
(
$server
->
getResult
());
...
@@ -112,7 +112,7 @@ class ServerResponseTest extends TestCase
...
@@ -112,7 +112,7 @@ class ServerResponseTest extends TestCase
public
function
testSetWebhookFail
()
public
function
testSetWebhookFail
()
{
{
$result
=
$this
->
setWebhookFail
();
$result
=
$this
->
setWebhookFail
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
self
::
assertFalse
(
$server
->
isOk
());
self
::
assertFalse
(
$server
->
isOk
());
self
::
assertNull
(
$server
->
getResult
());
self
::
assertNull
(
$server
->
getResult
());
...
@@ -172,7 +172,7 @@ class ServerResponseTest extends TestCase
...
@@ -172,7 +172,7 @@ class ServerResponseTest extends TestCase
public
function
testGetUpdatesArray
()
public
function
testGetUpdatesArray
()
{
{
$result
=
$this
->
getUpdatesArray
();
$result
=
$this
->
getUpdatesArray
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
self
::
assertCount
(
4
,
$server
->
getResult
());
self
::
assertCount
(
4
,
$server
->
getResult
());
self
::
assertInstanceOf
(
'\Longman\TelegramBot\Entities\Update'
,
$server
->
getResult
()[
0
]);
self
::
assertInstanceOf
(
'\Longman\TelegramBot\Entities\Update'
,
$server
->
getResult
()[
0
]);
...
@@ -186,7 +186,7 @@ class ServerResponseTest extends TestCase
...
@@ -186,7 +186,7 @@ class ServerResponseTest extends TestCase
public
function
testGetUpdatesEmpty
()
public
function
testGetUpdatesEmpty
()
{
{
$result
=
$this
->
getUpdatesEmpty
();
$result
=
$this
->
getUpdatesEmpty
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
self
::
assertEmpty
(
$server
->
getResult
());
self
::
assertEmpty
(
$server
->
getResult
());
}
}
...
@@ -221,7 +221,7 @@ class ServerResponseTest extends TestCase
...
@@ -221,7 +221,7 @@ class ServerResponseTest extends TestCase
public
function
testGetUserProfilePhotos
()
public
function
testGetUserProfilePhotos
()
{
{
$result
=
$this
->
getUserProfilePhotos
();
$result
=
$this
->
getUserProfilePhotos
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server_result
=
$server
->
getResult
();
$server_result
=
$server
->
getResult
();
$photos
=
$server_result
->
getPhotos
();
$photos
=
$server_result
->
getPhotos
();
...
@@ -251,7 +251,7 @@ class ServerResponseTest extends TestCase
...
@@ -251,7 +251,7 @@ class ServerResponseTest extends TestCase
public
function
testGetFile
()
public
function
testGetFile
()
{
{
$result
=
$this
->
getFile
();
$result
=
$this
->
getFile
();
$server
=
new
Server
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
$server
=
new
Response
(
json_decode
(
$result
,
true
),
'testbot'
);
self
::
assertInstanceOf
(
'\Longman\TelegramBot\Entities\File'
,
$server
->
getResult
());
self
::
assertInstanceOf
(
'\Longman\TelegramBot\Entities\File'
,
$server
->
getResult
());
}
}
...
@@ -261,7 +261,7 @@ class ServerResponseTest extends TestCase
...
@@ -261,7 +261,7 @@ class ServerResponseTest extends TestCase
//setWebhook ok
//setWebhook ok
$fake_response
=
Client
::
generateGeneralFakeServerResponse
();
$fake_response
=
Client
::
generateGeneralFakeServerResponse
();
$server
=
new
Server
Response
(
$fake_response
,
'testbot'
);
$server
=
new
Response
(
$fake_response
,
'testbot'
);
self
::
assertTrue
(
$server
->
isOk
());
self
::
assertTrue
(
$server
->
isOk
());
self
::
assertTrue
(
$server
->
getResult
());
self
::
assertTrue
(
$server
->
getResult
());
...
@@ -271,7 +271,7 @@ class ServerResponseTest extends TestCase
...
@@ -271,7 +271,7 @@ class ServerResponseTest extends TestCase
//sendMessage ok
//sendMessage ok
$fake_response
=
Client
::
generateGeneralFakeServerResponse
([
'chat_id'
=>
123456789
,
'text'
=>
'hello'
]);
$fake_response
=
Client
::
generateGeneralFakeServerResponse
([
'chat_id'
=>
123456789
,
'text'
=>
'hello'
]);
$server
=
new
Server
Response
(
$fake_response
,
'testbot'
);
$server
=
new
Response
(
$fake_response
,
'testbot'
);
/** @var Message $server_result */
/** @var Message $server_result */
$server_result
=
$server
->
getResult
();
$server_result
=
$server
->
getResult
();
...
...
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