mirror of
https://gh.wpcy.net/https://github.com/thomas-deep/freescoutAI.git
synced 2026-05-25 22:33:47 +08:00
191 lines
6 KiB
PHP
191 lines
6 KiB
PHP
<?php
|
|
|
|
namespace Modules\FreeScoutAI\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Database\Eloquent\Factory;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Route;
|
|
use App\Conversation;
|
|
use App\Thread;
|
|
|
|
class FreeScoutAIServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Boot the application events.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$this->registerTranslations();
|
|
$this->registerConfig();
|
|
$this->registerViews();
|
|
$this->registerFactories();
|
|
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
|
|
$this->registerEvents();
|
|
$this->registerAssets();
|
|
}
|
|
|
|
/**
|
|
* Register the service provider.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->app->register(RouteServiceProvider::class);
|
|
}
|
|
|
|
/**
|
|
* Register events.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerEvents()
|
|
{
|
|
// Register events here
|
|
}
|
|
|
|
/**
|
|
* Register assets.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerAssets()
|
|
{
|
|
// Register assets here
|
|
\Eventy::addAction('conversation.after_prev_convs', function($conversation, $mailbox) {
|
|
if ($conversation && $mailbox) {
|
|
$priority = \Modules\FreeScoutAI\Entities\AIPriority::where('conversation_id', $conversation->id)->first();
|
|
if ($priority) {
|
|
echo \View::make('freescoutai::partials.priority_badge', [
|
|
'priority' => $priority->priority
|
|
]);
|
|
}
|
|
}
|
|
}, 20, 2);
|
|
|
|
\Eventy::addAction('conversation.action_buttons', function($conversation, $mailbox) {
|
|
if ($conversation && $mailbox) {
|
|
$settings = \Modules\FreeScoutAI\Entities\AISettings::find($mailbox->id);
|
|
if ($settings && $settings->enabled && $settings->summary_enabled) {
|
|
echo '<a class="btn btn-light" href="javascript:void(0);" onclick="freescoutai_summarize(' . $conversation->id . ')"><i class="glyphicon glyphicon-list-alt"></i> ' . __('Zusammenfassen (KI)') . '</a>';
|
|
}
|
|
}
|
|
}, 20, 2);
|
|
|
|
\Eventy::addAction('conversation.action_buttons', function($conversation, $mailbox) {
|
|
if ($conversation && $mailbox) {
|
|
$settings = \Modules\FreeScoutAI\Entities\AISettings::find($mailbox->id);
|
|
if ($settings && $settings->enabled && $settings->priority_enabled) {
|
|
echo '<a class="btn btn-light" href="javascript:void(0);" onclick="freescoutai_prioritize(' . $conversation->id . ')"><i class="glyphicon glyphicon-sort-by-attributes"></i> ' . __('Priorisieren (KI)') . '</a>';
|
|
}
|
|
}
|
|
}, 21, 2);
|
|
|
|
\Eventy::addAction('thread.action_buttons', function($thread, $conversation) {
|
|
if ($thread && $conversation && $thread->type == Thread::TYPE_CUSTOMER) {
|
|
$mailbox = $conversation->mailbox;
|
|
$settings = \Modules\FreeScoutAI\Entities\AISettings::find($mailbox->id);
|
|
if ($settings && $settings->enabled && $settings->suggestions_enabled) {
|
|
echo '<a class="btn btn-light" href="javascript:void(0);" onclick="freescoutai_suggest(' . $thread->id . ')"><i class="glyphicon glyphicon-comment"></i> ' . __('Antwort generieren (KI)') . '</a>';
|
|
}
|
|
}
|
|
}, 20, 2);
|
|
|
|
\Eventy::addAction('compose.after_subject', function($conversation, $mailbox) {
|
|
if ($conversation && $mailbox) {
|
|
$settings = \Modules\FreeScoutAI\Entities\AISettings::find($mailbox->id);
|
|
if ($settings && $settings->enabled && $settings->modifications_enabled) {
|
|
echo \View::make('freescoutai::partials.modification_buttons');
|
|
}
|
|
}
|
|
}, 20, 2);
|
|
|
|
\Eventy::addAction('layout.body_bottom', function() {
|
|
echo \View::make('freescoutai::partials.summary_modal');
|
|
}, 20);
|
|
|
|
\Eventy::addAction('mailboxes.settings_menu', function($mailbox) {
|
|
if ($mailbox) {
|
|
echo \View::make('freescoutai::partials.settings_menu', [
|
|
'mailbox' => $mailbox
|
|
]);
|
|
}
|
|
}, 20, 1);
|
|
}
|
|
|
|
/**
|
|
* Register config.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerConfig()
|
|
{
|
|
$this->publishes([
|
|
__DIR__.'/../Config/config.php' => config_path('freescoutai.php'),
|
|
], 'config');
|
|
$this->mergeConfigFrom(
|
|
__DIR__.'/../Config/config.php', 'freescoutai'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Register views.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function registerViews()
|
|
{
|
|
$viewPath = resource_path('views/modules/freescoutai');
|
|
|
|
$sourcePath = __DIR__.'/../Resources/views';
|
|
|
|
$this->publishes([
|
|
$sourcePath => $viewPath
|
|
],'views');
|
|
|
|
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
|
return $path . '/modules/freescoutai';
|
|
}, \Config::get('view.paths')), [$sourcePath]), 'freescoutai');
|
|
}
|
|
|
|
/**
|
|
* Register translations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function registerTranslations()
|
|
{
|
|
$langPath = resource_path('lang/modules/freescoutai');
|
|
|
|
if (is_dir($langPath)) {
|
|
$this->loadTranslationsFrom($langPath, 'freescoutai');
|
|
} else {
|
|
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'freescoutai');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register an additional directory of factories.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function registerFactories()
|
|
{
|
|
if (! app()->environment('production')) {
|
|
app(Factory::class)->load(__DIR__ . '/../Database/factories');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the services provided by the provider.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function provides()
|
|
{
|
|
return [];
|
|
}
|
|
}
|