init
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Services\CorunaArchive;
|
||||
use App\Services\CorunaCrypto;
|
||||
use App\Services\SettingsService;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Nutgram\Laravel\RunningMode\LaravelWebhook;
|
||||
use SergiX44\Nutgram\Nutgram;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(CorunaCrypto::class, function () {
|
||||
$override = config('coruna.session_key');
|
||||
|
||||
return new CorunaCrypto(is_string($override) && $override !== '' ? $override : null);
|
||||
});
|
||||
|
||||
$this->app->singleton(CorunaArchive::class, function ($app) {
|
||||
return new CorunaArchive(
|
||||
$app->make(CorunaCrypto::class),
|
||||
(string) config('coruna.seven_zip', ''),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
try {
|
||||
$this->app->make(SettingsService::class)->applyToConfig();
|
||||
} catch (\Throwable) {
|
||||
// settings table may not exist yet during migrate
|
||||
}
|
||||
|
||||
// Override Nutgram's production safe_mode (md5 APP_KEY) so webhook updates
|
||||
// are not silently dropped when Telegram secret_token is unset/mismatched.
|
||||
$this->app->afterResolving(Nutgram::class, function (Nutgram $bot): void {
|
||||
if ($this->app->runningUnitTests() || $this->app->runningInConsole()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$secret = (string) config('coruna.telegram.webhook_secret', '');
|
||||
$webhook = $secret !== ''
|
||||
? new LaravelWebhook(
|
||||
getToken: static fn () => request()?->header('X-Telegram-Bot-Api-Secret-Token'),
|
||||
secretToken: $secret,
|
||||
)
|
||||
: new LaravelWebhook;
|
||||
$webhook->setSafeMode($secret !== '');
|
||||
$bot->setRunningMode($webhook);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user