-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
583 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Facades\App\Domains\EmailParser\Client; | ||
use Illuminate\Console\Command; | ||
|
||
class CheckEmailCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'llm_assistant:check_email'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'This will check email make sure the llm_assistant.check_email is true'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
logger('Checking Email'); | ||
$this->info('Checking Email'); | ||
Client::handle(); | ||
logger('Done Checking Email'); | ||
$this->info('Done Checking Email'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Domains\EmailParser; | ||
|
||
use App\Jobs\MailBoxParserJob; | ||
use Webklex\IMAP\Facades\Client as ClientFacade; | ||
|
||
class Client | ||
{ | ||
public function handle(): void | ||
{ | ||
$client = ClientFacade::account('default'); | ||
$client->connect(); | ||
|
||
$folders = $client->getFolders(false); | ||
|
||
foreach ($folders as $folder) { | ||
$messages = $folder->messages()->all()->limit(3, 0)->get(); | ||
|
||
logger('Emails', [ | ||
$messages->count(), | ||
]); | ||
|
||
foreach ($messages as $message) { | ||
logger('Getting Message'); | ||
|
||
$messageDto = MailDto::from([ | ||
'to' => $message->getTo(), | ||
'from' => $message->getFrom(), | ||
'body' => $message->getTextBody(), | ||
'subject' => $message->getSubject(), | ||
'header' => $message->getHeader()->raw, | ||
]); | ||
|
||
MailBoxParserJob::dispatch($messageDto); | ||
|
||
$message->delete(expunge: true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Domains\EmailParser; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
class MailDto extends Data | ||
{ | ||
public function __construct( | ||
public ?string $subject, | ||
public ?string $from, | ||
public ?string $to, | ||
public ?string $body, | ||
public ?string $header | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Domains\EmailParser\MailDto; | ||
use App\Models\Message; | ||
use App\Models\Tag; | ||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class MailBoxParserJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(public MailDto $mailDto) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
try { | ||
|
||
$tag = Tag::firstOrCreate([ | ||
'label' => 'email', | ||
], [ | ||
'active' => 1, | ||
]); | ||
|
||
$message = Message::create([ | ||
'role' => 'user', | ||
'user_id' => User::first()->id, | ||
'content' => sprintf("subject: %s \n body: %s", | ||
$this->mailDto->subject, | ||
$this->mailDto->body), | ||
]); | ||
|
||
$message->tags()->attach($tag->id); | ||
|
||
/** | ||
* If tons of text we tldr it | ||
* If a url we go get it then tldr it | ||
* can make that a function? | ||
*/ | ||
} catch (\Exception $e) { | ||
logger('Email error', [$e->getMessage()]); | ||
$this->fail(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.