Zoom Calendar

This commit is contained in:
Paolo Arena
2020-01-21 01:37:15 +01:00
parent 905c4a4a62
commit f5355c3a54
6 changed files with 245 additions and 56 deletions

View File

@@ -5,6 +5,7 @@ const appTelegram = ['7'];
const printf = require('util').format;
const { User } = require('../models/user');
const { CalZoom } = require('../models/calzoom');
const emoji = require('node-emoji');
@@ -13,6 +14,8 @@ const i18n = require("i18n");
const Benvenuto = emoji.get('heartbeat') + emoji.get('heartbeat') + emoji.get('heartbeat') + ' Benvenuto!';
const emo = {
STARS: emoji.get('stars'),
FIRE: emoji.get('fire'),
DREAM: emoji.get('beach_with_umbrella'),
EYES: emoji.get('eyes'),
DIZZY: emoji.get('dizzy'),
@@ -61,6 +64,7 @@ function getemojibynumber(number) {
const Menu = {
LAVAGNA: emoji.get('om_symbol') + ' La tua Lavagna',
LINK_CONDIVIDERE: emoji.get('link') + ' Link da condividere',
ZOOM: emoji.get('information_source') + ' Zoom (Conferenze)',
INFO: emoji.get('information_source') + ' Informazioni',
ASSISTENZA: emoji.get('open_hands') + ' Assistenza',
@@ -75,8 +79,8 @@ const Menu = {
};
const MenuStandard = [[Menu.LAVAGNA, Menu.LINK_CONDIVIDERE], [Menu.INFO, Menu.ASSISTENZA]];
const MenuPerAdmin = [[Menu.LAVAGNA, Menu.LINK_CONDIVIDERE], [Menu.INFO, Menu.ASSISTENZA], [Menu.ADMIN, Menu.ALTRO]];
const MenuStandard = [[Menu.LAVAGNA, Menu.LINK_CONDIVIDERE], [Menu.ZOOM, Menu.ASSISTENZA]];
const MenuPerAdmin = [[Menu.LAVAGNA, Menu.LINK_CONDIVIDERE], [Menu.ZOOM, Menu.ASSISTENZA], [Menu.ADMIN, Menu.ALTRO]];
const MenuYesNo = [[Menu.SI, Menu.NO]];
const MenuAdmin = [[Menu.MSGATUTTI, Menu.INDIETRO], ['', '']];
@@ -108,7 +112,7 @@ const txt = {
MSG_VERIFY_OK: emoji.get('grinning') + ' Benvenuto %s. Ora sei correttamente verificato!',
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: emoji.get('heart_eyes') + ' Si è appena Registrato %s\n(Invitato da %s)',
MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' Si è appena Registrato %s\n(Invitato da %s)',
MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !',
};
@@ -246,6 +250,8 @@ class Telegram {
await this.menuAssistenza(msg)
} else if (msg.text === Menu.INFO) {
await this.menuInformazioni(msg)
} else if (msg.text === Menu.ZOOM) {
await this.menuZoom(msg)
} else {
await this.msgScegliMenu(msg);
}
@@ -366,9 +372,56 @@ class Telegram {
await this.sendMsg(msg.chat.id, mystr);
}
async menuZoom(msg) {
let mystr = '';
const listazoom = await CalZoom.findAllIdApp(this.idapp);
const nextzoom = await CalZoom.getNextZoom(this.idapp);
mystr += emo.STARS + 'Zoom in programma:' + emo.STARS + '\n\n';
let index = 1;
listazoom.forEach((evento) => {
let iniziata = false;
if (nextzoom)
iniziata = (nextzoom._id.toString() === evento._id.toString());
if (iniziata) {
mystr += emo.CHECK_VERDE + ' QUESTA CONFERENZA E\' INIZIATA! ' + emo.CHECK_VERDE + '\n';
}
mystr += `${emo.EYES} ${tools.getstrDateTimeShort(evento.date_start)} ${emo.EYES}`;
mystr += `\n${evento.title}\n(${evento.note})\n\n`;
if (nextzoom) {
if (iniziata) {
mystr += emo.FIRE + 'CLICCA QUI PER ENTRARE ! ' + emo.FIRE + '\n';
mystr += tools.getlinkzoom(evento.id_conf_zoom) + '\n\n';
}
}
index++;
}
)
;
await
this
.sendMsg(msg
.chat
.id
,
mystr
)
;
}
async menuAdmin(msg) {
const mystr = 'scegli una voce:';
await this.sendMsg(msg.chat.id, mystr, MenuAdmin);
await
this.sendMsg(msg.chat.id, mystr, MenuAdmin);
}
async menumsgAll(msg) {
@@ -376,7 +429,8 @@ class Telegram {
if (rec.user) {
const mystr = 'Scrivi qui un Messaggio da inviare a TUTTI:';
rec.msgall_status = StatusMSGALL.ASK;
await this.sendMsg(msg.chat.id, mystr, MenuAdmin);
await
this.sendMsg(msg.chat.id, mystr, MenuAdmin);
}
}
@@ -384,7 +438,8 @@ class Telegram {
const mytext = tools.get__('TESTO_ASSISTENZA', msg);
await this.sendMsg(msg.chat.id, mytext);
await
this.sendMsg(msg.chat.id, mytext);
}
existInMemory(msg) {
@@ -422,23 +477,29 @@ class Telegram {
rec.username_bo = text;
// Check if username exist
const user = await User.findByUsername(this.idapp, rec.username_bo);
const user = await
User.findByUsername(this.idapp, rec.username_bo);
if (!user) {
await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND)
await
this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND)
} else {
rec.user = user;
await User.SetTelegramCheckCode(this.idapp, rec.username_bo, rec.code);
await
User.SetTelegramCheckCode(this.idapp, rec.username_bo, rec.code);
rec.status = Status.WAITFOR_VERIFY_CODE;
await this.sendMsg(msg.from.id, txt.MSG_VERIFY_CODE)
await
this.sendMsg(msg.from.id, txt.MSG_VERIFY_CODE)
}
}
} else if (text.length === 0) {
if (rec)
rec.status = Status.NONE;
await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA);
await
this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA);
this.deleteRecInMem(msg)
} else {
await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME)
await
this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME)
}
} catch (e) {
console.error('Error setUsernameBo:', e)
@@ -448,34 +509,39 @@ class Telegram {
async setVerifyCode(msg) {
try {
const rec = this.getRecInMem(msg);
const user = await User.findByUsername(this.idapp, rec.username_bo);
const user = await
User.findByUsername(this.idapp, rec.username_bo);
const code = msg.text.toString().trim();
let telegcode = 0;
if (user) {
telegcode = user.profile.teleg_checkcode.toString();
} else {
await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND);
await
this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND);
return
}
if (msg.text.length < 7) {
if (rec) {
if (code === telegcode) {
rec.status = Status.VERIFIED;
await User.SetTelegramIdSuccess(this.idapp, rec.username_bo, msg.from.id).then((recuser) => {
if (recuser) {
let name = recuser.name;
this.sendMsg(msg.from.id, printf(txt.MSG_VERIFY_OK, name))
} else {
this.sendMsg(msg.from.id, txt.MSG_ERR_UNKNOWN_VERIFY_CODE);
}
});
await
User.SetTelegramIdSuccess(this.idapp, rec.username_bo, msg.from.id).then((recuser) => {
if (recuser) {
let name = recuser.name;
this.sendMsg(msg.from.id, printf(txt.MSG_VERIFY_OK, name))
} else {
this.sendMsg(msg.from.id, txt.MSG_ERR_UNKNOWN_VERIFY_CODE);
}
});
} else {
if (rec.retry < 2) {
rec.retry++;
await this.sendMsg(msg.from.id, txt.MSG_ERR_VERIFY_CODE)
await
this.sendMsg(msg.from.id, txt.MSG_ERR_VERIFY_CODE)
} else {
rec.status = Status.NONE;
await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA);
await
this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA);
this.deleteRecInMem(msg);
}
}
@@ -483,9 +549,11 @@ class Telegram {
} else if (msg.text.length === 0) {
if (rec)
rec.status = Status.NONE;
await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA)
await
this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA)
} else {
await this.sendMsg(msg.from.id, txt.MSG_ERRORE_VERIFY_CODE_MAXLEN)
await
this.sendMsg(msg.from.id, txt.MSG_ERRORE_VERIFY_CODE_MAXLEN)
}
} catch (e) {
console.error('Error setVerifyCode', e);
@@ -495,18 +563,21 @@ class Telegram {
async sendMsgToAll(rec, msg, texttosend) {
if (texttosend.length < 3) {
} else {
const usersall = await User.getUsersTelegALL(rec.user.idapp);
const usersall = await
User.getUsersTelegALL(rec.user.idapp);
let nummsgsent = 0;
if (usersall) {
for (const rec of usersall) {
await this.sendMsg(rec.profile.teleg_id, texttosend);
await
this.sendMsg(rec.profile.teleg_id, texttosend);
nummsgsent++;
}
}
await this.sendMsg(msg.chat.id, nummsgsent + ' ' + getstr(msg.from.language_code, txt.MSG_MSG_SENT));
await
this.sendMsg(msg.chat.id, nummsgsent + ' ' + getstr(msg.from.language_code, txt.MSG_MSG_SENT));
}
rec.start_write_msgall = false;
@@ -519,29 +590,35 @@ class Telegram {
async receiveMsg(msg) {
let status = this.getstatusInMemory(msg);
if (status === Status.NONE) {
await this.start(msg);
await
this.start(msg);
let status = this.getstatusInMemory(msg);
if (status !== Status.VERIFIED)
return
} else {
await this.setUser(msg)
await
this.setUser(msg)
}
const rec = this.getRecInMem(msg);
status = this.getstatus(rec);
if (status === Status.WAITFOR_USERNAME_BO && !this.selectMenuHelp(msg)) {
await this.setUsernameBo(msg)
await
this.setUsernameBo(msg)
} else if (status === Status.WAITFOR_VERIFY_CODE) {
await this.setVerifyCode(msg)
await
this.setVerifyCode(msg)
} else if (status === Status.NONE) {
await this.start(msg);
await
this.start(msg);
} else if (status === Status.VERIFIED) {
let normale = true;
if (rec.msgall_status === StatusMSGALL.CONFIRM) {
if (msg.text === Menu.SI) {
// Take msg to send to ALL
await this.sendMsgToAll(rec, msg, rec.msgtosent)
await
this.sendMsgToAll(rec, msg, rec.msgtosent)
} else {
this.sendMsg(msg.chat.id, txt.MSG_OPERAZ_ANNULLATA);
}
@@ -555,17 +632,20 @@ class Telegram {
this.ChiediSINO(msg, domanda);
} else {
rec.msgall_status = StatusMSGALL.NONE;
await this.msgScegliMenu(msg);
await
this.msgScegliMenu(msg);
}
normale = false
}
if (normale) {
// Check Menu
await this.isMenu(rec, msg);
await
this.isMenu(rec, msg);
}
} else {
await this.isMenuNotVerified(rec, msg);
await
this.isMenuNotVerified(rec, msg);
}
}
@@ -573,9 +653,11 @@ class Telegram {
const rec = this.arrUsers.find((rec) => rec.id === msg.from.id);
if (!rec) {
await this.addUser(msg);
await
this.addUser(msg);
await this.sendMsg(msg.chat.id, getstr(msg.from.language_code, txt.MSG_ASK_USERNAME_BO));
await
this.sendMsg(msg.chat.id, getstr(msg.from.language_code, txt.MSG_ASK_USERNAME_BO));
return false;
}
@@ -585,7 +667,8 @@ class Telegram {
async setUser(msg) {
const id = msg.from.id;
const user = await User.UserByIdTelegram(this.idapp, id);
const user = await
User.UserByIdTelegram(this.idapp, id);
let rec = this.arrUsers.find((rec) => rec.id === msg.from.id);
if (user && rec) {
rec.user = user;
@@ -597,7 +680,8 @@ class Telegram {
const id = msg.from.id;
let rec = null;
try {
const user = await User.UserByIdTelegram(this.idapp, id);
const user = await
User.UserByIdTelegram(this.idapp, id);
let rec = this.arrUsers.find((rec) => rec.id === msg.from.id);
if (user && !rec) {
rec = this.addUser(msg);
@@ -645,7 +729,8 @@ class Telegram {
async getKeyboard(id, menu) {
let keyb = MenuStandard;
// Check if you are Admin
const ismanager = await User.isManagerByIdTeleg(this.idapp, id);
const ismanager = await
User.isManagerByIdTeleg(this.idapp, id);
if (ismanager)
keyb = MenuPerAdmin;
if (menu) {
@@ -664,7 +749,8 @@ class Telegram {
"resize_keyboard": true,
"keyboard": await this.getKeyboard(id, menu)
}
});
})
;
}
async msgBenvenuto(id) {
@@ -674,7 +760,8 @@ class Telegram {
"resize_keyboard": true,
"keyboard": await this.getKeyboard(id)
}
});
})
;
}
async ChiediSINO(msg, domanda) {
@@ -695,7 +782,8 @@ class Telegram {
"resize_keyboard": true,
"keyboard": await this.getKeyboard(msg.from.id)
}
});
})
;
}
}