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
cfb663e8
Commit
cfb663e8
authored
Jul 04, 2015
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for command like /command@bot1
parent
3a579eab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
16 deletions
+57
-16
README.md
README.md
+6
-5
Message.php
src/Entities/Message.php
+26
-7
Update.php
src/Entities/Update.php
+4
-2
Telegram.php
src/Telegram.php
+21
-2
No files found.
README.md
View file @
cfb663e8
...
...
@@ -88,12 +88,13 @@ Create set.php and put:
$loader
=
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'namebot'
;
// create Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
);
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
// set webhook
$telegram
->
setWebHook
(
'https://yourdomain/yourpath_to_hook.php'
);
echo
$telegram
->
setWebHook
(
'https://yourdomain/yourpath_to_hook.php'
);
```
...
...
@@ -104,9 +105,9 @@ After create hook.php and put:
$loader
=
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'namebot'
;
// create Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
);
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
// handle telegram webhook request
$telegram
->
handle
();
...
...
@@ -136,4 +137,4 @@ If you like living on the edge, please report any bugs you find on the [PHP Tele
Created by
[
Avtandil Kikabidze
][
1
]
.
[
0
]:
https://github.com/akalongman/php-telegram-bot
[
1
]:
mailto:akalongman@gmail.com
\ No newline at end of file
[
1
]:
mailto:akalongman@gmail.com
src/Entities/Message.php
View file @
cfb663e8
...
...
@@ -59,8 +59,11 @@ class Message extends Entity
protected
$_command
;
protected
$bot_name
;
public
function
__construct
(
array
$data
)
{
publicfunction
__construct
(
array
$data
,
$bot_name
)
{
$this
->
bot_name
=
$bot_name
;
$this
->
message_id
=
isset
(
$data
[
'message_id'
])
?
$data
[
'message_id'
]
:
null
;
if
(
empty
(
$this
->
message_id
))
{
...
...
@@ -102,7 +105,12 @@ class Message extends Entity
}
}
//return the entire command like /echo or /echo@bot1 if specified
public
function
getFullCommand
(){
return
strtok
(
$this
->
text
,
' '
);
}
public
function
getCommand
()
{
...
...
@@ -110,13 +118,24 @@ class Message extends Entity
return
$this
->
_command
;
}
$cmd
=
strtok
(
$this
->
text
,
' '
);
$cmd
=
$this
->
getFullCommand
();
if
(
substr
(
$cmd
,
0
,
1
)
===
'/'
)
{
$cmd
=
substr
(
$cmd
,
1
);
return
$this
->
_command
=
$cmd
;
//check if command is follow by botname
$split_cmd
=
explode
(
'@'
,
$cmd
);
if
(
isset
(
$split_cmd
[
1
])){
//command is followed by name check if is addressed to me
if
(
strtolower
(
$split_cmd
[
1
])
==
strtolower
(
$this
->
bot_name
)){
return
$this
->
_command
=
$split_cmd
[
0
];
}
}
else
{
//command is not followed by name
return
$this
->
_command
=
$cmd
;
}
}
return
false
;
}
...
...
@@ -162,8 +181,8 @@ class Message extends Entity
public
function
getText
(
$without_cmd
=
false
)
{
$text
=
$this
->
text
;
if
(
$without_cmd
)
{
$command
=
$this
->
getCommand
();
$text
=
substr
(
$text
,
strlen
(
'/'
.
$command
.
' '
),
strlen
(
$text
));
$command
=
$this
->
get
Full
Command
();
$text
=
substr
(
$text
,
strlen
(
$command
.
' '
),
strlen
(
$text
));
}
return
$text
;
...
...
src/Entities/Update.php
View file @
cfb663e8
...
...
@@ -17,11 +17,12 @@ class Update extends Entity
protected
$update_id
;
protected
$message
;
protected
$bot_name
;
public
function
__construct
(
array
$data
)
{
public
function
__construct
(
array
$data
,
$bot_name
)
{
$update_id
=
isset
(
$data
[
'update_id'
])
?
$data
[
'update_id'
]
:
null
;
...
...
@@ -31,8 +32,9 @@ class Update extends Entity
throw
new
\Exception
(
'update_id is empty!'
);
}
$this
->
bot_name
=
$bot_name
;
$this
->
update_id
=
$update_id
;
$this
->
message
=
new
Message
(
$message
);
$this
->
message
=
new
Message
(
$message
,
$bot_name
);
}
...
...
src/Telegram.php
View file @
cfb663e8
...
...
@@ -37,6 +37,14 @@ class Telegram
*/
protected
$api_key
=
''
;
/**
* Telegram API name
*
* @var string
*/
protected
$bot_name
=
''
;
/**
* Raw request data
*
...
...
@@ -101,8 +109,10 @@ class Telegram
*
* @param string $api_key
*/
public
function
__construct
(
$api_key
)
{
public
function
__construct
(
$api_key
,
$bot_name
)
{
$this
->
api_key
=
$api_key
;
$this
->
bot_name
=
$bot_name
;
Request
::
initialize
(
$this
);
}
...
...
@@ -220,7 +230,7 @@ class Telegram
}
$update
=
new
Update
(
$post
);
$update
=
new
Update
(
$post
,
$this
->
bot_name
);
$this
->
insertRequest
(
$update
);
...
...
@@ -374,6 +384,15 @@ class Telegram
return
$this
->
api_key
;
}
/**
* Get BOT NAME
*
* @return string
*/
public
function
getBotName
()
{
return
$this
->
bot_name
;
}
/**
* Set Webhook for bot
*
...
...
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