feat: Add tagging system for SMS logs and templates
- Introduced a `tag` field in the `SmsLog` entity to categorize SMS messages. - Updated the `SmsService` to handle the new `tag` parameter during SMS dispatch. - Implemented a `SmsTextResolver` service to resolve SMS message templates based on tags. - Created a new `SmsMessageTemplate` entity for editable SMS templates with placeholders. - Added endpoints for managing SMS message templates in the admin panel. - Enhanced existing SMS dispatching methods across various controllers to utilize the tagging system. - Migrated the database to include the new `tag` field and created a seeding command for default SMS templates. - Updated admin API to filter SMS logs by tag and include tag information in responses.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Sms\Command;
|
||||
|
||||
use App\Sms\Entity\SmsMessageTemplate;
|
||||
use App\Sms\Repository\SmsMessageTemplateRepository;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:seed-sms-message-templates',
|
||||
description: 'متن پیشفرض پیامکهای سیستمی را برای تگهایی که هنوز رکورد ندارند میسازد',
|
||||
)]
|
||||
class SeedSmsMessageTemplatesCommand extends Command
|
||||
{
|
||||
public function __construct(private readonly SmsMessageTemplateRepository $repo)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$created = 0;
|
||||
foreach (SmsMessageTemplate::DEFAULTS as $tag => $def) {
|
||||
if ($this->repo->findByTag($tag) !== null) {
|
||||
continue;
|
||||
}
|
||||
$this->repo->save(
|
||||
new SmsMessageTemplate($tag, $def['title'], $def['body'], $def['variables']),
|
||||
false,
|
||||
);
|
||||
$created++;
|
||||
}
|
||||
$this->repo->getEntityManager()->flush();
|
||||
|
||||
$output->writeln(sprintf('Seeded %d sms message templates.', $created));
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user