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
ca48e792
Commit
ca48e792
authored
Apr 06, 2017
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename variables 'bot_name' and similar to 'bot_username' to prevent confusion
parent
b2ec9768
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
56 additions
and
42 deletions
+56
-42
getUpdatesCLI.php
examples/getUpdatesCLI.php
+2
-2
hook.php
examples/hook.php
+2
-2
set.php
examples/set.php
+3
-2
unset.php
examples/unset.php
+3
-2
Entity.php
src/Entities/Entity.php
+5
-5
Message.php
src/Entities/Message.php
+3
-3
ReplyToMessage.php
src/Entities/ReplyToMessage.php
+3
-3
ServerResponse.php
src/Entities/ServerResponse.php
+11
-11
Request.php
src/Request.php
+3
-3
Telegram.php
src/Telegram.php
+21
-9
No files found.
examples/getUpdatesCLI.php
View file @
ca48e792
...
...
@@ -14,7 +14,7 @@ require __DIR__ . '/vendor/autoload.php';
// Add you bot's API key and name
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'username_bot'
;
$BOT_
USER
NAME
=
'username_bot'
;
// Define a path for your custom commands
//$commands_path = __DIR__ . '/Commands/';
...
...
@@ -29,7 +29,7 @@ $mysql_credentials = [
try
{
// Create Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_
USER
NAME
);
// Error, Debug and Raw Update logging
//Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
...
...
examples/hook.php
View file @
ca48e792
...
...
@@ -13,7 +13,7 @@ require __DIR__ . '/vendor/autoload.php';
// Add you bot's API key and name
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'username_bot'
;
$BOT_
USER
NAME
=
'username_bot'
;
// Define a path for your custom commands
//$commands_path = __DIR__ . '/Commands/';
...
...
@@ -28,7 +28,7 @@ $BOT_NAME = 'username_bot';
try
{
// Create Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_
USER
NAME
);
// Error, Debug and Raw Update logging
//Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
...
...
examples/set.php
View file @
ca48e792
...
...
@@ -3,11 +3,12 @@
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'username_bot'
;
$BOT_
USER
NAME
=
'username_bot'
;
$hook_url
=
'https://yourdomain/path/to/hook.php'
;
try
{
// Create Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_
USER
NAME
);
// Set webhook
$result
=
$telegram
->
setWebhook
(
$hook_url
);
...
...
examples/unset.php
View file @
ca48e792
...
...
@@ -3,10 +3,11 @@
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'username_bot'
;
$BOT_USERNAME
=
'username_bot'
;
try
{
// Create Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_
USER
NAME
);
// Delete webhook
$result
=
$telegram
->
deleteWebhook
();
...
...
src/Entities/Entity.php
View file @
ca48e792
...
...
@@ -29,14 +29,14 @@ abstract class Entity
/**
* Entity constructor.
*
* @todo Get rid of the $bot_name, it shouldn't be here!
* @todo Get rid of the $bot_
user
name, it shouldn't be here!
*
* @param array $data
* @param string $bot_name
* @param string $bot_
user
name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
__construct
(
$data
,
$bot_name
=
''
)
public
function
__construct
(
$data
,
$bot_
user
name
=
''
)
{
//Make sure we're not raw_data inception-ing
if
(
array_key_exists
(
'raw_data'
,
$data
))
{
...
...
@@ -47,7 +47,7 @@ abstract class Entity
$data
[
'raw_data'
]
=
$data
;
}
$data
[
'bot_
name'
]
=
$bot_
name
;
$data
[
'bot_
username'
]
=
$bot_user
name
;
$this
->
assignMemberVariables
(
$data
);
$this
->
validate
();
}
...
...
@@ -142,7 +142,7 @@ abstract class Entity
$sub_entities
=
$this
->
subEntities
();
if
(
isset
(
$sub_entities
[
$property_name
]))
{
return
new
$sub_entities
[
$property_name
](
$property
,
$this
->
getProperty
(
'bot_name'
));
return
new
$sub_entities
[
$property_name
](
$property
,
$this
->
getProperty
(
'bot_
user
name'
));
}
return
$property
;
...
...
src/Entities/Message.php
View file @
ca48e792
...
...
@@ -79,11 +79,11 @@ class Message extends Entity
* Message constructor
*
* @param array $data
* @param string $bot_name
* @param string $bot_
user
name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
__construct
(
array
$data
,
$bot_name
=
''
)
public
function
__construct
(
array
$data
,
$bot_
user
name
=
''
)
{
//Retro-compatibility
if
(
isset
(
$data
[
'new_chat_participant'
]))
{
...
...
@@ -95,7 +95,7 @@ class Message extends Entity
unset
(
$data
[
'left_chat_participant'
]);
}
parent
::
__construct
(
$data
,
$bot_name
);
parent
::
__construct
(
$data
,
$bot_
user
name
);
}
/**
...
...
src/Entities/ReplyToMessage.php
View file @
ca48e792
...
...
@@ -21,16 +21,16 @@ class ReplyToMessage extends Message
* ReplyToMessage constructor.
*
* @param array $data
* @param string $bot_name
* @param string $bot_
user
name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
__construct
(
array
$data
,
$bot_name
=
''
)
public
function
__construct
(
array
$data
,
$bot_
user
name
=
''
)
{
//As explained in the documentation
//Reply to message can't contain other reply to message entities
unset
(
$data
[
'reply_to_message'
]);
parent
::
__construct
(
$data
,
$bot_name
);
parent
::
__construct
(
$data
,
$bot_
user
name
);
}
}
src/Entities/ServerResponse.php
View file @
ca48e792
...
...
@@ -26,11 +26,11 @@ class ServerResponse extends Entity
* ServerResponse constructor.
*
* @param array $data
* @param string $bot_name
* @param string $bot_
user
name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
__construct
(
array
$data
,
$bot_name
)
public
function
__construct
(
array
$data
,
$bot_
user
name
)
{
// Make sure we don't double-save the raw_data
unset
(
$data
[
'raw_data'
]);
...
...
@@ -41,13 +41,13 @@ class ServerResponse extends Entity
if
(
$is_ok
&&
is_array
(
$result
))
{
if
(
$this
->
isAssoc
(
$result
))
{
$data
[
'result'
]
=
$this
->
createResultObject
(
$result
,
$bot_name
);
$data
[
'result'
]
=
$this
->
createResultObject
(
$result
,
$bot_
user
name
);
}
else
{
$data
[
'result'
]
=
$this
->
createResultObjects
(
$result
,
$bot_name
);
$data
[
'result'
]
=
$this
->
createResultObjects
(
$result
,
$bot_
user
name
);
}
}
parent
::
__construct
(
$data
,
$bot_name
);
parent
::
__construct
(
$data
,
$bot_
user
name
);
}
/**
...
...
@@ -88,12 +88,12 @@ class ServerResponse extends Entity
* Create and return the object of the received result
*
* @param array $result
* @param string $bot_name
* @param string $bot_
user
name
*
* @return \Longman\TelegramBot\Entities\Chat|\Longman\TelegramBot\Entities\ChatMember|\Longman\TelegramBot\Entities\File|\Longman\TelegramBot\Entities\Message|\Longman\TelegramBot\Entities\User|\Longman\TelegramBot\Entities\UserProfilePhotos|\Longman\TelegramBot\Entities\WebhookInfo
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private
function
createResultObject
(
$result
,
$bot_name
)
private
function
createResultObject
(
$result
,
$bot_
user
name
)
{
// We don't need to save the raw_data of the response object!
$result
[
'raw_data'
]
=
null
;
...
...
@@ -115,19 +115,19 @@ class ServerResponse extends Entity
}
//Response from sendMessage
return
new
Message
(
$result
,
$bot_name
);
return
new
Message
(
$result
,
$bot_
user
name
);
}
/**
* Create and return the objects array of the received result
*
* @param array $result
* @param string $bot_name
* @param string $bot_
user
name
*
* @return null|\Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Update[]
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private
function
createResultObjects
(
$result
,
$bot_name
)
private
function
createResultObjects
(
$result
,
$bot_
user
name
)
{
$results
=
[];
if
(
isset
(
$result
[
0
][
'user'
]))
{
...
...
@@ -144,7 +144,7 @@ class ServerResponse extends Entity
// We don't need to save the raw_data of the response object!
$update
[
'raw_data'
]
=
null
;
$results
[]
=
new
Update
(
$update
,
$bot_name
);
$results
[]
=
new
Update
(
$update
,
$bot_
user
name
);
}
}
...
...
src/Request.php
View file @
ca48e792
...
...
@@ -315,12 +315,12 @@ class Request
{
self
::
ensureValidAction
(
$action
);
$bot_
name
=
self
::
$telegram
->
getBotN
ame
();
$bot_
username
=
self
::
$telegram
->
getBotUsern
ame
();
if
(
defined
(
'PHPUNIT_TESTSUITE'
))
{
$fake_response
=
self
::
generateGeneralFakeServerResponse
(
$data
);
return
new
ServerResponse
(
$fake_response
,
$bot_name
);
return
new
ServerResponse
(
$fake_response
,
$bot_
user
name
);
}
self
::
ensureNonEmptyData
(
$data
);
...
...
@@ -333,7 +333,7 @@ class Request
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_
user
name
);
}
/**
...
...
src/Telegram.php
View file @
ca48e792
...
...
@@ -40,11 +40,11 @@ class Telegram
protected
$api_key
=
''
;
/**
* Telegram Bot name
* Telegram Bot
user
name
*
* @var string
*/
protected
$bot_name
=
''
;
protected
$bot_
user
name
=
''
;
/**
* Telegram Bot id
...
...
@@ -134,22 +134,22 @@ class Telegram
* Telegram constructor.
*
* @param string $api_key
* @param string $bot_name
* @param string $bot_
user
name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
__construct
(
$api_key
,
$bot_name
)
public
function
__construct
(
$api_key
,
$bot_
user
name
)
{
if
(
empty
(
$api_key
))
{
throw
new
TelegramException
(
'API KEY not defined!'
);
}
if
(
empty
(
$bot_name
))
{
if
(
empty
(
$bot_
user
name
))
{
throw
new
TelegramException
(
'Bot Username not defined!'
);
}
$this
->
api_key
=
$api_key
;
$this
->
bot_
name
=
$bot_
name
;
$this
->
bot_
username
=
$bot_user
name
;
preg_match
(
"/([0-9]*)\:.*/"
,
$this
->
api_key
,
$matches
);
$this
->
bot_id
=
$matches
[
1
];
...
...
@@ -319,7 +319,7 @@ class Telegram
'ok'
=>
false
,
'description'
=>
'getUpdates needs MySQL connection!'
,
],
$this
->
bot_name
$this
->
bot_
user
name
);
}
...
...
@@ -369,7 +369,7 @@ class Telegram
throw
new
TelegramException
(
'Invalid JSON!'
);
}
if
(
$response
=
$this
->
processUpdate
(
new
Update
(
$post
,
$this
->
bot_name
)))
{
if
(
$response
=
$this
->
processUpdate
(
new
Update
(
$post
,
$this
->
bot_
user
name
)))
{
return
$response
->
isOk
();
}
...
...
@@ -733,9 +733,21 @@ class Telegram
*
* @return string
*/
public
function
getBotUsername
()
{
return
$this
->
bot_username
;
}
/**
* Get Bot name
* @todo: Left for backwards compatibility, remove in the future
*
* @return string
*/
public
function
getBotName
()
{
return
$this
->
bot_name
;
TelegramLog
::
debug
(
'Usage of deprecated method getBotName() detected, please use getBotUsername() instead!'
);
return
$this
->
getBotUsername
();
}
/**
...
...
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