- 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:
@@ -63583,7 +63583,7 @@ module.exports = {
|
||||
{
|
||||
_id: 5782,
|
||||
istat: '030096',
|
||||
comune: 'Rivignano',
|
||||
comune: 'Rivignano Teor',
|
||||
prov: 'UD',
|
||||
reg: 'FVG',
|
||||
pref: '0432',
|
||||
|
||||
@@ -1812,9 +1812,11 @@ UserSchema.statics.getUserByUsernameTelegram = function (idapp, username_telegra
|
||||
username_telegram = username_telegram.substring(1);
|
||||
}
|
||||
|
||||
let regexp = new RegExp(`^${username_telegram}$`, 'i');
|
||||
|
||||
return User.findOne({
|
||||
idapp,
|
||||
'profile.username_telegram': username_telegram,
|
||||
'profile.username_telegram': { $regex: regexp },
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
};
|
||||
@@ -3925,6 +3927,23 @@ UserSchema.statics.getRealUsernameByUsername = async function (idapp, username)
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getRealUsernameByUsernameTelegram = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
let regexp = new RegExp(`^${username}$`, 'i');
|
||||
|
||||
return await User.findOne({
|
||||
idapp,
|
||||
'profile.username_telegram':
|
||||
{ $regex: regexp },
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}, { username: 1, _id: 1 }).then((rec) => {
|
||||
return (!!rec) ? rec.username : '';
|
||||
}).catch((e) => {
|
||||
console.error('getRealUsernameByUsername', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getRecLangAndIdByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
|
||||
@@ -63583,7 +63583,7 @@ module.exports = {
|
||||
{
|
||||
_id: 5782,
|
||||
istat: '030096',
|
||||
comune: 'Rivignano',
|
||||
comune: 'Rivignano Teor',
|
||||
prov: 'UD',
|
||||
reg: 'FVG',
|
||||
pref: '0432',
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4943,7 +4943,7 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
addRowTelegram(icon, title, content, acapo, islink) {
|
||||
addRowTelegram(icon, title, content, acapo, acapofine, islink) {
|
||||
let mystr = '';
|
||||
|
||||
let descrcontent = content;
|
||||
@@ -4952,11 +4952,16 @@ module.exports = {
|
||||
descrcontent = '';
|
||||
}
|
||||
|
||||
mystr += `${icon} <strong>${title}</strong>\n`;
|
||||
mystr += `${icon} <strong>${title}</strong>`;
|
||||
if (acapo) {
|
||||
mystr += `\n`;
|
||||
} else {
|
||||
mystr += `: `;
|
||||
}
|
||||
if (descrcontent) {
|
||||
mystr += `${descrcontent}\n`;
|
||||
|
||||
if (acapo) {
|
||||
if (acapofine) {
|
||||
mystr += `\n`;
|
||||
}
|
||||
}
|
||||
@@ -5273,7 +5278,7 @@ module.exports = {
|
||||
if (myrec.website) {
|
||||
sitoweb = myrec.website
|
||||
}
|
||||
|
||||
|
||||
contact_phone = myrec.contact_phone || '';
|
||||
contact_email = myrec.contact_email || '';
|
||||
|
||||
@@ -5289,25 +5294,25 @@ module.exports = {
|
||||
if ((myrec.contact_telegram && myrec.contact_telegram.toLowerCase() !== contatto_telegram.toLowerCase()) || !contatto) {
|
||||
contatto += '\n' + myrec.contact_telegram;
|
||||
}
|
||||
if (myrec.contact_phone) {
|
||||
contatto += ' - ' + this.get__('TELEFONO', lang) + ': ' + myrec.contact_phone;
|
||||
}
|
||||
/*if (myrec.contact_phone) {
|
||||
contatto += ' 📞 ' + myrec.contact_phone;
|
||||
}*/
|
||||
|
||||
}
|
||||
// let out = i18n.__('NEW_ANNUNCIO_TELEGRAM', mydescr, dovestr, descrestesa, userorig);
|
||||
|
||||
if (tiposcambio)
|
||||
out += this.addRowTelegram(iconascambio, tiposcambio + status, '', false);
|
||||
out += this.addRowTelegram(iconascambio, tiposcambio + status, '', true, false);
|
||||
|
||||
const url = this.getHostByIdApp(myrec.idapp) + shared_consts.getDirectoryByTable(tablerec, true) + myrec._id;
|
||||
|
||||
out += `<strong>${myrec.descr}</strong>\n\n`;
|
||||
|
||||
if (datastr)
|
||||
out += this.addRowTelegram('✨', 'Data Evento', datastr, true);
|
||||
out += this.addRowTelegram('✨', 'Data Evento', datastr, true, true);
|
||||
|
||||
if (cat)
|
||||
out += this.addRowTelegram('⭐️', 'Categoria', cat, true);
|
||||
out += this.addRowTelegram('⭐️', 'Categoria', cat, true, true);
|
||||
|
||||
let descrcontent = this.convertAndTruncateHTMLForTelegram(myrec.note, 500, url)
|
||||
|
||||
@@ -5318,39 +5323,44 @@ module.exports = {
|
||||
// descrcontent = '<span size="3"><b>Prova Pao</b> Ciaooo</span>';
|
||||
|
||||
if (descrcontent)
|
||||
out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true);
|
||||
out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true, true);
|
||||
|
||||
const localita = this.getComuniEProvinceByRec(myrec);
|
||||
|
||||
if (!solo_online)
|
||||
out += this.addRowTelegram('🏠', 'Località', localita, true);
|
||||
out += this.addRowTelegram('🏠', 'Località', localita, false, true);
|
||||
|
||||
const incambiodi = await this.getInCambioDiByRec(myrec);
|
||||
if (incambiodi)
|
||||
out += this.addRowTelegram('⚖️', 'In cambio di', incambiodi, true);
|
||||
out += this.addRowTelegram('⚖️', 'In cambio di', incambiodi, false, true);
|
||||
|
||||
if (organizedBy) {
|
||||
out += this.addRowTelegram('🏠', 'Organizzato da', organizedBy, true);
|
||||
out += this.addRowTelegram('🏠', 'Organizzato da', organizedBy, false, true);
|
||||
} else {
|
||||
out += this.addRowTelegram('👤', 'Contatto', contatto, true);
|
||||
out += this.addRowTelegram('👤', 'Contatto', contatto, false, true);
|
||||
}
|
||||
|
||||
if (contributo)
|
||||
out += this.addRowTelegram('💰', 'Contributo Richiesto', contributo, true);
|
||||
out += this.addRowTelegram('💰', 'Contributo Richiesto', contributo, false, true);
|
||||
|
||||
if (contact_phone || contact_email || sitoweb) {
|
||||
out += this.addRowTelegram('ℹ️', 'Info',
|
||||
out += this.addRowTelegram('ℹ️', 'Per Info:',
|
||||
(contact_phone ? ('📞 ' + contact_phone + ' ') : '')
|
||||
+ (contact_email ? (' 📨 ' + contact_email + ' ') : '')
|
||||
+ (sitoweb ? (' 🌐 ' + sitoweb + ' ') : '')
|
||||
, true);
|
||||
, true, true);
|
||||
}
|
||||
|
||||
if (writtenby && organizedBy) {
|
||||
out += this.addRowTelegram('✍️', 'Redatto da', '@' + writtenby, true);
|
||||
out += this.addRowTelegram('✍️', 'Redatto da', '@' + writtenby, false, true);
|
||||
}
|
||||
|
||||
out += this.addRowTelegram('', `👉🏻 Vedi Annuncio completo su RISO`, url, true, true);
|
||||
let cosastr = 'Annuncio';
|
||||
if (tablerec === shared_consts.TABLES_MYBACHECAS) {
|
||||
cosastr = 'Evento';
|
||||
}
|
||||
|
||||
out += this.addRowTelegram('', `👉🏻 Vedi ${cosastr} completo su RISO`, url, true, true, true);
|
||||
|
||||
if (myrec.photos && myrec.photos.length > 0) {
|
||||
// prende la prima foto ! ;
|
||||
|
||||
@@ -408,7 +408,7 @@ module.exports = {
|
||||
|
||||
const allquery = { ...query, ...addquery };
|
||||
|
||||
const arrusers = await User.find(
|
||||
let arrusers = await User.find(
|
||||
allquery,
|
||||
{
|
||||
username: 1,
|
||||
@@ -417,6 +417,9 @@ module.exports = {
|
||||
},
|
||||
).lean();
|
||||
|
||||
if (!tools.sulServer()) {
|
||||
arrusers = await User.find({ idapp, username: telegrambot.ADMIN_USER_SERVER });
|
||||
}
|
||||
|
||||
for (const user of arrusers) {
|
||||
|
||||
@@ -461,7 +464,12 @@ module.exports = {
|
||||
risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, text, undefined, undefined, undefined, undefined, params.img);
|
||||
await tools.snooze(25);
|
||||
|
||||
textsent = risult.text;
|
||||
try {
|
||||
if (risult && (risult.text || risult.caption))
|
||||
textsent = (risult.text || risult.caption);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.1.9
|
||||
1.1.11
|
||||
Reference in New Issue
Block a user