@fgalanj/telegramclient 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +15 -0
  2. package/telegramClient.js +90 -0
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@fgalanj/telegramclient",
3
+ "version": "1.0.1",
4
+ "description": "telegramClient",
5
+ "main": "telegramClient.js",
6
+ "scripts": {
7
+ "test": "node telegramClient.js"
8
+ },
9
+ "keywords": [
10
+ "telegram",
11
+ "client"
12
+ ],
13
+ "author": "FGalanSoftware",
14
+ "license": "ISC"
15
+ }
@@ -0,0 +1,90 @@
1
+ // ***********************************************************************************************
2
+ // * *
3
+ // * Fco Galan Software Ltd. *
4
+ // * *
5
+ // * telegramClient.js *
6
+ // * *
7
+ // * *
8
+ // * Copyright (c) 1980-2026 *
9
+ // * *
10
+ // ***********************************************************************************************
11
+ //
12
+ // ***********************************************************************************************
13
+ // * Copyright (c) 1980-2026 FGalan Software and its licensors. *
14
+ // * All rights reserved. *
15
+ // * Without the owner's prior written consent, *
16
+ // * no decompiling or reverse-engineering shall be allowed. *
17
+ // ***********************************************************************************************
18
+ //
19
+ // ***********************************************************************************************
20
+ // Aplicacion : Telegram-notifier: Envio de mensajes por telegram
21
+ // Modulo : telegramClient.js
22
+ // Envia un mensaje por telegram desde una app
23
+ // Lenguaje : node.js v12.16.3
24
+ // Historia de cambios:
25
+ // ***********************************************************************************************
26
+ // Version Fecha Programador Descripcion del cambio
27
+ // ------- ---------- ----------- -------------------------------------------------------------
28
+ // 1.0.1.0 2026/06/04 Fco Galan Version inicial
29
+ // Usa la API de mensajeria CS360
30
+ // para enviar un mensaje a traves de telegram
31
+ // Cliente reutilizable para invocar la API de Telegram
32
+ // Compatible con navegador (HTML) y Node.js (UMD)
33
+ // Envio de datos via body JSON (estandar REST)
34
+ // Documentacion
35
+ // ***********************************************************************************************
36
+ //
37
+
38
+ // Definir URL base de la API (sin parametros en la URL)
39
+ const API_URL = 'http://localhost:8040/mensaje';
40
+
41
+ // Determinar el entorno del llamado
42
+ (function(root, factory) {
43
+ // Deteccion del entorno
44
+ if (typeof module === 'object' && module.exports) {
45
+ // Entorno servidor: Node.js
46
+ module.exports = factory();
47
+ } else {
48
+ // Entorno navegador: exponer como variable global TelegramClient
49
+ root.TelegramClient = factory();
50
+ }
51
+ }(typeof self !== 'undefined' ? self : this, function() {
52
+
53
+ // *******************************************************************************************
54
+ // Funcion: enviarMensaje(mensaje)
55
+ // Descripcion: Invoca la API POST /mensaje enviando el texto en el body como JSON
56
+ // Segun el estandar REST, los datos de POST van en el cuerpo de la peticion
57
+ // Parametros: mensaje - Cadena a enviar (si es vacia/nula, el servidor usa la omision)
58
+ // Retorno: Promise que resuelve con la cadena "resultado" devuelta por la API
59
+ // *******************************************************************************************
60
+ // Enviar mensaje
61
+ async function enviarMensaje(mensaje) {
62
+ try {
63
+ // Preparar el body como objeto JSON
64
+ const body = {
65
+ mensajeEnviar: mensaje || ''
66
+ };
67
+
68
+ // Realizar la peticion POST con body JSON
69
+ const response = await fetch(API_URL, {
70
+ method: 'POST',
71
+ headers: {
72
+ 'Accept': 'application/json',
73
+ 'Content-Type': 'application/json' // Indicar que enviamos JSON
74
+ },
75
+ body: JSON.stringify(body) // Serializar el objeto a JSON
76
+ });
77
+
78
+ const data = await response.json();
79
+ return data.resultado;
80
+ } catch (error) {
81
+ // Error de red (servidor caido, CORS, etc.)
82
+ return 'Error de conexion con la API: ' + error.message;
83
+ }
84
+ }
85
+
86
+ // Definir API publica del modulo
87
+ return {
88
+ enviarMensaje: enviarMensaje
89
+ };
90
+ }));