diff --git a/src/Commands/DeleteWebhook.php b/src/Commands/DeleteWebhook.php
new file mode 100644
index 0000000..a620d6f
--- /dev/null
+++ b/src/Commands/DeleteWebhook.php
@@ -0,0 +1,45 @@
+configureBotArguments();
+
+ $this->addOption('drop-pending-updates', 'd', InputOption::VALUE_NONE, 'Drop all pending updates');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ parent::execute($input, $output);
+
+ $bot = $this->makeBot($input, $output);
+
+ $dropPendingUpdates = $input->getOption('drop-pending-updates') ?: null;
+
+ try {
+ $bot->deleteWebhook(
+ drop_pending_updates: $dropPendingUpdates
+ );
+ } catch (TelegramException $e) {
+ \Termwind\render('
' . $e->getMessage() . '
');
+ return self::FAILURE;
+ }
+
+ \Termwind\render('' . $bot->lastApiResult() . '
');
+ return self::SUCCESS;
+ }
+
+}
\ No newline at end of file
diff --git a/src/Commands/SetWebhook.php b/src/Commands/SetWebhook.php
index bac821d..5347cac 100644
--- a/src/Commands/SetWebhook.php
+++ b/src/Commands/SetWebhook.php
@@ -14,7 +14,7 @@
#[AsCommand(
name: 'set-webhook',
- description: 'Registers a webhook with Telegram servers.'
+ description: 'Specify a URL an receive incoming updates via an outgoing webhook.'
)]
class SetWebhook extends BotCommand
{
@@ -64,15 +64,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
secret_token: $secretToken
);
} catch (TelegramException $e) {
- render(<<{$e->getMessage()}
- HTML);
+ render('' . $e->getMessage() . '
');
return Command::FAILURE;
}
- render(<<<'HTML'
- Webhook was set successfully.
- HTML);
+ render('' . $bot->lastApiResult() . '
');
return Command::SUCCESS;
}
diff --git a/src/Layers/Base.php b/src/Layers/Base.php
index d5e39f3..896dafd 100644
--- a/src/Layers/Base.php
+++ b/src/Layers/Base.php
@@ -40,6 +40,13 @@ public function disableProxy(): static
return $this;
}
+ protected ?string $lastApiResult = null;
+
+ public function lastApiResult(): ?string
+ {
+ return $this->lastApiResult;
+ }
+
public function raw(string $method, $data = []): mixed
{
$parameters = array_map(
@@ -59,6 +66,8 @@ public function raw(string $method, $data = []): mixed
$json = json_decode($response->getBody()->getContents(), true);
if ($json['ok'] === true) {
+ $this->lastApiResult = $json['description'] ?? null;
+
$method = new \ReflectionMethod($this, $method);
preg_match('/@return (.+)\[]\n/u', $method->getDocComment(), $matches);
diff --git a/telepathy b/telepathy
index f535de4..12338d3 100755
--- a/telepathy
+++ b/telepathy
@@ -4,12 +4,14 @@
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Application;
+use Telepath\Commands\DeleteWebhook;
use Telepath\Commands\SetWebhook;
$application = new Application();
$application->addCommands([
new SetWebhook(),
+ new DeleteWebhook(),
]);
$application->run();
\ No newline at end of file