Commit fe4c5455 authored by Jack'lul's avatar Jack'lul

Merge pull request #202 from jacklul/quickupdate

Quick updates
parents 1549a4fd 0fcd30a8
......@@ -34,6 +34,11 @@ class Botan
*/
protected static $token = '';
/**
* @var string The actual command that is going to be reported
*/
public static $command = '';
/**
* Initilize botan
*/
......@@ -47,17 +52,30 @@ class Botan
}
/**
* Track function
* Lock function to make sure only the first command is reported
* ( in case commands are calling other commands $telegram->executedCommand() )
*
* @todo Advanced integration: https://github.com/botanio/sdk#advanced-integration
* @param string $command
*/
public static function lock($command = '')
{
if (empty(self::$command)) {
self::$command = $command;
}
}
/**
* Track function
*
* @param string $input
* @param string $command
*
* @return bool|string
* @throws TelegramException
*/
public static function track($input, $command = '')
{
if (empty(self::$token)) {
if (empty(self::$token) || $command != self::$command) {
return false;
}
......@@ -65,22 +83,26 @@ class Botan
throw new TelegramException('Input is empty!');
}
self::$command = '';
$obj = json_decode($input, true);
if (isset($obj['message'])) {
$data = $obj['message'];
if ((isset($obj['message']['entities']) && $obj['message']['entities'][0]['type'] == 'bot_command' && $obj['message']['entities'][0]['offset'] == 0) || substr($obj['message']['text'], 0, 1) == '/') {
if (strtolower($command) == 'generic') {
$command = 'Generic';
} elseif (strtolower($command) == 'genericmessage') {
$command = 'Generic Message';
} else {
$command = '/' . strtolower($command);
$event_name = 'Message';
if (isset($obj['message']['entities']) && is_array($obj['message']['entities'])) {
foreach ($obj['message']['entities'] as $entity) {
if ($entity['type'] == 'bot_command' && $entity['offset'] == 0) {
if (strtolower($command) == 'generic') {
$command = 'Generic';
} else {
$command = '/' . strtolower($command);
}
$event_name = 'Command (' . $command . ')';
break;
}
}
$event_name = 'Command ('.$command.')';
} else {
$event_name = 'Message';
}
} elseif (isset($obj['inline_query'])) {
$data = $obj['inline_query'];
......@@ -129,7 +151,9 @@ class Botan
*
* @param $url
* @param $user_id
*
* @return string
* @throws TelegramException
*/
public static function shortenUrl($url, $user_id)
{
......
......@@ -40,9 +40,9 @@ class InlinequeryCommand extends SystemCommand
$data = ['inline_query_id' => $inline_query->getId()];
$articles = [
['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => $query ]) ],
['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => $query ]) ],
['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => $query ]) ],
['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])],
['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])],
['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])],
];
$array_article = [];
......
This diff is collapsed.
......@@ -515,11 +515,16 @@ 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
if ($this->botan_enabled) {
Botan::lock($command);
}
//execute() method is executed after preExecute()
//This is to prevent executing a DB query without a valid connection
$this->last_command_response = $command_obj->preExecute();
//Botan.io integration
//Botan.io integration, send report after executing the command
if ($this->botan_enabled) {
Botan::track($this->update, $command);
}
......@@ -582,9 +587,11 @@ class Telegram
$user_id = $from->getId();
} elseif (($inline_query = $this->update->getInlineQuery()) && ($from = $inline_query->getFrom())) {
$user_id = $from->getId();
} elseif (($chosen_inline_result = $this->update->getChosenInlineResult()) && ($from = $chosen_inline_result->getFrom())) {
$user_id = $from->getId();
} elseif (($callback_query = $this->update->getCallbackQuery()) && ($from = $callback_query->getFrom())) {
$user_id = $from->getId();
} elseif (($chosen_inline_result = $this->update->getChosenInlineResult()) && ($from = $chosen_inline_result->getFrom())) {
} elseif (($edited_message = $this->update->getEditedMessage()) && ($from = $edited_message->getFrom())) {
$user_id = $from->getId();
}
}
......@@ -808,7 +815,6 @@ class Telegram
* Enable Botan.io integration
*
* @param $token
* @param $custom
* @return Telegram
*/
public function enableBotan($token)
......
This diff is collapsed.
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