feat: menus por permission_type (1=info, 2=informes, 3=completo)

This commit is contained in:
Lizandro Guarnizo
2026-06-27 18:46:35 -05:00
parent 7407c716d4
commit b96dbcc394
2 changed files with 70 additions and 8 deletions
+56
View File
@@ -96,6 +96,62 @@ $menuConfig = [
'ciclo_cosecha_dia' => ['type' => 'function', 'function' => 'api_report', 'params' => ['endpoint_key' => 'cosecha_dn', 'filename' => 'ciclo_cosecha_hoy.xlsx', 'caption' => 'Ciclo de cosecha del día de hoy', 'date_mode' => 'today']],
'ciclo_cosecha_historico' => ['type' => 'function', 'function' => 'api_report', 'params' => ['endpoint_key' => 'cosecha_dn', 'filename' => 'ciclo_cosecha_30dias.xlsx', 'caption' => 'Histórico ciclos de cosecha últimos 30 días', 'date_mode' => 'last_30']],
],
'per_type' => [
'1' => [
'greeting' => '¡Bienvenido! Escribe *menu* para recibir información.',
'fallback' => 'Escribe *menu* para recibir información.',
'commands' => [
'menu' => 'show_menu_cat1',
'info' => 'recibir_info_cat1',
],
'menus' => [
'show_menu_cat1' => [
'type' => 'list',
'header' => 'Bienvenido',
'body' => '¿Qué deseas hacer?',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Opciones',
'rows' => [
['id' => 'recibir_info_cat1', 'title' => 'Recibir Información', 'description' => 'Información útil para ti'],
],
],
],
],
],
'flows' => [
'show_menu_cat1' => ['type' => 'menu', 'menu' => 'show_menu_cat1'],
'recibir_info_cat1' => ['type' => 'function', 'function' => 'forward_to_ai'],
],
],
'2' => [
'greeting' => '¡Bienvenido! Escribe *menu* para descargar informes.',
'fallback' => 'Escribe *menu* para descargar informes.',
'commands' => [
'menu' => 'show_menu_cat2',
'informes' => 'descargar_informes',
],
'menus' => [
'show_menu_cat2' => [
'type' => 'list',
'header' => 'Menú',
'body' => 'Selecciona una opción:',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Opciones',
'rows' => [
['id' => 'descargar_informes', 'title' => 'Descargar Informes', 'description' => 'Accede a tus informes'],
],
],
],
],
],
],
],
];
$companies = CompanyRepository::findAll(true);
+14 -8
View File
@@ -6,9 +6,12 @@ class NormalBot
public static function process(array $company, array $context, string $input): ?array
{
$config = self::getConfig($company);
$commands = $config['commands'] ?? [];
$flows = $config['flows'] ?? [];
$menus = $config['menus'] ?? [];
$permType = (string)($company['_permission_type'] ?? 1);
$perType = $config['per_type'][$permType] ?? [];
$commands = $perType['commands'] ?? $config['commands'] ?? [];
$flows = array_merge($config['flows'] ?? [], $perType['flows'] ?? []);
$menus = array_merge($config['menus'] ?? [], $perType['menus'] ?? []);
$ctxId = null;
$botCtx = ConversationContext::getOrCreate((int)$company['id'], $context['from'], 'normal');
@@ -43,18 +46,19 @@ class NormalBot
return null;
}
$greeting = $config['greeting'] ?? null;
$greeting = $perType['greeting'] ?? $config['greeting'] ?? null;
if ($greeting !== null && $currentNode === null) {
ConversationContext::updateNode($ctxId, 'greeting');
if (isset($flows['greeting'])) {
return self::handleFlow($flows['greeting'], $context, $company, $ctxId);
$greetingFlowId = $perType['greeting_flow'] ?? 'greeting';
if (isset($flows[$greetingFlowId])) {
return self::handleFlow($flows[$greetingFlowId], $context, $company, $ctxId);
}
return self::sendText($greeting, $context['from'], $company);
}
$fallback = $config['fallback'] ?? null;
$fallback = $perType['fallback'] ?? $config['fallback'] ?? null;
if ($fallback !== null) {
return self::sendText($fallback, $context['from'], $company);
}
@@ -324,7 +328,9 @@ class NormalBot
public static function processInteractive(array $company, array $context, string $input): ?array
{
$config = self::getConfig($company);
$flows = $config['flows'] ?? [];
$permType = (string)($company['_permission_type'] ?? 1);
$perType = $config['per_type'][$permType] ?? [];
$flows = array_merge($config['flows'] ?? [], $perType['flows'] ?? []);
$botCtx = ConversationContext::getOrCreate((int)$company['id'], $context['from'], 'normal');
$ctxId = (int)$botCtx['id'];