Commit 34ad296b authored by Jack'lul's avatar Jack'lul

Botan integration improvements

parent 1c54e2c0
<?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);
}
}
......@@ -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();
......
......@@ -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();
......
This diff is collapsed.
......@@ -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());
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment