Skip to content

Expansão Interna do Sistema Central OTOBO

Neste artigo, você aprenderá como personalizar o OTOBO diretamente no núcleo – através de configuração XML, módulos Perl e templates. Mostramos passo a passo como integrar um módulo "HelloWorld" próprio ao sistema.


1. Estrutura de Diretórios

Todas as personalizações ficam abaixo do seu clone OTOBO no diretório Kernel/:


Kernel/
├─ Config/Files/           # Registros XML
│  └─ XML/
├─ System/                 # Módulos de lógica de negócios (Core)
├─ Modules/                # Controladores Frontend (Agente/Cliente)
├─ Output/HTML/Standard/   # Templates Template Toolkit (TT)
└─ Language/               # Traduções

2. Configuração XML

Novos módulos e rotas são registrados via XML. Crie um arquivo HelloWorld.xml em 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 Negócios)

Crie sua lógica em 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)

Em Kernel/Modules/AgentHelloWorld.pm, integre sua lógica ao frontend do 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. Templates (TT)

Crie o seguinte template em Kernel/Output/HTML/Standard/AgentHelloWorld.tt:

tt
[% Data.Text %]

<p>Este é o seu módulo HelloWorld criado!</p>

6. Fluxo de Trabalho de Exemplo

  1. Recarregar:

    bash
    bin/otobo.Console.pl Maint::Config::Rebuild
  2. Limpar Cache:

    bash
    bin/otobo.Console.pl Maint::Cache::Delete
  3. Abrir Navegador: Interface do Agente → Menu → "HelloWorld"


7. Dicas e Melhores Práticas

  • Declare ObjectDependencies corretamente (por exemplo, DB, Layout).
  • Não se esqueça da documentação POD em módulos Perl.
  • Mantenha as traduções em Kernel/Language/de_*.pm.
  • Configure unit tests com Mojolicious (opcional).
  • Após cada alteração, execute rebuild de configuração e limpe o cache.

Com isso, você tem um modelo sólido para realizar outras extensões do núcleo no OTOBO. Feliz desenvolvimento!