- fix: Invio RIS (non si vedevano i circuiti !)
- se si usava l'username telegram per registrarsi non faceva il controllo delle minuscole. - bottone "Invia RIS" era scomparso
This commit is contained in:
@@ -24,6 +24,8 @@ const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const sharp = require('sharp');
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
// const {ListaIngresso} = require('../models/listaingresso');
|
||||
@@ -911,13 +913,15 @@ const MyTelegramBot = {
|
||||
|
||||
if (myfunc === shared_consts.CallFunz.REGISTRATION) {
|
||||
|
||||
cl.setPhotoProfile(myuser, telegid, false);
|
||||
if (telegid > 0) {
|
||||
cl.setPhotoProfile(myuser, telegid, false);
|
||||
|
||||
const rismsg = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MSG_BENVENUTO, myuser.lang);
|
||||
const rismsg2 = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MS_SHARE_LINK, myuser.lang);
|
||||
const rismsg = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MSG_BENVENUTO, myuser.lang);
|
||||
const rismsg2 = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MS_SHARE_LINK, myuser.lang);
|
||||
|
||||
await cl.sendMsgLog(telegid, rismsg.body);
|
||||
await cl.sendMsg(telegid, rismsg2.body);
|
||||
await cl.sendMsgLog(telegid, rismsg.body);
|
||||
await cl.sendMsg(telegid, rismsg2.body);
|
||||
}
|
||||
|
||||
userDest = myuser.aportador_solidario;
|
||||
let notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
|
||||
@@ -3813,6 +3817,85 @@ class Telegram {
|
||||
|
||||
}
|
||||
|
||||
// Soluzione 1: Converti PNG in JPG prima dell'invio
|
||||
async sendPhoto(chatId, imageUrl, opt) {
|
||||
try {
|
||||
// Scarica l'immagine
|
||||
const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
|
||||
const imageBuffer = Buffer.from(response.data);
|
||||
|
||||
// Controlla il formato e converti se necessario
|
||||
const metadata = await sharp(imageBuffer).metadata();
|
||||
|
||||
if (metadata.format === 'png') {
|
||||
console.log('Conversione PNG in JPG...');
|
||||
const jpgBuffer = await sharp(imageBuffer)
|
||||
.jpeg({ quality: 90 })
|
||||
.toBuffer();
|
||||
|
||||
return await this.bot.sendPhoto(chatId, jpgBuffer, opt);
|
||||
}
|
||||
|
||||
// Se non è PNG, invia direttamente
|
||||
return await this.bot.sendPhoto(chatId, imageBuffer, opt);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Errore nell\'invio della foto:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Soluzione 2: Prova prima come PNG, se fallisce invia come documento
|
||||
async sendPhotoWithFallback(chatId, imageUrl, opt) {
|
||||
try {
|
||||
// Prova prima a inviare come foto
|
||||
await this.bot.sendPhoto(chatId, imageUrl, opt);
|
||||
} catch (error) {
|
||||
console.log('Invio come foto fallito, provo come documento...');
|
||||
try {
|
||||
// Se fallisce, invia come documento
|
||||
await this.bot.sendDocument(chatId, imageUrl, opt);
|
||||
} catch (docError) {
|
||||
console.error('Anche l\'invio come documento è fallito:', docError);
|
||||
throw docError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Soluzione 3: Implementazione completa con gestione errori e tentativi multipli
|
||||
async sendImageToTelegram(chatId, imageUrl, opt) {
|
||||
try {
|
||||
// Prima prova: invia direttamente l'URL
|
||||
try {
|
||||
return await this.bot.sendPhoto(chatId, imageUrl, opt);
|
||||
} catch (error) {
|
||||
console.log('Primo tentativo fallito, provo a convertire...');
|
||||
}
|
||||
|
||||
// Seconda prova: scarica e converti in JPG
|
||||
const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
|
||||
const imageBuffer = Buffer.from(response.data);
|
||||
|
||||
const jpgBuffer = await sharp(imageBuffer)
|
||||
.jpeg({ quality: 90 })
|
||||
.toBuffer();
|
||||
|
||||
try {
|
||||
return await this.bot.sendPhoto(chatId, jpgBuffer, opt);
|
||||
} catch (error) {
|
||||
console.log('Secondo tentativo fallito, provo come documento...');
|
||||
}
|
||||
|
||||
// Ultima prova: invia come documento
|
||||
return await this.bot.sendDocument(chatId, imageBuffer, opt);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Tutti i tentativi di invio sono falliti:', error);
|
||||
return false;
|
||||
//throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async _inviaMsg(id, text, form, menu, msg_id, chat_id, ripr_menuPrec, opt) {
|
||||
if (!text)
|
||||
return 0;
|
||||
@@ -3884,10 +3967,20 @@ class Telegram {
|
||||
}
|
||||
|
||||
|
||||
let inviato = false;
|
||||
|
||||
let risSendPhoto = null;
|
||||
|
||||
if (opt && opt.img) {
|
||||
if (false) {
|
||||
opt.img = 'https://riso.app/upload/profile/paoloar77/mybachecas/Fermentazione-Ruello-sito.png';
|
||||
//opt.img = 'https://riso.app/upload/profile/paoloar77/mybachecas/Fermentazione-Ruello-sito.jpg';
|
||||
// opt.img = 'https://riso.app/upload/profile/SoniaVioletFlame/myskills/1000133092.jpg';
|
||||
}
|
||||
opt.img = tools.fixUrl(opt.img, opt.idapp);
|
||||
console.log('opt.img', opt.img)
|
||||
return this.bot.sendPhoto(id, opt.img, { caption: text, ...form }).catch((e) => {
|
||||
risSendPhoto = await this.sendImageToTelegram(id, opt.img, { caption: text, ...form });
|
||||
/*return this.bot.sendPhoto(id, opt.img, { caption: text, ...form }).catch((e) => {
|
||||
let blocked = false;
|
||||
if ((e.message.indexOf('Forbidden') > 0) ||
|
||||
(e.message.indexOf('chat not found') > 0)) {
|
||||
@@ -3901,8 +3994,13 @@ class Telegram {
|
||||
// ++Todo: DA FARE ! local_sendMsgTelegramToTheManagers(this.idapp, addtext + text);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
});*/
|
||||
}
|
||||
|
||||
if (risSendPhoto) {
|
||||
inviato = true;
|
||||
}
|
||||
if (!inviato) {
|
||||
return this.bot.sendMessage(id, text, form).catch((e) => {
|
||||
let blocked = false;
|
||||
if ((e.message.indexOf('Forbidden') > 0) ||
|
||||
@@ -3920,6 +4018,8 @@ class Telegram {
|
||||
});
|
||||
}
|
||||
|
||||
return risSendPhoto
|
||||
|
||||
} catch (e) {
|
||||
console.error(e, 'text', text);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user