feat(call-script): add the Call Script component (0.19.0)
A new Mautic component, listed under Components > Call Scripts (/s/call-scripts),
built like the other domains on AbstractStandardFormController/FormModel.
- CallScript (mt3s_call_scripts): name, description, category, owner, status,
the publish window shown as start/end date and time, the HTML script with
dynamic tokens kept as typed (html cleaning mask), the calling window
(weekdays, hours, sentinel in the contact's or a fixed timezone) and the retry
policy (max attempts, delay, backoff: none/linear/exponential)
- CallScriptOutcome (mt3s_call_script_outcomes, ON DELETE CASCADE): label,
data type (checkbox/radio/free text/dropdown), options JSON ({value,label})
and position; nested collections reuse the program-collection JS
- validators: ValidCallingWindow, ValidCallScriptOutcomeOptions, and an atPath
option on EndDateAfterStartDate so its violation lands on publishDown
- config: routes, the Components menu item (parent mautic.core.components),
call_script category type, model alias, call_scripts permissions, version 0.19.0
- migration Version_0_19_0 creates both tables and their FKs immediately
(users/categories SET NULL, outcomes CASCADE), idempotent
- translations en_US/fr_FR, unit tests, readme/AGENTS documentation
This commit is contained in:
1 parent
88256ca345
commit
4fb36eebfc
33 files changed
+2537
-6
No files matched your search
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* One {value, label} row of a call script outcome's options. The rows are stored as a JSON list on
|
||||
* CallScriptOutcome::$options.
|
||||
*/
|
||||
class CallScriptOutcomeOptionType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->add('value', TextType::class, [
|
||||
'label' => 'mt3s.call_script.outcome_option.field.value',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control', 'maxlength' => 191],
|
||||
]);
|
||||
|
||||
$builder->add('label', TextType::class, [
|
||||
'label' => 'mt3s.call_script.outcome_option.field.label',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control', 'maxlength' => 191],
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'mt3s_call_script_outcome_option';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\Type;
|
||||
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScriptOutcome;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScriptOutcomeInputType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* One row of the outcomes collection in CallScriptType: the outcome's label, the data type the agent
|
||||
* records it with (checkbox, radio, free text or dropdown), and the options of the choice types.
|
||||
* Adding, removing and reordering is handled by Assets/js/mt3s-mp-program.js.
|
||||
*/
|
||||
class CallScriptOutcomeType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->add('label', TextType::class, [
|
||||
'label' => 'mt3s.call_script.outcome.field.label',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control', 'maxlength' => CallScriptOutcome::LABEL_MAX_LENGTH],
|
||||
]);
|
||||
|
||||
$builder->add('inputType', EnumType::class, [
|
||||
'label' => 'mt3s.call_script.outcome.field.type',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control program-outcome-type'],
|
||||
'class' => CallScriptOutcomeInputType::class,
|
||||
'choice_label' => fn (CallScriptOutcomeInputType $type): string => $type->getLabelKey(),
|
||||
]);
|
||||
|
||||
// The choices of a checkbox, radio or dropdown outcome; hidden by the JS for free text.
|
||||
$builder->add('options', CollectionType::class, [
|
||||
'label' => false,
|
||||
'entry_type' => CallScriptOutcomeOptionType::class,
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
'by_reference' => false,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__option__',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
// The row's order in the collection, rewritten by mt3s-mp-program.js after each change.
|
||||
$builder->add('position', HiddenType::class, [
|
||||
'attr' => ['class' => 'program-row-position'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => CallScriptOutcome::class,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'mt3s_call_script_outcome';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\Type;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Mautic\CategoryBundle\Form\Type\CategoryListType;
|
||||
use Mautic\CoreBundle\Form\DataTransformer\IdToEntityModelTransformer;
|
||||
use Mautic\CoreBundle\Form\EventListener\CleanFormSubscriber;
|
||||
use Mautic\CoreBundle\Form\Type\FormButtonsType;
|
||||
use Mautic\CoreBundle\Form\Type\PublishDownDateType;
|
||||
use Mautic\CoreBundle\Form\Type\PublishUpDateType;
|
||||
use Mautic\CoreBundle\Form\Type\TimezoneType;
|
||||
use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType;
|
||||
use Mautic\UserBundle\Entity\User;
|
||||
use Mautic\UserBundle\Form\Type\UserListType;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScript;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScriptRetryBackoff;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScriptTimezoneMode;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TimeType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* The create and edit form of a call script (Components > Call Scripts).
|
||||
*
|
||||
* The script keeps the HTML typed in it (the "html" cleaning mask), including the dynamic tokens like
|
||||
* {contact.first_name}. The outcomes are edited as a sortable collection (see Assets/js/mt3s-mp-program.js);
|
||||
* the options of an outcome are shown only for the checkbox, radio and dropdown types.
|
||||
*/
|
||||
class CallScriptType extends AbstractType
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
) {
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
// Pass a mask array, never nothing: without one, core applies its "clean" mask (HTML-encodes &, <, >,
|
||||
// quotes). "html" keeps the script markup; "clean" strips the rest of the fields.
|
||||
$builder->addEventSubscriber(new CleanFormSubscriber([
|
||||
'name' => 'clean',
|
||||
'description' => 'clean',
|
||||
'script' => 'html',
|
||||
]));
|
||||
|
||||
$builder->add('name', TextType::class, [
|
||||
'label' => 'mt3s.call_script.field.name',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control', 'maxlength' => CallScript::NAME_MAX_LENGTH],
|
||||
]);
|
||||
|
||||
$builder->add('description', TextareaType::class, [
|
||||
'label' => 'mt3s.call_script.field.description',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control', 'rows' => 2],
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('script', TextareaType::class, [
|
||||
'label' => 'mt3s.call_script.field.script',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => [
|
||||
'class' => 'form-control',
|
||||
'rows' => 14,
|
||||
'style' => 'font-family: monospace;',
|
||||
'tooltip' => 'mt3s.call_script.field.script.help',
|
||||
],
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
// Required here; the column is nullable only because of onDelete SET NULL.
|
||||
$builder->add(
|
||||
$builder->create('owner', UserListType::class, [
|
||||
'label' => 'mt3s.call_script.field.owner',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control'],
|
||||
'required' => true,
|
||||
'multiple' => false,
|
||||
])->addModelTransformer(new IdToEntityModelTransformer($this->em, User::class))
|
||||
);
|
||||
|
||||
$builder->add('category', CategoryListType::class, [
|
||||
'bundle' => 'call_script',
|
||||
'label' => 'mt3s.call_script.field.category',
|
||||
]);
|
||||
|
||||
$builder->add('isPublished', YesNoButtonGroupType::class, [
|
||||
'label' => 'mautic.core.form.available',
|
||||
]);
|
||||
|
||||
// The validity window: "start" and "end" date and time.
|
||||
$builder->add('publishUp', PublishUpDateType::class, [
|
||||
'label' => 'mt3s.call_script.field.start',
|
||||
]);
|
||||
|
||||
$builder->add('publishDown', PublishDownDateType::class, [
|
||||
'label' => 'mt3s.call_script.field.end',
|
||||
]);
|
||||
|
||||
// Calling window: the weekdays, the hours and the timezone the hours are read in.
|
||||
$builder->add('callingDays', ChoiceType::class, [
|
||||
'label' => 'mt3s.call_script.field.calling_days',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'choices' => $this->weekdayChoices(),
|
||||
'choice_translation_domain' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('callingFrom', TimeType::class, [
|
||||
'label' => 'mt3s.call_script.field.calling_from',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'widget' => 'single_text',
|
||||
'with_seconds' => false,
|
||||
'attr' => ['class' => 'form-control'],
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('callingTo', TimeType::class, [
|
||||
'label' => 'mt3s.call_script.field.calling_to',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'widget' => 'single_text',
|
||||
'with_seconds' => false,
|
||||
'attr' => ['class' => 'form-control'],
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('callingTimezoneMode', EnumType::class, [
|
||||
'label' => 'mt3s.call_script.field.calling_timezone_mode',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control'],
|
||||
'class' => CallScriptTimezoneMode::class,
|
||||
'choice_label' => fn (CallScriptTimezoneMode $mode): string => $mode->getLabelKey(),
|
||||
]);
|
||||
|
||||
$builder->add('callingTimezone', TimezoneType::class, [
|
||||
'label' => 'mt3s.call_script.field.calling_timezone',
|
||||
'placeholder' => '',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
// Retry policy: how many times, how long between attempts, and how the delay grows.
|
||||
$builder->add('retryMaxAttempts', IntegerType::class, [
|
||||
'label' => 'mt3s.call_script.field.retry_max_attempts',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => [
|
||||
'class' => 'form-control',
|
||||
'min' => CallScript::RETRY_ATTEMPTS_MIN,
|
||||
'max' => CallScript::RETRY_ATTEMPTS_MAX,
|
||||
'step' => 1,
|
||||
],
|
||||
]);
|
||||
|
||||
$builder->add('retryDelayMinutes', IntegerType::class, [
|
||||
'label' => 'mt3s.call_script.field.retry_delay_minutes',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => [
|
||||
'class' => 'form-control',
|
||||
'min' => 0,
|
||||
'max' => CallScript::RETRY_DELAY_MAX,
|
||||
'step' => 1,
|
||||
],
|
||||
]);
|
||||
|
||||
$builder->add('retryBackoff', EnumType::class, [
|
||||
'label' => 'mt3s.call_script.field.retry_backoff',
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control'],
|
||||
'class' => CallScriptRetryBackoff::class,
|
||||
'choice_label' => fn (CallScriptRetryBackoff $backoff): string => $backoff->getLabelKey(),
|
||||
]);
|
||||
|
||||
// Outcomes: the list of things the agent can record, each with its data type and options.
|
||||
$builder->add('outcomes', CollectionType::class, [
|
||||
'label' => false,
|
||||
'entry_type' => CallScriptOutcomeType::class,
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
'by_reference' => false,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__outcome__',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('buttons', FormButtonsType::class);
|
||||
|
||||
if (!empty($options['action'])) {
|
||||
$builder->setAction($options['action']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The weekdays of the calling window: translation key => ISO short name.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function weekdayChoices(): array
|
||||
{
|
||||
$choices = [];
|
||||
foreach (CallScript::WEEKDAYS as $day) {
|
||||
$choices['mt3s.call_script.day.'.$day] = $day;
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => CallScript::class,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'mt3s_call_script';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user