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
4d4cff90
Commit
4d4cff90
authored
Sep 20, 2015
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log bug fixed
parent
e65b0663
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
18 deletions
+23
-18
README.md
README.md
+1
-7
Request.php
src/Request.php
+20
-9
Telegram.php
src/Telegram.php
+2
-2
No files found.
README.md
View file @
4d4cff90
...
...
@@ -177,10 +177,6 @@ You need the database Mysql active.
Create
*getUpdateCLI.php*
(just edit
*example-getUpdateCLI.php*
) and
put into it:
```
php
#!/usr/bin/env php
<?php
$loader
=
require
__DIR__
.
'/vendor/autoload.php'
;
...
...
@@ -217,7 +213,6 @@ in commands, create database and import *structure.sql* and enable
Mysql support after object creation and BEFORE handle method:
```
php
$credentials
=
array
(
'host'
=>
'localhost'
,
'user'
=>
'dbuser'
,
'password'
=>
'dbpass'
,
'database'
=>
'dbname'
);
...
...
@@ -291,8 +286,7 @@ print_r($results);
```
### Logging
You can also log incoming messages on a text file, set this option
with the methods:
You can also log incoming messages on a text file, set this option with the methods:
```
php
$telegram
->
setLogRequests
(
true
);
$telegram
->
setLogPath
(
$BOT_NAME
.
'.log'
);
...
...
src/Request.php
View file @
4d4cff90
...
...
@@ -17,6 +17,7 @@ class Request
{
private
static
$telegram
;
private
static
$input
;
private
static
$input_raw
;
private
static
$server_response
;
private
static
$methods
=
array
(
...
...
@@ -44,25 +45,36 @@ class Request
}
}
public
static
function
setInputRaw
(
$input_raw
)
{
if
(
is_string
(
$input_raw
))
{
self
::
$input_raw
=
$input_raw
;
}
else
{
throw
new
TelegramException
(
"Log input is not a string"
);
}
}
public
static
function
getInput
()
{
if
(
$update
=
self
::
$telegram
->
getCustomUpdate
())
{
self
::
$input
=
$update
;
self
::
setInputRaw
(
$update
)
;
}
else
{
self
::
$input
=
file_get_contents
(
'php://input'
);
self
::
setInputRaw
(
file_get_contents
(
'php://input'
)
);
}
self
::
log
();
return
self
::
$input
;
return
self
::
$input
_raw
;
}
public
static
function
getUpdates
(
$data
)
{
if
(
$update
=
self
::
$telegram
->
getCustomUpdate
())
{
//Cannot be used for testing yet json update have to be converted in a ServerResponse Object
self
::
$input
=
$update
;
}
else
{
self
::
$input
=
self
::
send
(
'getUpdates'
,
$data
);
}
self
::
log
();
//TODO
//In send methods is set input_raw
self
::
log
();
return
self
::
$input
;
}
...
...
@@ -77,7 +89,7 @@ class Request
return
false
;
}
$status
=
file_put_contents
(
$path
,
self
::
$input
.
"
\n
"
,
FILE_APPEND
);
$status
=
file_put_contents
(
$path
,
self
::
$input
_raw
.
"
\n
"
,
FILE_APPEND
);
return
$status
;
}
...
...
@@ -111,9 +123,8 @@ class Request
public
static
function
send
(
$action
,
array
$data
=
null
)
{
if
(
!
in_array
(
$action
,
self
::
$methods
))
{
throw
new
TelegramException
(
'This methods doesn\'t exi
x
t!'
);
throw
new
TelegramException
(
'This methods doesn\'t exi
s
t!'
);
}
if
(
defined
(
'PHPUNIT_TESTSUITE'
))
{
...
...
@@ -145,8 +156,8 @@ class Request
$response
[
'description'
]
=
'Empty server response'
;
$result
=
json_encode
(
$response
);
}
//return $result
;
//For the getUpdate method log
self
::
setInputRaw
(
$result
)
;
$bot_name
=
self
::
$telegram
->
getBotName
();
return
new
ServerResponse
(
json_decode
(
$result
,
true
),
$bot_name
);
...
...
src/Telegram.php
View file @
4d4cff90
...
...
@@ -30,7 +30,7 @@ class Telegram
*
* @var string
*/
protected
$version
=
'0.17.
0
'
;
protected
$version
=
'0.17.
2
'
;
/**
* Telegram API key
...
...
@@ -258,7 +258,7 @@ class Telegram
/**
* Set custom update string for debug purposes
*
* @param string $update
* @param string $update
(json format)
*
* @return \Longman\TelegramBot\Telegram
*/
...
...
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