Impostato la lingua fissa a ITALIANO: ancora non ci sono le traduzioni e poi qualcosa sul server fa casino (non arrivano le richieste...)

Risolto Bug sui messaggi di registrazione, se l'utente non aveva l'Username Telegram
This commit is contained in:
paoloar77
2022-03-08 01:01:20 +01:00
parent 466fdd597d
commit 82e3ed7175
11 changed files with 209 additions and 96 deletions

View File

@@ -254,6 +254,7 @@ const Menu = {
AIUTO: '🔮 Help',
ALTRO: emoji.get('newspaper') + ' Altro',
SETPICPROFILE: '🖼 SetPicProfile',
RESETPWD: '🔑 SetResetPwd',
// MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi',
// MSG_NO_7_REQ: emoji.get('incoming_envelope') + 'No 7 Req.',
// MSG_NO_9_REQ: emoji.get('incoming_envelope') + 'No 9 Req',
@@ -490,12 +491,14 @@ const txt = {
'👉🏻 3.Premi su <b>Username</b> nella sezione account.\n' +
'👉🏻 4. Digita il tuo username. Deve essere un nome ancora libero e non già usato da altri.\n' +
'👉🏻 5. Per confermare premi sull\'icona con la spunta in alto a destra.\n' +
'🏁 Infine scrivi OK su questa chat. \n\n' +
'🏁 Infine scrivi OK su questa chat. \n' +
'(Se non riesci clicca qui per la guida: www.nigiara.it/telegram/come-impostare-uno-username-su-telegram.htm) \n\n' +
'💬 In questo modo le persone potranno contattarti dalla APP cliccando sull\'icona di Telegram, presente nel tuo profilo.',
MSG_SET_USERNAME_OK: '😄😄✅✅ Ottimo! Hai impostato lo Username Telegram!\n\n' +
'Ora le persone potranno contattarti su Telegram, anche dalla APP visitando il tuo profilo e cliccando sull\'icona di Telegram, (senza dover pubblicare il proprio numero di cellulare).\n\n' +
'Ora puoi proseguire sulla APP.',
MSG_SET_PICPROFILE: '🖼 Abbiamo impostato <b>la tua foto del Profilo</b>, copiandola dalla foto profilo di Telegram. Potrai comunque cambiarla dalla APP (%s)',
MSG_RESETPWD: 'Clicca qui per impostare una nuova password per accedere alla APP:',
MSG_ERR_UNKNOWN_VERIFY_CODE: 'Errore durante il salvataggio sul Server. Riprovare piú tardi',
MSG_EXIT_TELEGRAM: 'L\'account è stato ora scollegato da questo Telegram BOT.',
MSG_APORTADOR_USER_REGISTERED: emo.FIRE +
@@ -922,13 +925,13 @@ const MyTelegramBot = {
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
},
askConfirmationUser: async function(idapp, myfunc, myuser, userDest = '', {groupname, groupid}) {
const cl = getclTelegByidapp(idapp);
askConfirmationUser: async function(idapp, myfunc, myuser, userDest = '', groupname = '', groupid = '') {
try {
const cl = getclTelegByidapp(idapp);
const langdest = myuser.lang;
const telegid = myuser.profile.teleg_id;
let keyb = null;
let domanda = '';
@@ -936,12 +939,21 @@ const MyTelegramBot = {
const struserinfomsg = tools.getUserInfoMsg(idapp, myuser);
if (myfunc === shared_consts.CallFunz.REGISTRATION) {
cl.setPhotoProfile(myuser, telegid, false);
const rismsg = await MsgTemplate.getMsgByLang(idapp, shared_consts.TypeMsgTemplate.MSG_BENVENUTO, myuser.lang);
const rismsg2 = await MsgTemplate.getMsgByLang(idapp, shared_consts.TypeMsgTemplate.MS_SHARE_LINK, myuser.lang);
await cl.sendMsgLog(telegid, rismsg.body);
await cl.sendMsg(telegid, rismsg2.body);
userDest = myuser.aportador_solidario;
const notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
if (notask_verif) {
// Non chiedi la verifica Registrazione
setVerifiedReg(myuser.idapp, myuser.lang, myuser.username, userDest);
await setVerifiedReg(myuser.idapp, myuser.lang, myuser.username, userDest);
} else {
domanda = getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM') + '<br>' + struserinfomsg;
@@ -968,7 +980,7 @@ const MyTelegramBot = {
},
{
text: '🚫 Rifiuta ' + myuser.username,
callback_data: InlineConferma.RISPOSTA_NO + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + groupid ,
callback_data: InlineConferma.RISPOSTA_NO + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + groupid,
},
]);
}
@@ -1276,8 +1288,7 @@ async function sendMsgTelegramToTheAdmin(idapp, text, msg) {
async function setVerifiedReg(idapp, lang, usernameorig, usernameDest) {
try {
await User.setVerifiedByAportador(idapp, usernameorig, true);
await User.setFriendsCmd(idapp, usernameorig, usernameDest,
shared_consts.FRIENDSCMD.SETFRIEND);
await User.setFriendsCmd(idapp, usernameorig, usernameDest, shared_consts.FRIENDSCMD.SETFRIEND);
const msgDest = printf(getstr(lang, 'MSG_APORTADOR_CONFIRMED'),
`${usernameorig}`, usernameDest);
@@ -1510,15 +1521,14 @@ class Telegram {
if (rec.status === Status.VERIFIED) {
if (rec.user) {
if (rec.user.profile.username_telegram && msg.from.id > 0 &&
!msg.from.username) {
if (rec.user.profile.username_telegram && msg.from.id > 0 && !msg.from.username) {
rec.user.profile.username_telegram = msg.from.username;
await User.setUsernameTelegram(this.idapp, rec.user._id,
msg.from.username || '', msg.from.first_name || '',
msg.from.last_name || '');
}
if (!rec.user.profile.username_telegram && msg.from.username) {
if (!rec.user.profile.username_telegram && !!msg.from.username) {
rec.user.profile.username_telegram = msg.from.username;
await User.setUsernameTelegram(this.idapp, rec.user._id,
msg.from.username || '', msg.from.first_name || '',
@@ -1527,7 +1537,7 @@ class Telegram {
printf(getstr(rec.user.lang, 'MSG_SET_USERNAME_OK')));
if (!rec.user.verified_by_aportador) {
this.askConfirmationUser(this.idapp, shared_consts.CallFunz.REGISTRATION, rec.user);
MyTelegramBot.askConfirmationUser(this.idapp, shared_consts.CallFunz.REGISTRATION, rec.user);
}
} else {
@@ -1843,7 +1853,9 @@ class Telegram {
} else if (cmd1.toLowerCase() === Menu.MSG_TO_USER) {
await this.menumsg_A_Utente(msg);
} else if (testo === Menu.SETPICPROFILE) {
await this.setPhotoProfile(rec, msg);
await this.setPhotoProfile(rec.user, msg.from.id);
} else if (testo === Menu.RESETPWD) {
await this.setResetPwd(rec, msg);
} else if (this.isSelMenu(msg, testo, 'INDIETRO') ||
(testo === Menu.it.INDIETRO)) {
await this.msgScegliMenu(msg);
@@ -2385,6 +2397,13 @@ class Telegram {
return this.arrUsers.find((rec) => rec.username_bo === username);
}
setRecByUsername(username, myrec) {
const ind = this.arrUsers.findIndex((rec) => rec.username_bo === username);
if (ind >= 0) {
this.arrUsers[ind] = myrec;
}
}
deleteRecInMem(msg) {
this.arrUsers = this.arrUsers.filter(
(rec) => rec.id !== this.getchatid(msg));
@@ -2496,35 +2515,24 @@ class Telegram {
rec.status = Status.VERIFIED;
rec.datemenu_updated = null;
rec.menuDb = null;
await User.SetTelegramIdSuccess(this.idapp, user._id, msg.from.id).then(async (recuser) => {
const recuser = await User.SetTelegramIdSuccess(this.idapp, user._id, msg.from.id);
if (recuser) {
console.log(recuser.username, ' SI E\' VERIFICATO CON TELEGRAM !');
let username = recuser.name;
const rismsg = await MsgTemplate.getMsgByLang(this.idapp, shared_consts.TypeMsgTemplate.MSG_BENVENUTO, recuser.lang);
const rismsg2 = await MsgTemplate.getMsgByLang(this.idapp, shared_consts.TypeMsgTemplate.MS_SHARE_LINK, recuser.lang);
return {recuser, rismsg, rismsg2};
}).then(async ({recuser, rismsg, rismsg2}) => {
if (recuser) {
console.log(recuser.username, ' SI E\' VERIFICATO CON TELEGRAM !');
this.setPhotoProfile(rec, msg, false);
let username = recuser.name;
// this.sendMsgLog(msg.from.id, printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, tools.getHostByIdApp(this.idapp)));
await this.sendMsgLog(msg.from.id, rismsg.body);
await this.sendMsg(msg.from.id, rismsg2.body);
if (msg.from.username) {
MyTelegramBot.askConfirmationUser(this.idapp, shared_consts.CallFunz.REGISTRATION, recuser);
}
this.checkIfUsernameTelegramSet(msg, recuser);
// local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg);
// this.sendMsgLog(msg.from.id, printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, tools.getHostByIdApp(this.idapp)));
if (!!msg.from.username) {
await MyTelegramBot.askConfirmationUser(this.idapp, shared_consts.CallFunz.REGISTRATION, recuser);
} else {
this.sendMsgLog(msg.from.id, getstr(this.getlang(msg), 'MSG_ERR_UNKNOWN_VERIFY_CODE'));
console.log(' ... MA GLI MANCA L\'USERNAME TELEGRAM !! ');
}
});
this.checkIfUsernameTelegramSet(msg, recuser);
// local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg);
} else {
this.sendMsgLog(msg.from.id, getstr(this.getlang(msg), 'MSG_ERR_UNKNOWN_VERIFY_CODE'));
}
} else {
if (rec.retry < 2) {
rec.retry++;
@@ -3079,7 +3087,7 @@ class Telegram {
shared_consts.VISIB_ONLYIF_VERIFIED, isVerified))
) {
rec.active_mem = true;
if (rec.main) {
if (true) {
lang = rec.lang;
if (!arrlang[rec.lang])
arrlang[rec.lang] = {menu: []};
@@ -3152,8 +3160,9 @@ class Telegram {
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(recdb.value)) {
recdb.pagenow = parseInt(recdb.value);
recdb.pageChange = true;
recuser.pagenow = parseInt(recdb.value);
recuser.pageChange = true;
// this.setRecByUsername(recuser.username, recuser);
}
return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) {
@@ -3329,6 +3338,7 @@ class Telegram {
}
} catch (e) {
console.error('Error sendMsg', e);
return null;
}
}
@@ -3354,18 +3364,35 @@ class Telegram {
return mymenuout;
}
async setPhotoProfile(rec, msg, showmsg = true) {
async setResetPwd(rec, msg) {
try {
if (rec.user) {
const idapp = this.idapp;
const bot = this.bot;
const username = rec.user.username;
const lang = rec.user.lang;
const link = await User.createNewRequestPwdByUsernameAndGetLink(idapp, username);
if (link) {
local_sendMsgTelegram(idapp, username, getstr(lang, 'MSG_RESETPWD') + '\n' + link);
}
}
} catch (e) {
console.error('Err', e);
}
}
async setPhotoProfile(user, telegid, showmsg = true) {
try {
if (user) {
const idapp = this.idapp;
const bot = this.bot;
const username = user.username;
const lang = user.lang;
const token = this.token;
const editprofile = tools.getHostByIdApp(idapp, true) + '/editprofile';
let myfileprofile = tools.getdirByIdApp(idapp, true) +
server_constants.DIR_UPLOAD + '/profile/' + username + '/';
let user_profile = bot.getUserProfilePhotos(msg.from.id);
let user_profile = bot.getUserProfilePhotos(telegid);
user_profile.then(function(res) {
if (res.photos[0]) {
var file_id = res.photos[0][2].file_id;
@@ -3390,9 +3417,7 @@ class Telegram {
then((ris) => {
// console.log('4) sendMsg picprofile Copied !');
if (showmsg) {
local_sendMsgTelegram(idapp, username,
printf(getstr(lang, 'MSG_SET_PICPROFILE'),
editprofile));
local_sendMsgTelegram(idapp, username, printf(getstr(lang, 'MSG_SET_PICPROFILE'), editprofile));
}
});
// console.log('scaricato');