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
218359f8
Commit
218359f8
authored
Feb 02, 2018
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow running getUpdates without database connection
parent
f7cac58d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
15 deletions
+27
-15
Telegram.php
src/Telegram.php
+27
-15
No files found.
src/Telegram.php
View file @
218359f8
...
...
@@ -137,6 +137,14 @@ class Telegram
*/
protected
$run_commands
=
false
;
/**
* Last update ID
* Only used when running getUpdates in a loop without database
*
* @var integer
*/
protected
$last_update_id
=
-
1
;
/**
* Telegram constructor.
*
...
...
@@ -320,26 +328,21 @@ class Telegram
throw
new
TelegramException
(
'Bot Username is not defined!'
);
}
if
(
!
DB
::
isDbConnected
())
{
return
new
ServerResponse
(
[
'ok'
=>
false
,
'description'
=>
'getUpdates needs MySQL connection!'
,
],
$this
->
bot_username
);
}
//Take custom input into account.
if
(
$custom_input
=
$this
->
getCustomInput
())
{
$response
=
new
ServerResponse
(
json_decode
(
$custom_input
,
true
),
$this
->
bot_username
);
}
else
{
//DB Query
$last_update
=
DB
::
selectTelegramUpdate
(
1
);
$last_update
=
reset
(
$last_update
);
if
(
DB
::
isDbConnected
())
{
//DB Query
$last_update
=
DB
::
selectTelegramUpdate
(
1
);
$last_update
=
reset
(
$last_update
);
//As explained in the telegram bot api documentation
$offset
=
isset
(
$last_update
[
'id'
])
?
$last_update
[
'id'
]
+
1
:
null
;
//As explained in the telegram bot api documentation
$offset
=
isset
(
$last_update
[
'id'
])
?
$last_update
[
'id'
]
+
1
:
null
;
}
else
{
//Increment variable containing last update_id
$offset
=
$this
->
last_update_id
+
1
;
}
$response
=
Request
::
getUpdates
(
[
...
...
@@ -351,6 +354,15 @@ class Telegram
}
if
(
$response
->
isOk
())
{
// Set last update_id based on returned updates
if
(
!
DB
::
isDbConnected
())
{
$result
=
$response
->
getResult
();
if
(
end
(
$result
))
{
$this
->
last_update_id
=
end
(
$result
)
->
getUpdateId
();
}
}
//Process all updates
/** @var Update $result */
foreach
((
array
)
$response
->
getResult
()
as
$result
)
{
...
...
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