]*>|<\/div>/gi;
const finalText = cleanedText.replace(divRegex, '');
return finalText;
},
firstchars(value, numchars = 200, continua, link) {
if (!value) {
return '';
}
try {
value = this.convertHTMLTagsForTelegram(value);
value = this.removeSpanAndDivTags(value);
truncatedValue = this.truncateString(value, numchars);
// Aggiungi il testo aggiuntivo per indicare il troncamento
if (continua) {
if (link) {
truncatedValue += `
(... continua sulla App)`;
} else {
truncatedValue += `
(... continua sulla App)`;
}
} else {
truncatedValue += ' ...';
}
return truncatedValue;
} catch (e) {
return value;
}
},
convertHTMLTagsForTelegram(text) {
const htmlTagsMap = {
'
': '',
'': '',
'': '',
'': '',
'': '',
};
// Sostituzione dei tag HTML con quelli Markdown supportati da Telegram
let convertedText = text;
for (const htmlTag in htmlTagsMap) {
const regex = new RegExp(htmlTag, 'g');
convertedText = convertedText.replace(regex, htmlTagsMap[htmlTag]);
}
return convertedText;
},
removeFontTags(text) {
// Rimozione dei tag e dalla stringa di testo
const regex = /]*>|<\/font>/gi;
const cleanedText = text.replace(regex, '');
return cleanedText;
},
removeAtChar(mystr) {
if (mystr && mystr[0] === '@') {
return mystr = mystr.substring(1);
}
return mystr;
},
updateQueryStringParameter(uri, key, value) {
if (uri === '' || !uri)
return '';
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
if (uri.match(re)) {
return uri.replace(re, '$1' + key + '=' + value + '$2');
} else {
return uri + separator + key + '=' + value;
}
},
isArray(val) {
return Array.isArray(val);
},
getContentByTypeMsg(typemsg) {
},
getContentNotifByParams(params, content, typesend) {
if (typesend === shared_consts.TypeSend.TELEGRAM) {
let myhost = this.getHostByIdApp(params.idapp);
if (params.textaddTelegram) {
content = content + '\n' + params.textaddTelegram;
}
if (params.linkaddTelegram) {
if (params.openUrl)
content = content + '\n' + '' + params.linkaddTelegram + '';
}
/*if (params.openUrl)
content = content + '\n' + '' + i18n.__('OPEN PAGE') + '';
*/
}
return content;
},
getAhref(username, link) {
return `${username}`;
},
replaceStringAtEnd(inputString, searchString, replacement) {
// Create a regular expression that matches the searchString at the end of the inputString
const regex = new RegExp(searchString + '$');
// Use the replace method with the regular expression to replace the string
const result = inputString.replace(regex, replacement);
return result;
},
getstrDateTimeEvent(myevent) {
let mystr = '';
// is same day?
if (this.getstrDateShort(myevent.dateTimeStart) === this.getstrDateShort(myevent.dateTimeEnd)) {
mystr = i18n.__('DATEDAYONLY', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
this.getstrTime(myevent.dateTimeEnd))
} else {
mystr = i18n.__('DATE_2DAYS', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
this.getstrDateLong(myevent.dateTimeEnd), this.getstrTime(myevent.dateTimeEnd))
}
return '🗓 ' + mystr;
},
getDoveStrByEvent(myrec) {
let dove = '🏠 ';
if (myrec.mycities && myrec.mycities.length > 0) {
dove += myrec.mycities[0].comune + ' (' + myrec.mycities[0].prov + ')'
}
return dove;
},
async getDescrEstesaStrByEvent(myrec) {
let mystr = '';
mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, ' ', ''), 800);
if (mystr)
mystr = 'ℹ️ ' + mystr
return mystr;
},
async getEventForTelegram(myrec, mydescr, userorig) {
try {
let datastr = this.getstrDateTimeEvent(myrec);
let dovestr = this.getDoveStrByEvent(myrec);
let descrestesa = await this.getDescrEstesaStrByEvent(myrec);
let organizedby = myrec.organisedBy;
let contributo = myrec.contribstr;
let newdescr = i18n.__('NEW_EVENT', userorig, datastr, mydescr, dovestr);
let newdescrtelegram = i18n.__('NEW_EVENT_TELEGRAM', datastr, mydescr, dovestr, descrestesa, userorig);
if (organizedby) {
newdescrtelegram += i18n.__('ORGANIZED_BY', organizedby);
}
if (contributo) {
newdescrtelegram += i18n.__('CONTRIB', contributo);
}
newdescrtelegram += i18n.__('EVENT_ADDED_FROM', userorig);
return { newdescr, newdescrtelegram }
} catch (e) {
console.error('Error', e);
}
},
addRowTelegram(icon, title, content, acapo, islink) {
let mystr = '';
let descrcontent = content;
if (islink) {
title = `