Skip to content

Commit

Permalink
A few improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed Mar 20, 2022
1 parent d95a73d commit 7ef9e7d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
15 changes: 15 additions & 0 deletions app/Telegram/Commands/StartCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Longman\TelegramBot\Commands;

use Longman\TelegramBot\Entities\ServerResponse;

class StartCommand extends UserCommand
{

public function execute(): ServerResponse
{
return $this->replyToChat('Don\'t mind me, I\'m just testing a few things...');
}

}
6 changes: 6 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Longman\TelegramBot\Request;

require 'vendor/autoload.php';

define('BASE_PATH', __DIR__);
Expand All @@ -11,6 +13,10 @@ function createTelegram() {
static $telegram;

if (! $telegram) {
if ($botApiUri = env('TELEGRAM_BOT_API_SERVER')) {
Request::setCustomBotApiUri($botApiUri);
}

$telegram = new \Longman\TelegramBot\Telegram(
env('TELEGRAM_BOT_TOKEN'),
env('TELEGRAM_BOT_USERNAME')
Expand Down
6 changes: 1 addition & 5 deletions scripts/close.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@

$response = Request::close();

if (! $response->isOk()) {
echo $response->getDescription() . PHP_EOL;
} else {
echo 'close was successful.' . PHP_EOL;
}
echo $response->getDescription() . PHP_EOL;
11 changes: 11 additions & 0 deletions scripts/deleteWebhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Longman\TelegramBot\Request;

require '../bootstrap.php';

$telegram = createTelegram();

$response = Request::deleteWebhook();

echo $response->getDescription() . PHP_EOL;
3 changes: 3 additions & 0 deletions scripts/getUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
// If there is a webhook, we delete it first
$telegram->deleteWebhook();

$telegram->useGetUpdatesWithoutDatabase();

while (true) {

try {

echo "Polling..." . PHP_EOL;
$telegram->handleGetUpdates([
'timeout' => 30,
]);
Expand Down
6 changes: 1 addition & 5 deletions scripts/logOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@

$response = Request::logOut();

if (! $response->isOk()) {
echo $response->getDescription() . PHP_EOL;
} else {
echo 'logOut was successful.' . PHP_EOL;
}
echo $response->getDescription() . PHP_EOL;
7 changes: 1 addition & 6 deletions scripts/setWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@
$webhookUrl = env('APP_URL') . '/handle.php';
$response = $telegram->setWebhook($webhookUrl);

if (! $response->isOk()) {
echo $response->getDescription() . PHP_EOL;
} else {
echo "Webhook was set to {$webhookUrl}" . PHP_EOL;
}

echo $response->getDescription() . PHP_EOL;

0 comments on commit 7ef9e7d

Please sign in to comment.