VERSIONE 0.3.3: RISO:

"RISO.APP
alla fine copiare la cartella upload di insiemesipuo.app in riso.app"
Corretto BOT Menu
Altre sistemazioni (idShippings)
This commit is contained in:
paoloar77
2022-03-02 20:18:29 +01:00
parent 310eefba14
commit 94a2a073e5
6 changed files with 126 additions and 72 deletions

View File

@@ -1,9 +1,9 @@
const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET, tools.ISP];
const appTelegram = [tools.FREEPLANET, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM, tools.ISP];
const appTelegram_DEVELOP = [tools.ISP];
const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM, tools.RISO];
const appTelegram_DEVELOP = [tools.RISO];
const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];
@@ -245,6 +245,7 @@ const Menu = {
EXIT_TELEGRAM: 'exittotelegram',
MSG_TO_USER: 'sendmsgto',
ADMIN: emoji.get('information_desk_person') + ' Admin',
AIUTO: '🔮 Help',
ALTRO: emoji.get('newspaper') + ' Altro',
SETPICPROFILE: '🖼 SetPicProfile',
// MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi',
@@ -487,6 +488,7 @@ const txt = {
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_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 +
@@ -1431,10 +1433,6 @@ class Telegram {
this.bot = bot;
this.token = bot.token;
this.arrUsers = [];
this.pagenow = 1;
this.pageChange = false;
this.menuDb = null;
this.menuSaved = {};
this.lastid = 0;
//++
}
@@ -1598,7 +1596,7 @@ class Telegram {
await User.setUsernameTelegram(this.idapp, rec.user._id,
msg.from.username || '', msg.from.first_name || '',
msg.from.last_name || '');
this.sendMsg(msg.from.id,
await this.sendMsg(msg.from.id,
printf(getstr(rec.user.lang, 'MSG_SET_USERNAME_OK')));
} else {
if (!rec.user.profile.username_telegram) {
@@ -1610,7 +1608,7 @@ class Telegram {
if (risp === '') {
if (menusite) {
risp = this.getValueMenu(this.idapp, rec, msg, testo, lang);
risp = await this.getValueMenu(this.idapp, rec, msg, testo, lang);
noanswer = true;
} else if (MsgBot.CIAO.includes(testo.replace('!', ''))) {
risp = 'Ciao ';
@@ -1784,10 +1782,10 @@ class Telegram {
// }
}
if (risp !== '') {
if (risp !== '' && risp !== shared_consts.RIS_OK) {
rec.numdomande++;
if (!noanswer) {
await tools.snooze(600);
await tools.snooze(500);
risp = '[BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp;
}
this._inviaMsg(id, risp, keyboard);
@@ -1887,6 +1885,8 @@ class Telegram {
await this.menuExitToTelegram(msg);
} else if (testo === Menu.ADMIN) {
await this.menuAdmin(msg);
} else if (testo === Menu.AIUTO) {
await this.menuAiuto(msg);
} else if (testo === Menu.LANG) {
await this.menuLang(msg);
} else if (testo === Menu.MSGATUTTI) {
@@ -2246,6 +2246,10 @@ class Telegram {
await this.sendMsg(msg.chat.id, mystr);
}
async menuAiuto(msg) {
const mystr = this.getstrChatHelp();
await this.sendMsg(msg.chat.id, mystr);
}
async menuAdmin(msg) {
const mystr = tools.get__('SCEGLI_VOCE', this.getlang(msg));
await
@@ -2557,14 +2561,15 @@ class Telegram {
// let ris = await this.getUser(msg, rec, false);
rec.status = Status.VERIFIED;
rec.datemenu_updated = null;
rec.menuDb = null;
await User.SetTelegramIdSuccess(this.idapp, user._id,
msg.from.id).then((recuser) => {
if (recuser) {
this.setPhotoProfile(rec, msg);
let username = recuser.name;
this.sendMsg(msg.from.id,
printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username,
tools.getHostByIdApp(this.idapp)));
printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, tools.getHostByIdApp(this.idapp)));
this.checkIfUsernameTelegramSet(msg, recuser);
// local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg);
@@ -2748,6 +2753,8 @@ class Telegram {
}
if (inviaveramente) {
textdainviare = this.convertSpecialTags(utente, textdainviare);
if (destin === Destin.A_UTENTE) {
await this.sistemaRecDest(rec, msg);
await this.sendMsg(utente.profile.teleg_id,
@@ -3020,6 +3027,7 @@ class Telegram {
updateMenuBot() {
for (let rec of this.arrUsers) {
rec.menuDb = null;
rec.datemenu_updated = null;
}
}
@@ -3054,6 +3062,10 @@ class Telegram {
msg_wait: false,
lastmenu: null,
datemenu_updated: null,
pageChange: false,
menuSaved: {},
pagenow: 1,
menuDb: null,
};
this.arrUsers.push(rec);
@@ -3068,6 +3080,10 @@ class Telegram {
}
menuisVisible(idapp, menu) {
}
async loadMenuFromDb(idapp, id) {
try {
let load = false;
@@ -3079,10 +3095,12 @@ class Telegram {
load = true;
}
if (check) {
if (!(this.menuSaved[idapp]))
load = true;
if (recuser) {
if (!(recuser.menuSaved[idapp]))
load = true;
}
}
if (load || !this.menuDb || this.pageChange) {
if (load || !recuser.menuDb || recuser.pageChange) {
// Check if you are Admin
const user = await User.UserByIdTelegram(idapp, id);
@@ -3092,7 +3110,7 @@ class Telegram {
const isVerified = user ? user.profile.teleg_id > 0 &&
user.verified_by_aportador : false;
this.menuDb = await MyBot.findAllIdApp(idapp);
recuser.menuDb = await MyBot.findAllIdApp(idapp);
let arrlang = {};
@@ -3100,16 +3118,12 @@ class Telegram {
let arrtemp = [];
let lang = '';
for (const rec of this.menuDb) {
for (const rec of recuser.menuDb) {
rec.active_mem = false;
if (rec.active && rec.page === this.pagenow
&& ((isAdmin && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_ADMIN))
|| (isManager && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_MANAGER))
|| (isVerified && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLYIF_VERIFIED))
|| (rec.visibility === 0))
if (rec.active && rec.page === recuser.pagenow
&& (tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_ADMIN, isAdmin) &&
tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_MANAGER, isManager) &&
tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLYIF_VERIFIED, isVerified))
) {
rec.active_mem = true;
if (rec.main) {
@@ -3137,10 +3151,10 @@ class Telegram {
if (recuser)
recuser.datemenu_updated = new Date();
this.pageChange = false;
this.menuSaved[idapp] = arrlang;
recuser.pageChange = false;
recuser.menuSaved[idapp] = arrlang;
}
return this.menuSaved[idapp];
return recuser.menuSaved[idapp];
} catch (e) {
console.log('Err loadMenuFromDb: ' + e);
}
@@ -3156,7 +3170,7 @@ class Telegram {
}
}
for (const rec of this.menuDb) {
for (const rec of recuser.menuDb) {
if (rec.active_mem) {
if (rec.idapp === idapp && rec.lang === lang &&
rec.label.toLowerCase() === testo) {
@@ -3170,30 +3184,33 @@ class Telegram {
return false;
}
getValueMenu(idapp, rec, msg, testo, lang) {
async getValueMenu(idapp, recuser, msg, testo, lang) {
try {
for (const recdb of this.menuDb) {
if (recdb.active_mem) {
if (recdb.idapp === idapp && recdb.lang === lang &&
recdb.label.toLowerCase() === testo) {
if (recdb.type === shared_consts.BOTTYPE_TEXT) {
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_LINK) {
//++TODO: Link diretto !?
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(recdb.value)) {
this.pagenow = parseInt(recdb.value);
this.pageChange = true;
}
return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) {
if (recdb.value) {
this.isMenu(rec, msg, recdb.value, true);
return '';
}
}
if (recuser) {
for (const recdb of recuser.menuDb) {
if (recdb.active_mem) {
if (recdb.idapp === idapp && recdb.lang === lang &&
recdb.label.toLowerCase() === testo) {
if (recdb.type === shared_consts.BOTTYPE_TEXT) {
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_LINK) {
//++TODO: Link diretto !?
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(recdb.value)) {
recdb.pagenow = parseInt(recdb.value);
recdb.pageChange = true;
}
return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) {
if (recdb.value) {
this.isMenu(rec, msg, recdb.value, true);
return shared_consts.RIS_OK;
}
}
}
}
}
}
@@ -3201,7 +3218,7 @@ class Telegram {
} catch (e) {
return '';
}
return '';
}
async getKeyboard(id, menu, lang) {
@@ -3380,7 +3397,9 @@ class Telegram {
const idapp = this.idapp;
const bot = this.bot;
const username = rec.user.username;
const lang = rec.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);
@@ -3391,16 +3410,21 @@ class Telegram {
file.then(function(result) {
const file_path = result.file_path;
const photo_url = 'https://api.telegram.org/file/bot' + token +
'/' + file_path;
let filename = tools.extractFileName(photo_url)
const photo_url = 'https://api.telegram.org/file/bot' + token + '/' + file_path;
console.log('photo_url', photo_url);
let filename = tools.extractFileName(photo_url);
myfileprofile += filename;
tools.downloadImage(photo_url, myfileprofile).
console.log('myfileprofile', myfileprofile);
return tools.downloadImage(photo_url, myfileprofile).
then((ris) => {
User.setPicProfile(idapp, username, filename);
console.log('setPicProfile ris', ris);
return User.setPicProfile(idapp, username, filename).then((ris) => {
console.log('sendMsg picprofile Copied !');
local_sendMsgTelegram(idapp, username, printf(getstr(lang, 'MSG_SET_PICPROFILE'), editprofile));
});
// console.log('scaricato');
});
// bot.sendMessage(chatId, photo_url);
});
}
});