Skip to content

Ampliar el Núcleo de OTOBO Internamente

En este artículo, aprenderás a personalizar OTOBO directamente en el núcleo, a través de configuración XML, módulos Perl y plantillas. Te mostraremos paso a paso cómo integrar tu propio módulo "HelloWorld" en el sistema.


1. Estructura de Directorios

Todas las personalizaciones se encuentran dentro de tu clon de OTOBO, en el directorio Kernel/:


Kernel/
├─ Config/Files/           # Registros XML
│  └─ XML/
├─ System/                 # Módulos de lógica de negocio (Core)
├─ Modules/                # Controladores Frontend (Agente/Cliente)
├─ Output/HTML/Standard/   # Plantillas Template Toolkit (TT)
└─ Language/               # Traducciones

2. Configuración XML

Los nuevos módulos y rutas se registran mediante XML. Crea un archivo HelloWorld.xml en Kernel/Config/Files/XML/:

xml
<?xml version="1.0" encoding="UTF-8"?>
<otobo_config version="2.0" init="Application">

  <!-- 1. Registrar módulo Frontend -->
  <Setting Name="Frontend::Module###AgentHelloWorld" Required="1" Valid="1">
    <Navigation>Frontend::Agent::ModuleRegistration</Navigation>
    <Value>
      <Item ValueType="FrontendRegistration">
        <Hash>
          <Item Key="Group"><Array><Item>users</Item></Array></Item>
          <Item Key="Description" Translatable="1">Módulo HelloWorld</Item>
          <Item Key="Title"       Translatable="1">HelloWorld</Item>
          <Item Key="NavBarName">HelloWorld</Item>
        </Hash>
      </Item>
    </Value>
  </Setting>

</otobo_config>

3. Módulo Core (Lógica de Negocio)

Crea tu lógica en Kernel/System/HelloWorld.pm:

perl
package Kernel::System::HelloWorld;
use strict;
use warnings;
our @ObjectDependencies = ();  

sub new {
    my ($Type, %Param) = @_;
    return bless {}, $Type;
}

sub GetHelloWorldText {
    my ($Self, %Param) = @_;
    return $Self->_FormatText(String => 'Hello World');
}

sub _FormatText {
    my ($Self, %Param) = @_;
    return uc $Param{String};
}

1;

4. Módulo Frontend (Controlador)

En Kernel/Modules/AgentHelloWorld.pm, integra tu lógica en el frontend del Agente:

perl
package Kernel::Modules::AgentHelloWorld;
use strict;
use warnings;

sub new { bless {}, shift }

sub Run {
    my ($Self, %Param) = @_;

    my $HelloObj    = $Kernel::OM->Get('Kernel::System::HelloWorld');
    my $LayoutObj   = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
    my %Data;
    
    $Data{Text} = $HelloObj->GetHelloWorldText();

    return 
        $LayoutObj->Header(Title => 'HelloWorld')
      . $LayoutObj->NavigationBar()
      . $LayoutObj->Output(
          TemplateFile => 'AgentHelloWorld',
          Data         => \%Data,
        )
      . $LayoutObj->Footer();
}

1;

5. Plantillas (TT)

Crea la siguiente plantilla en Kernel/Output/HTML/Standard/AgentHelloWorld.tt:

tt
[% Data.Text %]

<p>¡Este es tu módulo HelloWorld creado por ti mismo!</p>

6. Flujo de Trabajo de Ejemplo

  1. Recargar:

    bash
    bin/otobo.Console.pl Maint::Config::Rebuild
  2. Limpiar caché:

    bash
    bin/otobo.Console.pl Maint::Cache::Delete
  3. Abrir navegador: Interfaz de Agente → Menú → "HelloWorld"


7. Consejos y Buenas Prácticas

  • Declarar ObjectDependencies limpiamente (por ejemplo, DB, Layout).
  • No olvidar la documentación POD en los módulos Perl.
  • Mantener las traducciones en Kernel/Language/de_*.pm.
  • Configurar pruebas unitarias con Mojolicious (opcional).
  • Después de cada cambio, reconstruir la configuración y limpiar la caché.

Con esto, tienes una plantilla sólida para implementar extensiones de núcleo adicionales en OTOBO. ¡Feliz desarrollo!