ip
This commit is contained in:
@@ -489,19 +489,19 @@ function miCuenta() {
|
||||
this.tg.verificando = true;
|
||||
this.tg.verMsg = '';
|
||||
try {
|
||||
const r = await axios.get('/portal/mi-perfil/telegram-status');
|
||||
if (r.data.linked) {
|
||||
const r = await axios.post('/portal/mi-perfil/telegram-validar');
|
||||
if (r.data.ok) {
|
||||
this.tg.linked = true;
|
||||
this.tg.chat_id = r.data.chat_id;
|
||||
this.tg.token = '';
|
||||
this.tg.verMsg = '✅ ¡Telegram vinculado correctamente!';
|
||||
this.tg.verOk = true;
|
||||
} else {
|
||||
this.tg.verMsg = 'Aún no se detectó el mensaje. Asegúrate de enviar el código al bot.';
|
||||
this.tg.verMsg = r.data.error || 'No se encontró el mensaje. Envía /vincular ' + this.tg.token + ' al bot.';
|
||||
this.tg.verOk = false;
|
||||
}
|
||||
} catch(e) {
|
||||
this.tg.verMsg = 'Error al verificar. Intenta de nuevo.';
|
||||
this.tg.verMsg = e.response?.data?.error || 'Error al verificar. Intenta de nuevo.';
|
||||
this.tg.verOk = false;
|
||||
} finally { this.tg.verificando = false; }
|
||||
},
|
||||
|
||||
@@ -43,12 +43,18 @@
|
||||
class="text-xs px-2 py-0.5 rounded-full whitespace-nowrap"></span>
|
||||
</div>
|
||||
<p x-show="cfg.notas" x-text="cfg.notas" class="text-xs text-gray-500 italic"></p>
|
||||
<div class="flex gap-2 mt-auto pt-2 border-t">
|
||||
<div class="flex gap-2 mt-auto pt-2 border-t flex-wrap">
|
||||
<button @click="testConfig(cfg)" :disabled="testLoading[cfg.ID]"
|
||||
class="flex-1 text-xs border border-[#8eb02f] text-[#8eb02f] px-3 py-1.5 rounded hover:bg-[#8eb02f] hover:text-white transition-colors disabled:opacity-50">
|
||||
<span x-show="!testLoading[cfg.ID]">🔔 Probar</span>
|
||||
<span x-show="testLoading[cfg.ID]">Enviando…</span>
|
||||
</button>
|
||||
<button @click="setWebhook(cfg)" :disabled="webhookLoading[cfg.ID]"
|
||||
class="flex-1 text-xs border border-indigo-400 text-indigo-600 px-3 py-1.5 rounded hover:bg-indigo-50 transition-colors disabled:opacity-50"
|
||||
title="Registra este bot para recibir mensajes del portal de clientes">
|
||||
<span x-show="!webhookLoading[cfg.ID]">🔗 Webhook portal</span>
|
||||
<span x-show="webhookLoading[cfg.ID]">Registrando…</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)"
|
||||
@@ -57,6 +63,9 @@
|
||||
<p x-show="testResult[cfg.ID]" x-text="testResult[cfg.ID]"
|
||||
:class="testOk[cfg.ID] ? 'text-green-600' : 'text-red-600'"
|
||||
class="text-xs mt-1"></p>
|
||||
<p x-show="webhookResult[cfg.ID]" x-text="webhookResult[cfg.ID]"
|
||||
:class="webhookOk[cfg.ID] ? 'text-green-600' : 'text-red-600'"
|
||||
class="text-xs mt-1"></p>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
@@ -218,6 +227,7 @@ function telegramApp() {
|
||||
deleteModal: false, deleteId: null,
|
||||
form: { nombre: '', bot_token: '', chat_id: '', notas: '', activo: true },
|
||||
testLoading: {}, testResult: {}, testOk: {},
|
||||
webhookLoading: {}, webhookResult: {}, webhookOk: {},
|
||||
sendForm: { config_ids: [], titulo: '', mensaje: '' },
|
||||
sendLoading: false, sendResult: '', sendOk: true,
|
||||
logs: [], logPage: 1, logTotalPages: 1, logTotal: 0,
|
||||
@@ -279,6 +289,17 @@ function telegramApp() {
|
||||
this.$set(this.testResult, cfg.ID, d.ok ? '✅ Mensaje enviado correctamente.' : ('❌ ' + (d.error || 'Error')));
|
||||
this.$set(this.testLoading, cfg.ID, false);
|
||||
},
|
||||
async setWebhook(cfg) {
|
||||
this.$set(this.webhookLoading, cfg.ID, true);
|
||||
this.$set(this.webhookResult, cfg.ID, '');
|
||||
const res = await fetch(`/app/telegram/${cfg.ID}/set-portal-webhook`, { method: 'POST' });
|
||||
const d = await res.json();
|
||||
this.$set(this.webhookOk, cfg.ID, d.ok);
|
||||
this.$set(this.webhookResult, cfg.ID, d.ok
|
||||
? '✅ Webhook registrado: ' + (d.webhook_url || '')
|
||||
: '❌ Error: ' + (d.telegram?.description || d.error || 'Error desconocido'));
|
||||
this.$set(this.webhookLoading, cfg.ID, false);
|
||||
},
|
||||
|
||||
async sendMessage() {
|
||||
this.sendResult = '';
|
||||
|
||||
Reference in New Issue
Block a user