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
34ad296b
Commit
34ad296b
authored
Dec 26, 2016
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Botan integration improvements
parent
1c54e2c0
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
199 additions
and
97 deletions
+199
-97
ShortenerCommand.php
examples/Commands/ShortenerCommand.php
+49
-0
getUpdatesCLI.php
examples/getUpdatesCLI.php
+2
-0
hook.php
examples/hook.php
+2
-0
Botan.php
src/Botan.php
+131
-91
BotanDB.php
src/BotanDB.php
+10
-2
Telegram.php
src/Telegram.php
+5
-4
No files found.
examples/Commands/ShortenerCommand.php
0 → 100644
View file @
34ad296b
<?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\Commands\UserCommands
;
use
Longman\TelegramBot\Botan
;
use
Longman\TelegramBot\Commands\UserCommand
;
use
Longman\TelegramBot\Request
;
/**
* User "/shortener" command
*/
class
ShortenerCommand
extends
UserCommand
{
/**#@+
* {@inheritdoc}
*/
protected
$name
=
'shortener'
;
protected
$description
=
'Botan Shortener example'
;
protected
$usage
=
'/shortener'
;
protected
$version
=
'1.0.0'
;
/**#@-*/
/**
* {@inheritdoc}
*/
public
function
execute
()
{
$message
=
$this
->
getMessage
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$user_id
=
$message
->
getFrom
()
->
getId
();
$data
=
[];
$data
[
'chat_id'
]
=
$chat_id
;
$text
=
Botan
::
shortenUrl
(
"https://github.com/akalongman/php-telegram-bot"
,
$user_id
);
$data
[
'text'
]
=
$text
;
return
Request
::
sendMessage
(
$data
);
}
}
examples/getUpdatesCLI.php
View file @
34ad296b
...
...
@@ -62,7 +62,9 @@ try {
//$telegram->setUploadPath('../Upload');
// Botan.io integration
// Second argument is optional maximum timeout
//$telegram->enableBotan('your_token');
//$telegram->enableBotan('your_token', 3);
// Handle telegram getUpdates request
$serverResponse
=
$telegram
->
handleGetUpdates
();
...
...
examples/hook.php
View file @
34ad296b
...
...
@@ -61,7 +61,9 @@ try {
//$telegram->setUploadPath('../Upload');
// Botan.io integration
// Second argument is optional maximum timeout
//$telegram->enableBotan('your_token');
//$telegram->enableBotan('your_token', 3);
// Handle telegram webhook request
$telegram
->
handle
();
...
...
src/Botan.php
View file @
34ad296b
This diff is collapsed.
Click to expand it.
src/BotanDB.php
View file @
34ad296b
...
...
@@ -47,13 +47,21 @@ class BotanDB extends DB
try
{
$sth
=
self
::
$pdo
->
prepare
(
'SELECT * FROM `'
.
TB_BOTAN_SHORTENER
.
'`
WHERE `user_id` = :user_id AND `url` = :url
ORDER BY `created_at` DESC
LIMIT 1
'
);
$sth
->
bindParam
(
':user_id'
,
$user_id
,
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':url'
,
$url
,
PDO
::
PARAM_
INT
);
$sth
->
bindParam
(
':url'
,
$url
,
PDO
::
PARAM_
STR
);
$sth
->
execute
();
return
$sth
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
$result
=
$sth
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
if
(
isset
(
$result
[
0
][
'short_url'
]))
{
return
$result
[
0
][
'short_url'
];
}
return
$result
;
}
catch
(
Exception
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
...
...
src/Telegram.php
View file @
34ad296b
...
...
@@ -455,7 +455,7 @@ class Telegram
//Handle a generic command or non existing one
$this
->
last_command_response
=
$this
->
executeCommand
(
'Generic'
);
}
else
{
//Botan.io integration, make sure only the command user executed is reported
//Botan.io integration, make sure only the
actual
command user executed is reported
if
(
$this
->
botan_enabled
)
{
Botan
::
lock
(
$command
);
}
...
...
@@ -815,14 +815,15 @@ class Telegram
/**
* Enable Botan.io integration
*
* @param $token
* @param string $token
* @param integer $timeout
*
* @return \Longman\TelegramBot\Telegram
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
enableBotan
(
$token
)
public
function
enableBotan
(
$token
,
$timeout
=
3
)
{
Botan
::
initializeBotan
(
$token
);
Botan
::
initializeBotan
(
$token
,
$timeout
);
$this
->
botan_enabled
=
true
;
return
$this
;
...
...
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