telegram
This commit is contained in:
@@ -55,6 +55,12 @@
|
||||
<span x-show="!webhookLoading[cfg.ID]">🔗 Webhook portal</span>
|
||||
<span x-show="webhookLoading[cfg.ID]">Registrando…</span>
|
||||
</button>
|
||||
<button @click="checkWebhook(cfg)" :disabled="webhookInfoLoading[cfg.ID]"
|
||||
class="flex-1 text-xs border border-slate-300 text-slate-600 px-3 py-1.5 rounded hover:bg-slate-50 transition-colors disabled:opacity-50"
|
||||
title="Consulta getWebhookInfo en Telegram para este bot">
|
||||
<span x-show="!webhookInfoLoading[cfg.ID]">📡 Estado webhook</span>
|
||||
<span x-show="webhookInfoLoading[cfg.ID]">Consultando…</span>
|
||||
</button>
|
||||
<button @click="openEdit(cfg)"
|
||||
class="text-xs border border-blue-400 text-blue-500 px-3 py-1.5 rounded hover:bg-blue-50">Editar</button>
|
||||
<button @click="confirmDelete(cfg.ID)"
|
||||
@@ -228,6 +234,7 @@ function telegramApp() {
|
||||
form: { nombre: '', bot_token: '', chat_id: '', notas: '', activo: true },
|
||||
testLoading: {}, testResult: {}, testOk: {},
|
||||
webhookLoading: {}, webhookResult: {}, webhookOk: {},
|
||||
webhookInfoLoading: {},
|
||||
sendForm: { config_ids: [], titulo: '', mensaje: '' },
|
||||
sendLoading: false, sendResult: '', sendOk: true,
|
||||
logs: [], logPage: 1, logTotalPages: 1, logTotal: 0,
|
||||
@@ -312,6 +319,32 @@ function telegramApp() {
|
||||
this.webhookLoading[cfg.ID] = false;
|
||||
}
|
||||
},
|
||||
async checkWebhook(cfg) {
|
||||
this.webhookInfoLoading[cfg.ID] = true;
|
||||
this.webhookResult[cfg.ID] = '';
|
||||
try {
|
||||
const res = await fetch(`/app/telegram/${cfg.ID}/webhook-info`);
|
||||
const d = await res.json();
|
||||
const info = d.result || {};
|
||||
const hasPortalURL = (info.url || '').includes('/webhooks/telegram-portal');
|
||||
const hasError = !!(info.last_error_message || info.last_synchronization_error_date);
|
||||
|
||||
this.webhookOk[cfg.ID] = !!d.ok && hasPortalURL && !hasError;
|
||||
|
||||
const parts = [];
|
||||
if (info.url) parts.push(`URL: ${info.url}`);
|
||||
if (typeof info.pending_update_count !== 'undefined') parts.push(`Pendientes: ${info.pending_update_count}`);
|
||||
if (info.last_error_message) parts.push(`Último error: ${info.last_error_message}`);
|
||||
if (!parts.length) parts.push(d.description || 'Sin datos de webhook');
|
||||
|
||||
this.webhookResult[cfg.ID] = (this.webhookOk[cfg.ID] ? '✅ ' : '⚠️ ') + parts.join(' | ');
|
||||
} catch (e) {
|
||||
this.webhookOk[cfg.ID] = false;
|
||||
this.webhookResult[cfg.ID] = '❌ Error consultando webhook: ' + e.message;
|
||||
} finally {
|
||||
this.webhookInfoLoading[cfg.ID] = false;
|
||||
}
|
||||
},
|
||||
|
||||
async sendMessage() {
|
||||
this.sendResult = '';
|
||||
|
||||
Reference in New Issue
Block a user