Notifica Telegram e Push quando mandi la stretta di mano
This commit is contained in:
@@ -25,3 +25,7 @@ Gio 05/01 ORE 19:28: USER [paoloar77]: vai al sito
|
||||
Gio 05/01 ORE 19:28: USER [paoloar77]: link da condividere
|
||||
|
||||
Gio 16/02 ORE 18:14: USER [paoloar77]: vai al sito
|
||||
|
||||
Mar 06/06 ORE 19:39: USER [paoloar77]: ciaooooooooooooooooo
|
||||
|
||||
Mar 06/06 ORE 19:54: USER [paoloar77]: dasjdalksjdasdklasjkldasjlkdjasl
|
||||
|
||||
13
logevents.txt
Normal file
13
logevents.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
Mar 06/06 ORE 19:06: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:07: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:38: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:39: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
ciaooooooooooooooooo
|
||||
Mar 06/06 ORE 19:49: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:54: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
dasjdalksjdasdklasjkldasjlkdjasl
|
||||
@@ -14,6 +14,8 @@
|
||||
"✅ %s accepted your Friendship request !": "✅ %s ha accettato la tua richiesta di Amicizia !",
|
||||
"✅ You have accepted %s' Friendship request!": "✅ Hai accettato la richiesta di Amicizia di %s !",
|
||||
"HANDSHAKE_SET": "<strong>%s</strong> ha comunicato che ti conosce personalmente e ha fiducia in te.",
|
||||
"HANDSHAKE_CONFIRMED": "🤝 Hai contraccambiato la fiducia in <strong>%s</strong>!",
|
||||
"HANDSHAKE_ACCEPTED": "🤝 <strong>%s</strong> ha contraccambiato la fiducia in te !",
|
||||
"GROUPS_ACCEPTED": "✅ Sei stato accettato a far parte del Gruppo %s (da parte di %s)",
|
||||
"GROUPS_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del Gruppo %s. Se pensi sia un'errore, contatta l'amministratore del Gruppo.",
|
||||
"GROUPS_REMOVED": "❌ l'utente %s è stato rimosso del Gruppo %s (da parte di %s)",
|
||||
@@ -95,5 +97,5 @@
|
||||
"EVENT_SEND_MSG": "%s ha mandato un messaggio sull'evento %s: \n%s",
|
||||
"SET_ATTEND": "%s ha detto che Parteciperà all'evento: %s",
|
||||
"SET_ATTEND_OTHERS": "%s e altre %s persone hanno detto che Parteciperanno all'evento: %s",
|
||||
"CLICCA_QUI": "CLICCA_QUI"
|
||||
"CLICCA_QUI": "CLICCA QUI"
|
||||
}
|
||||
@@ -122,6 +122,7 @@ const SiteSchema = new Schema({
|
||||
enableRegMultiChoice: { type: Boolean },
|
||||
enableDebugOn: { type: Boolean },
|
||||
enabledRegNeedTelegram: { type: Boolean },
|
||||
showViewEventi: { type: Boolean },
|
||||
showViewGroups: { type: Boolean },
|
||||
showViewCircuits: { type: Boolean },
|
||||
showViewUsers: { type: Boolean },
|
||||
|
||||
@@ -2165,7 +2165,7 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
//}
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.SETHANDSHAKE) {
|
||||
// Aggiungo la Stretta di mano a lui
|
||||
const foundIfAlreadyFriend = await User.findOne({
|
||||
const foundIfAlreadyHandshake = await User.findOne({
|
||||
idapp,
|
||||
username: usernameDest,
|
||||
'profile.handshake': {
|
||||
@@ -2175,7 +2175,7 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
|
||||
let rec = null;
|
||||
|
||||
if (!foundIfAlreadyFriend) {
|
||||
if (!foundIfAlreadyHandshake) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.handshake': {
|
||||
@@ -2186,12 +2186,28 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
};
|
||||
rec = await User.updateOne({ idapp, username: usernameDest }, update);
|
||||
|
||||
if (!disablenotif) {
|
||||
// Send a notification to the DESTINATION HANDSHAKE !
|
||||
let req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
|
||||
shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
|
||||
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true, usernameOrig);
|
||||
let req = tools.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
if (rec) {
|
||||
try {
|
||||
if (!disablenotif) {
|
||||
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
|
||||
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
|
||||
const msgDest = i18n.__({ phrase: 'HANDSHAKE_CONFIRMED', locale: userDest.lang }, usernameDest);
|
||||
const msgOrig = i18n.__({ phrase: 'HANDSHAKE_ACCEPTED', locale: user.lang }, usernameOrig);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Send a notification to the DESTINATION HANDSHAKE !
|
||||
// await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, false, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
|
||||
// shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
|
||||
}
|
||||
|
||||
const userprofile = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
@@ -3409,8 +3425,8 @@ UserSchema.statics.getNameSurnameById = async function (idapp, userId) {
|
||||
|
||||
UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({ idapp, 'profile.manage_telegram': true },
|
||||
// Int32 mongodb 6.0
|
||||
return await User.find({ idapp, 'profile.manage_telegram': true , perm: { $bitsAnySet: 0b010 } },
|
||||
{ username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
@@ -3418,6 +3434,19 @@ UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getusersAdmin = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
// Int32 mongodb 6.0
|
||||
|
||||
return await User.find({ idapp, 'profile.manage_telegram': true, perm: { $bitsAnySet: 0b001 } },
|
||||
{ username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getusersAdmin', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getusersRespList = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
@@ -3500,7 +3529,7 @@ UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) {
|
||||
}, { 'profile.teleg_id': 1 }).then((rec) => {
|
||||
return (!!rec && rec.profile.teleg_id === idtelegram);
|
||||
}).catch((e) => {
|
||||
console.error('getusersManagers', e);
|
||||
console.error('isManagerByIdTeleg', e);
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -709,7 +709,7 @@ const MyTelegramBot = {
|
||||
MyForm = null) {
|
||||
|
||||
if (!idtelegram)
|
||||
return;
|
||||
return {text: ''};
|
||||
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
if (cl && idtelegram) {
|
||||
@@ -718,6 +718,8 @@ const MyTelegramBot = {
|
||||
chat_id, ripr_menuPrec);
|
||||
}
|
||||
|
||||
return {text: ''};
|
||||
|
||||
},
|
||||
|
||||
deleteRecInMemByUsername: function (idapp, username_bo) {
|
||||
@@ -977,14 +979,14 @@ const MyTelegramBot = {
|
||||
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_HANDSHAKE) {
|
||||
sendnotif = true;
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE;
|
||||
typeid = shared_consts.TypeNotifs.ID_HANDSHAKE_NEW_REC;
|
||||
typeid = shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED;
|
||||
paramsObj = { usernameDest: userDest };
|
||||
|
||||
domanda = printf(tools.gettranslate('RICHIESTA_HANDSHAKE', langdest), myuser.username) + '<br>' + struserinfomsg;
|
||||
|
||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
{
|
||||
text: '✅🤝 Ricambia la fiducia',
|
||||
text: '✅🤝 Ricambia la stretta di mano',
|
||||
callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + userDest + tools.SEP + '',
|
||||
},
|
||||
]);
|
||||
@@ -1153,7 +1155,7 @@ sendMsgTelegramToTheAdminAllSites: async function (text, senzaintestazione) {
|
||||
},
|
||||
|
||||
sendMsgTelegramToTheAdmin: async function (idapp, text, senzaintestazione) {
|
||||
const usersmanagers = await User.getusersManagers(idapp);
|
||||
const usersmanagers = await User.getusersAdmin(idapp);
|
||||
|
||||
let intestaz = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': ';
|
||||
if (senzaintestazione)
|
||||
@@ -1300,39 +1302,6 @@ sendMsgFromSiteToBotTelegram: async function (idapp, user, params) {
|
||||
|
||||
};
|
||||
|
||||
async function sendMsgTelegramToTheAdmin(idapp, text, msg) {
|
||||
const usersmanagers = await User.getusersManagers(idapp);
|
||||
|
||||
const clorig = getclTelegByidapp(idapp);
|
||||
const rec = clorig.getRecInMem(msg);
|
||||
let username = '';
|
||||
if (!!rec) {
|
||||
username = rec.username_bo;
|
||||
} else {
|
||||
username = msg.chat.username;
|
||||
}
|
||||
|
||||
text = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': Da ' +
|
||||
msg.chat.first_name + ' ' + msg.chat.last_name + ' [' + username +
|
||||
']: \n' + text;
|
||||
tools.writeEventsLog(text);
|
||||
|
||||
if (usersmanagers) {
|
||||
for (const rec of usersmanagers) {
|
||||
if (User.isAdmin(rec.perm)) {
|
||||
const idtelegram = rec.profile.teleg_id;
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
if (cl && idtelegram) {
|
||||
await cl.sendMsg(idtelegram, text);
|
||||
}
|
||||
await tools.snooze(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
async function setVerifiedReg(idapp, lang, usernameorig, usernameDest) {
|
||||
try {
|
||||
await User.setVerifiedByAportador(idapp, usernameorig, true);
|
||||
@@ -1384,6 +1353,32 @@ async function local_sendMsgTelegramToTheManagers(
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
async function local_sendMsgTelegramToTheAdmin(
|
||||
idapp, text, msg, username_bo) {
|
||||
const usersAdmin = await User.getusersAdmin(idapp);
|
||||
|
||||
let username = msg.chat.username;
|
||||
if (username_bo)
|
||||
username = username_bo;
|
||||
|
||||
text = emo.ROBOT_FACE + ': Da ' + msg.chat.first_name + ' ' +
|
||||
msg.chat.last_name + ' (' + username + '): \n' + text;
|
||||
tools.writeEventsLog(text);
|
||||
|
||||
if (usersAdmin) {
|
||||
for (const rec of usersAdmin) {
|
||||
const idtelegram = rec.profile.teleg_id;
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
if (cl && idtelegram) {
|
||||
await cl.sendMsg(idtelegram, text, undefined, undefined, undefined,
|
||||
undefined, true);
|
||||
}
|
||||
await tools.snooze(100);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
async function local_sendMsgTelegram(idapp, username, text) {
|
||||
@@ -3090,9 +3085,12 @@ class Telegram {
|
||||
}
|
||||
|
||||
const rec = this.getRecInMem(msg);
|
||||
let testo = msg.text.toLowerCase().trim();
|
||||
|
||||
status = this.getstatus(rec);
|
||||
if (status === Status.WAITFOR_USERNAME_TELEGRAM && !this.selectMenuHelp(msg) && !this.selectMenuLang(msg)) {
|
||||
if (testo === Menu.EXIT_TELEGRAM) {
|
||||
await this.menuExitToTelegram(msg);
|
||||
}else if (status === Status.WAITFOR_USERNAME_TELEGRAM && !this.selectMenuHelp(msg) && !this.selectMenuLang(msg)) {
|
||||
// await this.setUsernameBo(msg);
|
||||
await this.settotheDatabase(msg);
|
||||
} else if (status === Status.WAITFOR_USERNAME_INVITANTE && !this.selectMenuHelp(msg) && !this.selectMenuLang(msg)) {
|
||||
@@ -4037,6 +4035,8 @@ if (true) {
|
||||
|
||||
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
||||
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
||||
// Invia questo msg anche all'Admin
|
||||
await local_sendMsgTelegramToTheAdmin(user.idapp, msgDest, msg, data.userDest);
|
||||
}
|
||||
|
||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.REGISTRATION) {
|
||||
@@ -4136,12 +4136,12 @@ if (true) {
|
||||
|
||||
if (userDest) {
|
||||
cmd = shared_consts.FRIENDSCMD.SETHANDSHAKE;
|
||||
const foundIfAlreadyFriend = await User.isMyHandShake(user.idapp, data.username, data.userDest);
|
||||
const foundIfAlreadyFriend = await User.isMyHandShake(user.idapp, data.userDest, data.username);
|
||||
|
||||
if (!foundIfAlreadyFriend) {
|
||||
// Aggiungilo nelle HandShake
|
||||
const req = tools.getReqByPar(user.idapp, username_action);
|
||||
const ris = await User.setFriendsCmd(req, user.idapp, data.username, data.userDest, cmd);
|
||||
const ris = await User.setFriendsCmd(req, user.idapp, data.userDest, data.username, cmd);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -922,7 +922,12 @@ module.exports = {
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.SETHANDSHAKE) {
|
||||
// const foundIfAlready = await User.isMyHandShake(idapp, username, usernameOrig);
|
||||
const userrecDest = await User.getUserShortDataByUsername(idapp, usernameOrig);
|
||||
|
||||
const foundIfAlready = await User.isMyHandShake(idapp, username, usernameOrig);
|
||||
if (!foundIfAlready) {
|
||||
telegrambot.askConfirmationUserFriend(idapp, shared_consts.CallFunz.RICHIESTA_HANDSHAKE, userrecDest, username, usernameOrig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user