- Versione 1.0.28

- Bottone "Condividi" permette di creare un post Telegram con l'annuncio selezionato.
- migliorata grafica dell'annuncio.
This commit is contained in:
Surya Paolo
2024-02-27 22:08:06 +01:00
parent 3191312372
commit 6ff9922a29
6 changed files with 402 additions and 38 deletions

View File

@@ -9,6 +9,9 @@ const appTelegram_DEVELOP = [tools.RISO];
const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];
const appTeleg_BotOnGroup = [tools.IDAPP_BOTONGROUP];
//PIPPO
const printf = require('util').format;
@@ -722,7 +725,7 @@ const MyTelegramBot = {
}
}
return arrTeleg;
},
@@ -1350,6 +1353,25 @@ const MyTelegramBot = {
invia = true;
} else if (params.cmd === shared_consts.MsgTeleg.SHARE_TEXT) {
invia = !!params.content;
} else if (params.cmd === shared_consts.MsgTeleg.SHARE_ANNUNCIO) {
const mytable = globalTables.getTableByTableName(params.tablerec);
if (params.idrec && params.idrec !== '0') {
// const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
const myrectableorig = await mytable.getCompleteRecord(params.idapp, params.idrec);
if (myrectableorig) {
const eventobj = await tools.getAnnuncioForTelegram(myrectableorig, params.tablerec, '', user.username, false);
if (eventobj) {
params.textcontent_Telegram = eventobj.newdescrtelegram;
params.typesend = shared_consts.TypeSend.TELEGRAM;
//const rismsg =
params.content = eventobj.newdescr;
params.title = '';
invia = true;
}
}
}
}
if (tipomsgtempl > 0) {
@@ -4089,6 +4111,17 @@ function getclTelegBytoken(token) {
return null;
}
// Funzione per ottenere il nome del gruppo
async function getGroupName(bot, groupId) {
try {
const chat = await bot.getChat(groupId);
return chat.title;
} catch (error) {
console.error('Errore durante l\'ottenimento del nome del gruppo:', error);
return null;
}
}
function getclTelegByidapp(idapp) {
// ****************************
if (appTelegramFinti.includes(idapp)) {
@@ -4112,6 +4145,81 @@ if (true) {
internetAvailable().then(() => {
// ..
if (appTeleg_BotOnGroup.length > 0) {
console.log('TELEGRAM BOT GROUP .... ');
for (const idapp of appTeleg_BotOnGroup) {
const token = tools.getTelegramKeyByIdApp(idapp);
const nomebot = tools.getTelegramBotNameByIdApp(idapp);
if (token && nomebot) {
const bot = new TelegramBot(token, { polling: true });
// Gestisce il comando /start
bot.onText(/\/start/, (msg) => {
console.log('START BOT GROUP ... ');
/*
const chatId = msg.chat.id;
const message = 'Benvenuto! Usa il comando /request per inviare una richiesta di accesso al gruppo.';
bot.sendMessage(chatId, message);
*/
});
bot.onText(/\/request/, (msg) => {
const chatId = msg.chat.id;
const fromId = msg.from.id;
const fromUsername = msg.from.username;
const groupId = chatId;
if (chatId == groupId) {
const message = `Richiesta di accesso al gruppo da parte di ${msg.from.first_name} ${msg.from.last_name} (@${fromUsername})`;
bot.sendMessage(groupId, message);
} else {
console.log('Comando /request ricevuto in una chat privata.');
}
});
bot.on('text', (msg) => {
console.log('TEXT...');
const chatId = msg.chat.id;
const userName = msg.from.username || msg.from.first_name;
const userId = msg.from.id;
});
bot.on('new_chat_members', async (msg) => {
const chatId = msg.chat.id;
const newMembers = msg.new_chat_members;
const groupId = chatId;
const nomegruppo = await getGroupName(bot, groupId);
// Ottiene la lista degli amministratori del gruppo
const admins = await bot.getChatAdministrators(chatId);
// Trova l'ID dell'amministratore del gruppo
const adminId = admins.find(admin => admin.status === 'administrator').user.id;
// Verifica se il nuovo membro è stato aggiunto al gruppo
if (chatId == groupId) {
newMembers.forEach(async (member) => {
//const message = `🔑 Nuova Richiesta di accesso al gruppo ${nomegruppo} da parte di ${member.username} (` + member.first_name + ' ' + member.last_name + ')';
const message = `Benvenuto/a ${member.first_name} (${member.username}) sul gruppo "${nomegruppo}" !`;
bot.sendMessage(adminId, message);
// bot.sendMessage(groupId, message);
});
}
});
}
}
}
console.log('TELEGRAM STARTING.... ', process.env.NODE_ENV);
for (const idapp of arrTeleg) {