2020-01-03 01:52:49 +01:00
const tools = require ( '../tools/general' ) ;
2020-02-19 16:09:16 +01:00
const appTelegram = [ tools . AYNI ] ;
2020-01-03 01:52:49 +01:00
2020-02-07 22:08:46 +01:00
const appTelegramFinti = [ '2' ] ;
2020-02-19 16:09:16 +01:00
const appTelegramDest = [ tools . AYNI ] ;
2020-02-07 22:08:46 +01:00
2020-01-03 01:52:49 +01:00
const printf = require ( 'util' ) . format ;
const { User } = require ( '../models/user' ) ;
2020-01-21 01:37:15 +01:00
const { CalZoom } = require ( '../models/calzoom' ) ;
2020-03-10 21:44:14 +01:00
const { Nave } = require ( '../models/nave' ) ;
2020-02-07 22:08:46 +01:00
const shared _consts = require ( '../tools/shared_nodejs' ) ;
2020-01-03 01:52:49 +01:00
2020-01-03 22:02:18 +01:00
const emoji = require ( 'node-emoji' ) ;
2020-01-20 01:48:25 +01:00
const i18n = require ( "i18n" ) ;
2020-01-03 22:02:18 +01:00
const Benvenuto = emoji . get ( 'heartbeat' ) + emoji . get ( 'heartbeat' ) + emoji . get ( 'heartbeat' ) + ' Benvenuto!' ;
2020-01-03 01:52:49 +01:00
2020-01-20 01:48:25 +01:00
const emo = {
2020-02-19 16:09:16 +01:00
JOY : emoji . get ( 'joy' ) ,
JOY2 : emoji . get ( 'rolling_on_the_floor_laughing' ) ,
DANCER : emoji . get ( 'dancer' ) ,
2020-01-21 01:37:15 +01:00
STARS : emoji . get ( 'stars' ) ,
FIRE : emoji . get ( 'fire' ) ,
2020-02-19 16:09:16 +01:00
SUN : emoji . get ( 'sunrise' ) ,
2020-02-07 22:08:46 +01:00
TV : emoji . get ( 'tv' ) ,
NEWSPAPER : emoji . get ( 'newspaper' ) ,
2020-02-19 16:09:16 +01:00
KISS : emoji . get ( 'kiss' ) ,
2020-02-07 22:08:46 +01:00
PENCIL : emoji . get ( 'pencil2' ) ,
2020-01-20 01:48:25 +01:00
DREAM : emoji . get ( 'beach_with_umbrella' ) ,
EYES : emoji . get ( 'eyes' ) ,
DIZZY : emoji . get ( 'dizzy' ) ,
ONE _HUNDRED : emoji . get ( '100' ) ,
SMILE _STAR : emoji . get ( 'star-struck' ) ,
2020-02-19 16:09:16 +01:00
LEFT _FACING _FIST : emoji . get ( 'left-facing_fist' ) ,
2020-01-20 01:48:25 +01:00
CHECK _VERDE : emoji . get ( 'white_check_mark' ) ,
CHECK _GRIGIA : emoji . get ( 'ballot_box_with_check' ) ,
CROSS _ROSSA : emoji . get ( 'x' ) ,
ENVELOPE : emoji . get ( 'envelope' ) ,
EXCLAMATION _MARK : emoji . get ( 'exclamation' ) ,
QUESTION _MARK : emoji . get ( 'question' ) ,
ARROW _RIGHT : emoji . get ( 'arrow_right' ) ,
INVITATI : emoji . get ( 'man_and_woman_holding_hands' ) ,
HEART : emoji . get ( 'heart' ) ,
BLUE _HEART : emoji . get ( 'blue_heart' ) ,
GREEN _HEART : emoji . get ( 'green_heart' ) ,
YELLOW _HEART : emoji . get ( 'yellow_heart' ) ,
PURPLE _HEART : emoji . get ( 'purple_heart' ) ,
GIFT _HEART : emoji . get ( 'gift_heart' ) ,
2020-03-10 21:44:14 +01:00
GIFT : emoji . get ( 'gift' ) ,
2020-02-05 00:39:25 +01:00
ROBOT _FACE : emoji . get ( 'robot_face' ) ,
ADMIN : emoji . get ( 'information_desk_person' ) ,
2020-02-19 16:09:16 +01:00
MALE : emoji . get ( 'man-tipping-hand' ) ,
FEMALE : emoji . get ( 'female-guard' ) ,
INNOCENT : emoji . get ( 'innocent' ) ,
CREDIT _CARD : emoji . get ( 'credit_card' ) ,
PERSON : emoji . get ( 'man-tipping-hand' ) ,
} ;
MsgBot = {
2020-03-10 21:44:14 +01:00
MIANAVE : [ 'Nave' ] ,
CIAO : [ 'ciao' , 'ciaoo' , 'hola' , 'holaa' , 'hey' , 'salve' , 'buongiorno' , 'buondi' , 'ciao ❤️' ] ,
2020-02-19 16:09:16 +01:00
CI _SEI : [ 'ci sei' , 'c\'è qualcuno' , 'c\'è nessuno' ] ,
CHI _SONO _IO : [ 'chi sono io' , 'chi sono' ] ,
COME _STAI : [ 'tutto bene' , 'come stai' , 'come stai' , 'come va' , 'come butta' , 'come va oggi' ] ,
COME _TI _CHIAMI : [ 'chi sei' , 'come ti chiami' , 'qual\'è il tuo nome' , 'qual\'e\' il tuo nome' , 'che lavoro fai' , 'di cosa ti occupi' ] ,
COSA _FAI : [ 'cosa fai' , 'cosa combini' , 'che fai' ] ,
QUANTI _ANNI _HAI : [ 'quanti anni hai' , 'che età hai' ] ,
SEI _LIBERO _STASERA : [ 'sei libera stasera' , 'sei libero stasera' , 'usciamo insieme' , 'fare l\'amore con me' , 'fare sesso' , 'vuoi scopare' , 'vuoi trombare' ] ,
MI _TROVI _UN _MOROSO : [ 'trovi un moroso' , 'una morosa' , 'fidanzato' , 'fidanzata' , 'trovi un marito' , 'trovi una moglie' ] ,
CHAT _EMPOWER : [ 'chat empower' ] ,
MASCHIO _FEMMINA : [ 'sei uomo o donna' , 'sei maschio o femmina' , 'sei ragazzo o ragazza' , 'che sesso hai' ] ,
DAMMI _UN _BACIO : [ 'dammi un bacio' , 'baciami' ] ,
HAHA : [ 'hahaha' , 'ahah' , '😂' ] ,
MI _AMI : [ 'mi ami' ] ,
TI _AMO : [ 'ti amo' , 'ti adoro' , 'ti lovvo' ] ,
GRAZIE : [ 'grazie ainy' , 'grazie' , 'grazie mille' , 'graziee' , 'grazie 😘' , 'grazie😘' ] ,
PRINCIPE _AZZURRO : [ 'principe azzurro' ] ,
SPOSAMI : [ 'sposami' , 'vuoi sposar' , 'sei sposat' , 'ci sposiamo' , 'ti sposo' , 'sei sposat' , 'mi sposi' ] ,
CHE _TEMPO _FA : [ 'che tempo' ] ,
NON _TROO _INVITATI : [ 'non trovo invitati' , 'non riesco a trovare invitati' ] ,
PAROLACCE : [ 'stronz' , 'fanculo' ] ,
COME _SI _CHIAMA : [ 'come si chiama' ] ,
2020-03-10 21:44:14 +01:00
PROSSIMO _ZOOM : [ 'prossimo zoom' , 'fare lo zoom' , 'gli zoom' , 'conferenz' , 'zoom' ] ,
2020-02-19 16:09:16 +01:00
LAVAGNA : [ 'lavagna' , 'Lavagna' , 'LAVAGNA' ] ,
SEI _LIBERO : [ 'sei liber' , 'sei sposat' , 'sei fidanzat' , 'sei single' ] ,
AIUTO : [ 'ayni help' , 'help' , 'aiuto' , 'ho bisogno di' , 'ho problemi' , 'non riesco' , 'mi puoi aiutare' , 'mi aiuti' , 'aiutami' , 'posso chiederti' , 'puoi aiutarmi' ] ,
UOMO : [ 'uomo' , 'maschio' ] ,
SORPRESA : [ 'noo' , 'davvero' , 'sii' , 'facciamo festa' , 'è qui la festa' , 'festa' ] ,
UGUALE : [ '👍🏻' , '✨' , '❤🏻' , '⭐' , '❤' , '❤❤' , '🤩' ] ,
SI : [ 'si' , 'yes' ] ,
NO : [ 'no' , 'noo' ] ,
DONNA : [ 'donna' , 'femmina' ] ,
FARE _DOMANDA : [ 'fare una domanda' , 'posso farti una domanda' ] ,
DIVENTERO _RICCA : [ 'diventerò ricc' ] ,
MA _ALLORA : [ 'ma allora' ] ,
CHI _E _VISTAR : [ 'chi è vistar' ] ,
CHI _E _PAOLO : [ 'chi è paolo' ] ,
} ;
MsgRisp = {
CHAT _EMPOWER : 'Entra nella Chat EMPOWER !!!\n' + 'https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g ' + emo . PURPLE _HEART + emo . GIFT _HEART + emo . BLUE _HEART
2020-01-20 01:48:25 +01:00
} ;
function getemojibynumber ( number ) {
if ( number === 0 ) {
return emoji . get ( 'zero' )
} else if ( number === 1 ) {
return emoji . get ( 'one' )
} else if ( number === 2 ) {
return emoji . get ( 'two' )
} else if ( number === 3 ) {
return emoji . get ( 'three' )
} else if ( number === 4 ) {
return emoji . get ( 'four' )
} else if ( number === 5 ) {
return emoji . get ( 'five' )
} else if ( number === 6 ) {
return emoji . get ( 'six' )
} else if ( number === 7 ) {
return emoji . get ( 'seven' )
} else if ( number === 8 ) {
return emoji . get ( 'height' )
} else if ( number === 9 ) {
return emoji . get ( 'nine' )
2020-03-10 21:44:14 +01:00
} else {
return number ;
2020-01-20 01:48:25 +01:00
}
}
2020-03-10 21:44:14 +01:00
strNave = "Nave" ;
2020-02-19 16:09:16 +01:00
2020-01-03 01:52:49 +01:00
const Menu = {
2020-02-19 16:09:16 +01:00
ACCEDI : emo . PERSON + ' Accedi' ,
LAVAGNA : emoji . get ( 'om_symbol' ) + ' Lavagna (Requisiti)' ,
2020-01-03 22:02:18 +01:00
LINK _CONDIVIDERE : emoji . get ( 'link' ) + ' Link da condividere' ,
2020-01-21 01:37:15 +01:00
ZOOM : emoji . get ( 'information_source' ) + ' Zoom (Conferenze)' ,
2020-01-03 22:02:18 +01:00
INFO : emoji . get ( 'information_source' ) + ' Informazioni' ,
2020-02-19 16:09:16 +01:00
ASSISTENZA : emoji . get ( 'open_hands' ) + ' Le Chat di AYNI' ,
2020-01-03 22:02:18 +01:00
2020-01-20 01:48:25 +01:00
ADMIN : emoji . get ( 'information_desk_person' ) + ' Admin' ,
ALTRO : emoji . get ( 'newspaper' ) + ' Altro' ,
MSGATUTTI : emoji . get ( 'incoming_envelope' ) + ' Invia a TUTTI' ,
2020-03-10 21:44:14 +01:00
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' ,
MSG _TO _USER : 'sendmsgto' ,
MSG _SI _INVITATI _NO _7REQ _INVITATI : emoji . get ( 'incoming_envelope' ) + 'Inv e NO 7 Req' ,
2020-02-07 22:08:46 +01:00
MSGSTAFF : emoji . get ( 'incoming_envelope' ) + ' Invia a STAFF' ,
2020-01-20 01:48:25 +01:00
INDIETRO : emoji . get ( 'back' ) + ' Indietro' ,
SI : emoji . get ( 'thumbsup' ) + ' SI' ,
NO : emoji . get ( 'thumbsdown' ) + ' NO' ,
2020-03-10 21:44:14 +01:00
CHAT _PERSONALE : emoji . get ( 'female-office-worker' ) + emoji . get ( 'computer' ) ,
ESCI _DA _CHAT : emoji . get ( 'incoming_envelope' ) + ' Esci dalla Conversazione' ,
2020-01-03 22:02:18 +01:00
EXIT _TELEGRAM : 'exittotelegram' ,
2020-03-10 21:44:14 +01:00
MIANAVE : emo . GIFT + ' ' + strNave ,
2020-01-03 01:52:49 +01:00
} ;
2020-03-10 21:44:14 +01:00
const CONTA _SOLO = 'contasolo' ;
const RICEVI _EMAIL = 'riceviemail' ;
const SendMsgCmd = [ CONTA _SOLO , RICEVI _EMAIL ] ;
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
const MenuNoLogin = [ [ Menu . ACCEDI ] , [ Menu . ASSISTENZA ] ] ;
2020-01-21 01:37:15 +01:00
const MenuStandard = [ [ Menu . LAVAGNA , Menu . LINK _CONDIVIDERE ] , [ Menu . ZOOM , Menu . ASSISTENZA ] ] ;
2020-03-10 21:44:14 +01:00
const MenuPerAdmin = [ [ Menu . LAVAGNA , Menu . LINK _CONDIVIDERE ] , [ Menu . ZOOM , Menu . ASSISTENZA ] , [ Menu . MIANAVE , Menu . ADMIN , Menu . ALTRO ] ] ;
2020-01-20 01:48:25 +01:00
const MenuYesNo = [ [ Menu . SI , Menu . NO ] ] ;
2020-03-10 21:44:14 +01:00
const MenuAdmin = [ [ Menu . MSGSTAFF , Menu . MSGATUTTI , Menu . INDIETRO ] , [ Menu . MSG _NO _7 _REQ , Menu . MSG _NO _9 _REQ ] , [ Menu . MSG _TO _NAVE , Menu . MSG _SI _INVITATI _NO _7REQ _INVITATI ] ] ;
const MenuSend = [ [ CONTA _SOLO , RICEVI _EMAIL ] , [ Menu . INDIETRO ] ] ;
2020-02-07 22:08:46 +01:00
const MenuYes = [ [ Menu . MSGSTAFF , Menu . INDIETRO ] , [ '' , '' ] ] ;
2020-03-10 21:44:14 +01:00
const MenuChat = [ [ Menu . ESCI _DA _CHAT , Menu . INDIETRO ] ] ;
2020-01-03 01:52:49 +01:00
2020-02-19 16:09:16 +01:00
const Sex = {
MALE : 1 ,
FEMALE : - 1 ,
} ;
2020-01-03 01:52:49 +01:00
const Status = {
NONE : 0 ,
VERIFIED : 1 ,
WAITFOR _USERNAME _BO : 102 ,
WAITFOR _VERIFY _CODE : 103 ,
2020-02-19 16:09:16 +01:00
WAITFOR _RISPOSTA : 110 ,
2020-01-03 01:52:49 +01:00
} ;
2020-03-10 21:44:14 +01:00
const Destin = {
STAFF : 1 ,
TUTTI : 2 ,
NO _7 _REQ : 3 ,
NO _9 _REQ : 4 ,
SI _INVITATI _NO _7REQ _INVITATI : 5 ,
A _UTENTE : 6 ,
MSG _TO _NAVE : 7 ,
} ;
2020-01-20 01:48:25 +01:00
const StatusMSGALL = {
NONE : 0 ,
ASK : 1 ,
CONFIRM : 2 ,
} ;
2020-01-03 01:52:49 +01:00
const txt = {
2020-01-03 22:02:18 +01:00
MSG _SCEGLI _MENU : emoji . get ( 'dizzy' ) + ' Scegli una voce di menu:' + emoji . get ( 'dizzy' ) ,
2020-02-05 00:39:25 +01:00
MSG _ASK _USERNAME _BO : 'Scrivi nel messaggio lo username o la email con cui ti sei registrato sul sito di %s:' ,
2020-02-19 16:09:16 +01:00
MSG _ERRORE _USERNAME : 'Attenzione! Devi inserire solo lo username (40 caratteri massimo)' ,
2020-03-10 21:44:14 +01:00
MSG _ERRORE _USERNAME _NOT _FOUND : 'Per Completare la Verifica Telegram BOT, devi ora scrivere qui sotto nel messaggio l\'Username OPPURE la email con cui ti sei registrato sul sito di AYNI:' ,
2020-01-20 01:48:25 +01:00
MSG _ERRORE _USERNAME _ANNULLA : 'Inserimento Annullato. Riprovare' ,
MSG _OPERAZ _ANNULLATA : 'Operazione Annullata' ,
2020-01-03 01:52:49 +01:00
MSG _ERRORE _VERIFY _CODE _MAXLEN : 'Attenzione! Devi inserire solo il codice a 6 cifre' ,
2020-02-19 16:09:16 +01:00
MSG _VERIFY _CODE : '1. Ora ritorna sul sito di AYNI:\n%s\n2. Copia il codice di Autenticazione (di 6 cifre) che troverai scritto in alto\n3. Scrivilo (o incollalo) qui sotto come messaggio:' ,
MSG _ERR _VERIFY _CODE : 'Codice di Verifica Errato!' + emo . EXCLAMATION _MARK + '\nControlla sul sito %s e riscrivi il nuovo codice di 6 cifre.' ,
MSG _VERIFY _OK : emoji . get ( 'grinning' ) + ' Benvenuto %s! Ti sei correttamente verificato con AYNI BOT. ' + '\nSono il tuo assistente virtuale.\n' +
'Continua la guida passo passo tornando sul sito di AYNI.\n\nQuesta chat ti servirà per vedere velocemente la tua Lavagna e per ricevere Importanti avvisi su come procedere il tuo cammino.\n\nUsa il menu qui sotto per controllare la tua situazione.' + emo . GREEN _HEART ,
2020-02-05 00:39:25 +01:00
2020-01-03 22:02:18 +01:00
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.' ,
2020-01-27 15:07:53 +01:00
MSG _APORTADOR _USER _REGISTERED : emo . FIRE + ' Si è appena Registrato "%s (n. %s)"\n(Invitato da %s)' ,
2020-01-20 01:48:25 +01:00
MSG _MSG _SENT : emoji . get ( 'envelope' ) + ' Messaggi Inviati !' ,
2020-03-10 21:44:14 +01:00
MSG _MSG _TOSENT : emoji . get ( 'envelope' ) + ' Messaggi da Inviare' ,
2020-02-19 16:09:16 +01:00
MSG _MSG _INCORSO : emoji . get ( 'envelope' ) + ' messaggi in corso... Inviati attualmente' ,
2020-01-03 01:52:49 +01:00
} ;
const TelegramBot = require ( 'node-telegram-bot-api' ) ;
2020-01-03 22:02:18 +01:00
module . exports = {
ADMIN _IDTELEGRAM _SERVER : '12429864' ,
ADMIN _USER _SERVER : 'paoloar77' ,
ADMIN _USER _NAME _SERVER : 'Paolo' ,
phase : {
REGISTRATION : 1
} ,
2020-03-10 21:44:14 +01:00
getCiao : function ( idapp , username , lang ) {
return tools . gettranslate ( 'CIAO' , lang ) + ' ' + username + '!\n' ;
} ,
2020-01-03 22:02:18 +01:00
notifyToTelegram : async function ( phase , mylocalsconf ) {
let userdest = mylocalsconf . user . aportador _solidario ;
2020-01-20 01:48:25 +01:00
let NameFrom = ` ${ mylocalsconf . user . name } ${ mylocalsconf . user . surname } ` ;
2020-01-27 15:07:53 +01:00
const ind _order = mylocalsconf . user . ind _order ;
2020-01-20 01:48:25 +01:00
let aportador = '' ;
2020-01-20 02:18:11 +01:00
if ( userdest ) {
2020-01-20 01:48:25 +01:00
aportador = ` ( ${ userdest } ) ` ;
2020-01-20 02:18:11 +01:00
NameFrom += aportador ;
} else {
aportador = mylocalsconf . user . aportador _solidario _nome _completo ;
}
2020-01-20 01:48:25 +01:00
2020-01-03 22:02:18 +01:00
let text = '' ;
if ( phase === this . phase . REGISTRATION ) {
2020-01-20 01:48:25 +01:00
if ( userdest ) {
NameFrom = await User . getNameSurnameByUsername ( mylocalsconf . idapp , userdest ) + aportador ;
2020-01-20 02:18:11 +01:00
aportador = NameFrom ;
2020-01-20 01:48:25 +01:00
}
2020-01-27 15:07:53 +01:00
text = printf ( txt . MSG _APORTADOR _USER _REGISTERED , ` ${ mylocalsconf . user . name } ${ mylocalsconf . user . surname } ( ${ mylocalsconf . user . username } ) ` , ind _order , aportador ) ;
2020-01-03 22:02:18 +01:00
}
2020-01-20 02:18:11 +01:00
let addtext = "" ;
if ( ! ! mylocalsconf . user . aportador _solidario ) {
addtext = '[Inviato a ' + NameFrom + ']:' + '\n' ;
2020-01-20 01:48:25 +01:00
await this . sendMsgTelegram ( mylocalsconf . idapp , userdest , text ) ;
2020-01-20 02:18:11 +01:00
}
2020-01-03 22:02:18 +01:00
2020-01-20 02:18:11 +01:00
await this . sendMsgTelegramToTheManagers ( mylocalsconf . idapp , addtext + text ) ;
2020-01-03 22:02:18 +01:00
} ,
sendMsgTelegramToTheManagers : async function ( idapp , text ) {
const usersmanagers = await User . getusersManagers ( idapp ) ;
// console.log('usersmanagers', usersmanagers);
2020-03-10 21:44:14 +01:00
tools . writeManagersLog ( text ) ;
2020-01-03 22:02:18 +01:00
if ( usersmanagers ) {
2020-01-20 02:18:11 +01:00
for ( const rec of usersmanagers ) {
2020-03-10 21:44:14 +01:00
await this . sendMsgTelegramByIdTelegram ( idapp , rec . profile . teleg _id , emo . ROBOT _FACE + '[BOT-STAFF]' + emo . ADMIN + ': ' + text , undefined , undefined , true ) ;
2020-02-07 22:08:46 +01:00
await tools . snooze ( 300 )
2020-01-20 02:18:11 +01:00
}
2020-01-03 22:02:18 +01:00
}
2020-02-07 22:08:46 +01:00
return true
2020-01-03 22:02:18 +01:00
} ,
2020-03-10 21:44:14 +01:00
getMsgByTipoMsg : function ( mydata , lang , user ) {
if ( ! ! mydata . msgextra ) {
return mydata . msgextra ;
}
if ( mydata . tipomsg === tools . TipoMsg . SEND _LINK _CHAT _DONATORI ) {
return printf ( tools . gettranslate ( 'SEND_LINK_CHAT_DONATORI' , lang ) , user . name , mydata . msgpar1 ) ;
}
} ,
sendMsgTelegramToNave : async function ( idapp , mydata ) {
let nummsgsent = 0 ;
let strout = '' ;
try {
const arrnavi = await Nave . getusersByNave ( idapp , mydata . navemediatore ) ;
// console.log('usersmanagers', usersmanagers);
tools . writeManagersLog ( 'sendMsgTelegramToNave' ) ;
if ( arrnavi ) {
for ( const nave of arrnavi ) {
const user = await User . findByIndOrder ( idapp , nave . ind _order ) ;
if ( ! ! user ) {
const lang = user . lang ;
const idteleg = user . profile . teleg _id ;
const mymsg = this . getMsgByTipoMsg ( mydata , lang , user ) ;
if ( ! ! idteleg ) {
strout += '\n' + user . name + ' ' + user . surname + ':' ;
if ( mydata . inviareale ) {
await this . sendMsgTelegramByIdTelegram ( idapp , idteleg , mymsg , undefined , undefined , true ) ;
await tools . snooze ( 300 ) ;
strout += ' -> MSG INVIATO' ;
} else {
strout += ' (Pronto da Inviare)' ;
}
nummsgsent ++ ;
}
}
}
if ( nummsgsent > 0 ) {
if ( mydata . tipomsg === tools . TipoMsg . SEND _LINK _CHAT _DONATORI ) {
const fields _to _update = {
sent _msg _howto _make _gift : true
} ;
await Nave . findOneAndUpdate ( { _id : mydata . navemediatore . id } , { $set : fields _to _update } , { new : false } ) ;
}
}
}
return { nummsgsent , strout } ;
} catch ( e ) {
console . error ( e ) ;
return { nummsgsent , strout } ;
}
} ,
2020-02-19 16:09:16 +01:00
sendMsgTelegramToTheAdmin : async function ( idapp , text ) {
const usersmanagers = await User . getusersManagers ( idapp ) ;
if ( usersmanagers ) {
for ( const rec of usersmanagers ) {
if ( User . isAdmin ( rec . perm ) ) {
2020-03-10 21:44:14 +01:00
this . sendMsgTelegramByIdTelegram ( idapp , rec . profile . teleg _id , emo . ROBOT _FACE + '[BOT-ADMIN]' + emo . ADMIN + ': ' + text , undefined , undefined , true ) ;
2020-02-19 16:09:16 +01:00
await tools . snooze ( 300 )
}
}
}
return true
} ,
2020-01-20 01:48:25 +01:00
sendMsgTelegramToALL : async function ( idapp , text ) {
const usersall = await User . getUsersTelegALL ( idapp ) ;
if ( usersall ) {
2020-02-07 22:08:46 +01:00
for ( const rec of usersall ) {
this . sendMsgTelegramByIdTelegram ( idapp , rec . profile . teleg _id , text ) ;
await tools . snooze ( 300 )
}
2020-01-20 01:48:25 +01:00
}
} ,
2020-03-10 21:44:14 +01:00
sendMsgTelegram : async function ( idapp , username , text , alsotomanagers ) {
2020-01-03 22:02:18 +01:00
const teleg _id = await User . TelegIdByUsername ( idapp , username ) ;
const cl = getclTelegByidapp ( idapp ) ;
if ( cl && teleg _id ) {
2020-01-20 01:48:25 +01:00
await cl . sendMsg ( teleg _id , text )
2020-01-03 22:02:18 +01:00
}
2020-03-10 21:44:14 +01:00
if ( alsotomanagers ) {
await this . sendMsgTelegramToTheManagers ( idapp , text )
}
2020-01-03 22:02:18 +01:00
} ,
2020-03-10 21:44:14 +01:00
sendMsgTelegramByIdTelegram : async function ( idapp , idtelegram , text , message _id , chat _id , ripr _menuPrec ) {
2020-01-20 01:48:25 +01:00
if ( ! idtelegram )
return ;
2020-01-03 22:02:18 +01:00
const cl = getclTelegByidapp ( idapp ) ;
if ( cl && idtelegram ) {
2020-02-19 16:09:16 +01:00
let myform = null ;
2020-03-10 21:44:14 +01:00
return await cl . sendMsg ( idtelegram , text , null , null , message _id , chat _id , ripr _menuPrec )
2020-01-03 22:02:18 +01:00
}
}
} ;
2020-02-19 16:09:16 +01:00
async function sendMsgTelegramToTheAdmin ( idapp , text , msg ) {
const usersmanagers = await User . getusersManagers ( idapp ) ;
2020-03-10 21:44:14 +01:00
const clorig = getclTelegByidapp ( idapp ) ;
const rec = clorig . getRecInMem ( msg ) ;
let username = '' ;
if ( ! ! rec ) {
username = rec . username _bo ;
} else {
username = msg . chat . username ;
}
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
text = emo . ROBOT _FACE + '[BOT-ADMIN]' + emo . ADMIN + ': Da ' + msg . chat . first _name + ' ' + msg . chat . last _name + ' [' + username + ']: \n' + text ;
2020-02-19 16:09:16 +01:00
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
}
2020-03-10 21:44:14 +01:00
function getusernameByUser ( idapp , msg ) {
let username = '' ;
let rec = this . getRecInMem ( msg ) ;
if ( ! ! rec )
username = rec . username _bo ;
if ( username === '' ) {
username = msg . chat . username ;
}
return username ;
}
async function local _sendMsgTelegramToTheManagers ( idapp , text , msg , username _bo ) {
2020-02-19 16:09:16 +01:00
const usersmanagers = await User . getusersManagers ( idapp ) ;
2020-03-10 21:44:14 +01:00
let username = msg . chat . username ;
if ( username _bo )
username = username _bo ;
2020-02-19 16:09:16 +01:00
text = emo . ROBOT _FACE + '[BOT-STAFF]' + emo . ADMIN + ': Da ' + msg . chat . first _name + ' ' + msg . chat . last _name + ' (' + username + '): \n' + text ;
tools . writeEventsLog ( text ) ;
if ( usersmanagers ) {
for ( const rec of usersmanagers ) {
const idtelegram = rec . profile . teleg _id ;
const cl = getclTelegByidapp ( idapp ) ;
if ( cl && idtelegram ) {
2020-03-10 21:44:14 +01:00
await cl . sendMsg ( idtelegram , text , undefined , undefined , undefined , undefined , true )
2020-02-19 16:09:16 +01:00
}
await tools . snooze ( 300 )
}
}
return true
}
2020-01-03 01:52:49 +01:00
function getstr ( lang , text ) {
return text ;
}
class Telegram {
constructor ( idapp , bot ) {
this . idapp = idapp ;
this . bot = bot ;
this . token = bot . token ;
this . arrUsers = [ ] ;
}
2020-01-20 01:48:25 +01:00
async createIfNotExist ( msg ) {
if ( ! await this . alreadyExist ( msg ) ) {
2020-02-19 16:09:16 +01:00
if ( await this . insertIntoDB ( msg ) ) {
2020-01-20 01:48:25 +01:00
let rec = this . getRecInMem ( msg ) ;
if ( rec . user )
rec . status = Status . VERIFIED
}
return true
} else {
return false
}
}
2020-01-03 01:52:49 +01:00
2020-01-20 01:48:25 +01:00
async start ( msg ) {
2020-01-03 01:52:49 +01:00
// Check if Present to the DB
2020-01-20 01:48:25 +01:00
if ( ! await this . createIfNotExist ( msg ) ) {
2020-01-03 01:52:49 +01:00
let rec = this . getRecInMem ( msg ) ;
if ( ! rec )
rec = this . addUser ( msg ) ;
2020-01-20 01:48:25 +01:00
if ( rec . user )
rec . status = Status . VERIFIED
2020-01-03 01:52:49 +01:00
}
}
2020-02-19 16:09:16 +01:00
async IsTesto ( msg ) {
let risp = '' ;
const id = msg . chat . id ;
let testo = msg . text . toLowerCase ( ) . trim ( ) ;
testo = testo . replace ( '!' , '' ) ;
testo = testo . replace ( '?' , '' ) ;
testo = testo . replace ( 'é' , 'è' ) ;
let contastiera = false ;
let noanswer = false ;
const rec = this . getRecInMem ( msg ) ;
let myname = '' ;
if ( rec . user ) {
myname = rec . user . name + ' ' + rec . user . surname + ' (n.' + rec . user . ind _order + ')' ;
}
if ( rec . statusmsg === Status . WAITFOR _RISPOSTA ) {
if ( rec . msgcodeprec === MsgBot . COME _STAI ) {
risp = 'L\'importante è trovare Serenità dentro di noi' + emo . GIFT _HEART + '\nNutrirsi di Sole e Viaggiare il più possibile ! ' + emo . DREAM ;
} else if ( rec . msgcodeprec === MsgBot . QUANTI _ANNI _HAI ) {
const eta = testo . match ( /\d+/g ) ;
if ( ! eta ) {
risp = 'Mmmh, non me lo vuoi dire...' ;
} else {
if ( eta < 20 ) {
risp = 'Woww! Sei molto giovane!' ;
} else if ( ( eta > 20 ) && ( eta < 30 ) ) {
risp = 'Sei giovane anche tu!' ;
} else if ( ( eta > 30 ) && ( eta < 50 ) ) {
risp = 'Sono i migliori anni questi !' ;
} else if ( ( eta > 50 ) && ( eta < 60 ) ) {
risp = 'Complimenti !' ;
} else if ( eta > 60 ) {
risp = 'Però! Ti mantieni in forma!' + emo . SMILE _STAR ;
}
risp = 'Ah ' + eta + ' anni !\n' + risp ;
}
} else if ( rec . msgcodeprec === MsgBot . CHAT _EMPOWER ) {
if ( ! MsgBot . SI . includes ( testo ) ) {
risp = MsgRisp . CHAT _EMPOWER
} else {
risp = 'Bene ! Allora divertiti conoscendo persone nuove ! ' ;
}
} else if ( rec . msgcodeprec === MsgBot . MASCHIO _FEMMINA ) {
if ( MsgBot . UOMO . includes ( testo ) ) {
rec . sex = Sex . MALE ;
risp = 'Ok, sarò il tuo uomo ' + emo . MALE ;
} else {
rec . sex = Sex . FEMALE ;
risp = 'Ok, sarò la tua donna ' + emo . ADMIN ;
}
}
rec . statusmsg = 0 ;
}
rec . msgcodeprec = '' ;
if ( risp === '' ) {
if ( MsgBot . CIAO . includes ( testo . replace ( '!' , '' ) ) ) {
risp = 'Ciao ' ;
if ( rec )
if ( rec . user )
risp += rec . user . name ;
risp += '!' ;
} else if ( MsgBot . COME _STAI . includes ( testo . replace ( '?' , '' ) ) ) {
risp = 'Io Benone Grazie! ' + emoji . get ( 'heartbeat' ) + ' E tu?' ;
rec . statusmsg = Status . WAITFOR _RISPOSTA ;
rec . msgcodeprec = MsgBot . COME _STAI
} else if ( MsgBot . CHI _SONO _IO . includes ( testo . replace ( '?' , '' ) ) ) {
risp = 'Su Telegram ti chiami "' + msg . chat . first _name + ' ' + msg . chat . last _name + '"\n' ;
if ( ! ! rec . user ) {
risp += '\nSul sito ti sei registrato come:\n\n[N. ' + rec . user . ind _order + ']: ' + rec . user . name + ' ' + rec . user . surname + '\nUsername: ' + rec . user . username + '\n' + 'Email: ' + rec . user . email ;
} else {
risp = 'Ancora non ti sei Attivato su AYNI BOT' ;
}
} else if ( MsgBot . CI _SEI . includes ( testo . replace ( '?' , '' ) ) ) {
risp = 'Io Si, ci sono !' ;
} else if ( MsgBot . QUANTI _ANNI _HAI . includes ( testo . replace ( '?' , '' ) ) ) {
risp = 'Io sono abbastanza Giovane ! ' + emo . SMILE _STAR + '\nNon posso dirti che età ho. E tu?' ;
rec . statusmsg = Status . WAITFOR _RISPOSTA ;
rec . msgcodeprec = MsgBot . QUANTI _ANNI _HAI
} else if ( MsgBot . DAMMI _UN _BACIO . includes ( testo ) ) {
risp = emo . KISS ;
} else if ( MsgBot . COSA _FAI . includes ( testo ) ) {
risp = 'Ora sto chattando con te!\nSolitamente sono in attesa di ricevere messaggi ' + emo . ENVELOPE ;
} else if ( MsgBot . MASCHIO _FEMMINA . includes ( testo . replace ( '?' , '' ) ) ) {
risp = 'Cosa vorresti che fossi? Uomo o donna?' ;
rec . msgcodeprec = MsgBot . MASCHIO _FEMMINA ;
rec . statusmsg = Status . WAITFOR _RISPOSTA ;
} else if ( MsgBot . COME _TI _CHIAMI . includes ( testo . replace ( '?' , '' ) ) ) {
risp = 'Io mi chiamo AYNI BOT e sono il tuo assistente Virtuale. ' + emo . EYES + '\nPuoi usare il menu che compare qui sotto per sapere tutto sulle mie funzionalità ' + emo . GREEN _HEART ;
contastiera = true ;
} else if ( MsgBot . UGUALE . includes ( testo ) ) {
risp = testo ;
2020-03-10 21:44:14 +01:00
// } else if (MsgBot.CHI_E_VISTAR.includes(testo)) {
// risp = 'Vistar è un nomade che vive in Perù tra i selvaggi, filosofeggiando e cazzeggiando qua e la... Per questo è un Fico ed è adulato dalle ragazze di tutto il Globo ' + emo.JOY + emo.JOY + emo.JOY;
// } else if (MsgBot.CHI_E_PAOLO.includes(testo)) {
// risp = 'Paolo è il Programmatore Sborone di AYNI. Anche lui Fico quanto Vistar (ma chi è Vistar) ' + emo.JOY + ' che anzichè creare la Nave cazzeggia su AYNI BOT, trovando risposte alle domande più assurde.' + emo.JOY2 + emo.JOY2;
2020-02-19 16:09:16 +01:00
} else if ( MsgBot . COME _SI _CHIAMA . includes ( testo ) ) {
risp = 'Eh non te lo posso dire! ' + emo . JOY ;
} else if ( MsgBot . GRAZIE . includes ( testo . replace ( '!' , '' ) ) ) {
risp = 'Prego ! ' + emo . KISS + emo . KISS + emo . KISS ;
} else if ( MsgBot . MI _AMI . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = ' Tantissimo! ' + emo . KISS + emo . GIFT _HEART + emo . GIFT _HEART + emo . GIFT _HEART ;
} else if ( MsgBot . TI _AMO . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = ' Anche IO! ' + emo . KISS + emo . SMILE _STAR + emo . GIFT _HEART + emo . BLUE _HEART + emo . GREEN _HEART ;
} else if ( MsgBot . PRINCIPE _AZZURRO . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Chissà... Forse si!\nAnche se meglio averne un\'altro di scorta, nel caso il Principe non sia disponibile.' ;
} else if ( MsgBot . AIUTO . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Clicca qui per entrare nella Chat AYNI - HELP di Supporto\n' + 'https://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w' + '\n\nI miei colleghi umani ti aiuteranno a risolvere !' ;
} else if ( MsgBot . SPOSAMI . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'No Grazie! Sono per la Libertà a Vita! ' + emo . JOY + '\nMa se vuoi possiamo conoscerci meglio!' + emo . DANCER + emo . FIRE ;
} else if ( MsgBot . CHE _TEMPO _FA . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Il tempo oggi è Sereno da me! ' + emo . SUN ;
} else if ( MsgBot . NON _TROO _INVITATI . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = MsgRisp . CHAT _EMPOWER ;
} else if ( MsgBot . SEI _LIBERO . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Io? Sono per la Libertà! ' + emo . JOY + '\nMa se vuoi possiamo conoscerci meglio!' + emo . DANCER + emo . FIRE ;
} else if ( MsgBot . FARE _DOMANDA . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Dipende ' + emo . SMILE _STAR + '\nProvaci!' ;
} else if ( MsgBot . DIVENTERO _RICCA . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Mmmmh... Perchè non pensi di Vivere già nell\'Abbondanza ?\nCosa ti manca veramente?\nForse di realizzare che la ricchezza è un sentirlo, non un diventarlo.' + emo . GIFT _HEART ;
} else if ( MsgBot . MA _ALLORA . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Ma allora cosa?' ;
} else if ( MsgBot . SEI _LIBERO _STASERA . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Si vabbeh, non è che puoi prendere subito tutta questa confidenza' + emo . EXCLAMATION _MARK + emo . SMILE _STAR + '\nIntanto inizia ad invitare altre persone a conoscermi, poi ne riparliamo ' + emo . GIFT _HEART ;
} else if ( MsgBot . MI _TROVI _UN _MOROSO . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = emo . SMILE _STAR + emo . SMILE _STAR + emo . SMILE _STAR + emo . SMILE _STAR + '\nMagari! Così la smetteresti di scrivere a me (ad un BOT Virtuale) e tromberesti di più ' + emo . DANCER + emo . DANCER ;
risp += '\n\n' + MsgRisp . CHAT _EMPOWER ;
} else if ( MsgBot . SORPRESA . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) && testo . length < 15 ) {
risp = 'Siiiii ! Davvero! ' + emo . DREAM + '\nTi ricordo che nella CHAT EMPOWER si fa FESTA!\n\nChat AYNI - EMPOWER: Entra ⛩ nella nostra Community chat:\n https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g' ;
} else if ( MsgBot . PAROLACCE . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) ) {
risp = 'Da te non me l\'aspettavo proprio !! ' + emo . INNOCENT + emo . CROSS _ROSSA ;
} else if ( MsgBot . HAHA . find ( ( rec ) => testo . indexOf ( rec ) > - 1 ) && testo . length < 8 ) {
risp = emo . JOY + emo . JOY + emo . JOY ;
2020-03-10 21:44:14 +01:00
} else if ( testo . length > 1 ) {
2020-02-19 16:09:16 +01:00
noanswer = true ;
risp = 'Non ti capisco... d\'altronde sono solo un Robot ' + emo . ROBOT _FACE + emo . JOY2 + '\n\n(Per AIUTO, contatta la Chat AYNI - HELP)' ;
// risp += '\nClicca qui per entrare nella Chat AYNI - HELP di Supporto\n' + 'https://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w' + '\n\nI miei colleghi umani ti aiuteranno a risolvere !';
2020-03-10 21:44:14 +01:00
await local _sendMsgTelegramToTheManagers ( this . idapp , testo , msg , rec . username _bo ) ;
2020-02-19 16:09:16 +01:00
}
}
let keyboard = { } ;
if ( contastiera ) {
keyboard = {
"reply_markup" : {
"resize_keyboard" : true ,
"keyboard" : await this . getKeyboard ( id )
}
}
}
if ( rec . numdomande > 3 && rec . msgcodeprec === '' ) {
2020-03-10 21:44:14 +01:00
// if (rec.user) {
// const dashboard = await User.getDashboard(this.idapp, rec.user.aportador_solidario, rec.user.username, rec.user.aportador_solidario_name_surname);
//
// risp += '\n\nNel frattempo ti ricordo che ';
// if (dashboard.myself.numinvitati === 1)
// risp += 'hai solo ' + dashboard.myself.numinvitati + ' invitato!';
// else if (dashboard.myself.numinvitati === 0)
// risp += 'ancora non hai portato nessun Invitato! ' + emo.LEFT_FACING_FIST;
// else if (dashboard.myself.numinvitati > 2)
// risp += 'hai ' + dashboard.myself.numinvitati + ' invitati !' + emo.STARS;
//
// risp += '\n\nSei già entrato nella Chat di EMPOWER?';
// rec.msgcodeprec = MsgBot.CHAT_EMPOWER;
// rec.statusmsg = Status.WAITFOR_RISPOSTA;
// rec.numdomande = 0;
// }
2020-02-19 16:09:16 +01:00
}
if ( risp !== '' ) {
rec . numdomande ++ ;
await tools . snooze ( 600 ) ;
this . _inviaMsg ( id , '[AYNI BOT' + emo . ROBOT _FACE + ' scrive]:\n' + risp , keyboard ) ;
let strlog = 'USER [' + myname + ']: ' + testo + '\n' ;
if ( ! noanswer ) {
strlog += 'BOT: ' + risp + '\n' ;
}
tools . writelog ( strlog ) ;
}
return risp !== '' ;
}
2020-01-20 01:48:25 +01:00
async isMenuNotVerified ( rec , msg ) {
if ( msg . text === Menu . ASSISTENZA ) {
await this . menuAssistenza ( msg )
} else if ( msg . text === Menu . INFO ) {
await this . menuInformazioni ( msg )
2020-02-19 16:09:16 +01:00
} else if ( msg . text === Menu . ZOOM || MsgBot . PROSSIMO _ZOOM . find ( ( rec ) => msg . text . indexOf ( rec ) > - 1 ) ) {
2020-01-21 01:37:15 +01:00
await this . menuZoom ( msg )
2020-02-19 16:09:16 +01:00
} else if ( await this . IsTesto ( msg ) ) {
// OK
2020-01-20 01:48:25 +01:00
} else {
await this . msgScegliMenu ( msg ) ;
}
}
async isMenu ( rec , msg ) {
2020-02-19 16:09:16 +01:00
if ( ! msg )
return ;
if ( msg . text === undefined )
return ;
2020-03-10 21:44:14 +01:00
const arrtext = msg . text . split ( " " ) ;
let cmd2 = "" ;
let cmd1 = arrtext [ 0 ] ;
if ( arrtext . length > 1 )
cmd2 = arrtext [ 1 ] ;
let oldusername = rec . msgall _username _specifico ;
if ( ( msg . text === Menu . ESCI _DA _CHAT ) || ( msg . text === Menu . INDIETRO ) ) {
rec . msgall _username _specifico = '' ;
} else {
if ( rec . msgall _username _specifico !== '' ) {
await this . SendMsgToUser ( msg , rec , rec . msgall _username _specifico , msg . text ) ;
return true ;
}
}
2020-02-19 16:09:16 +01:00
if ( msg . text === Menu . LAVAGNA || MsgBot . LAVAGNA . find ( ( rec ) => msg . text . indexOf ( rec ) > - 1 ) ) {
2020-03-10 21:44:14 +01:00
await this . menuLavagna ( msg ) ;
} else if ( msg . text === Menu . MIANAVE || ( cmd2 === strNave ) || MsgBot . MIANAVE . find ( ( rec ) => msg . text . indexOf ( rec ) > - 1 ) ) {
await this . menuNave ( msg )
2020-02-19 16:09:16 +01:00
} else if ( msg . text === Menu . ACCEDI ) {
await this . menuAccedi ( msg )
2020-01-03 22:02:18 +01:00
} else if ( msg . text === Menu . LINK _CONDIVIDERE ) {
2020-01-20 01:48:25 +01:00
await this . menuLinkCondividere ( msg )
2020-01-03 22:02:18 +01:00
} else if ( msg . text === Menu . EXIT _TELEGRAM ) {
2020-01-20 01:48:25 +01:00
await this . menuExitToTelegram ( msg )
} else if ( msg . text === Menu . ADMIN ) {
await this . menuAdmin ( msg )
} else if ( msg . text === Menu . MSGATUTTI ) {
await this . menumsgAll ( msg )
2020-02-07 22:08:46 +01:00
} else if ( msg . text === Menu . MSGSTAFF ) {
await this . menumsgStaff ( msg )
2020-03-10 21:44:14 +01:00
} else if ( msg . text === Menu . MSG _NO _7 _REQ ) {
await this . menumsg _No _7 _Req ( msg )
} else if ( msg . text === Menu . MSG _NO _9 _REQ ) {
await this . menumsg _No _9 _Req ( msg )
} else if ( cmd1 === Menu . MSG _TO _NAVE ) {
await this . menumsg _to _Nave ( msg , cmd2 )
} else if ( msg . text === Menu . MSG _SI _INVITATI _NO _7REQ _INVITATI ) {
await this . menumsg _Si _Invitati _No _7Req ( msg )
} else if ( cmd1 . toLowerCase ( ) === Menu . MSG _TO _USER ) {
await this . menumsg _A _Utente ( msg )
2020-01-20 01:48:25 +01:00
} else if ( msg . text === Menu . INDIETRO ) {
await this . msgScegliMenu ( msg ) ;
2020-03-10 21:44:14 +01:00
} else if ( msg . text === Menu . ESCI _DA _CHAT ) {
await this . sendMsg ( msg . chat . id , 'Uscito dalla Chat con ' + oldusername ) ;
rec . msgall _username _specifico = '' ;
2020-01-03 22:02:18 +01:00
} else {
2020-01-20 01:48:25 +01:00
await this . isMenuNotVerified ( rec , msg ) ;
}
}
2020-01-27 15:07:53 +01:00
getsymb ( symb , valid , isnum , num , smileif ) {
2020-01-20 01:48:25 +01:00
let str = symb + ': ' ;
if ( valid )
str += emo . CHECK _VERDE ;
else
str += emo . CROSS _ROSSA ;
if ( isnum ) {
2020-01-27 15:07:53 +01:00
str += ' ' + getemojibynumber ( num ) ;
2020-01-20 01:48:25 +01:00
if ( smileif )
str += emo . SMILE _STAR ;
2020-01-03 01:52:49 +01:00
}
2020-01-20 01:48:25 +01:00
return str + ' ' ;
}
isdreamset ( user ) {
if ( user ) {
if ( user . profile . my _dream )
if ( user . profile . my _dream . length > 10 )
return true
}
return false
2020-01-03 01:52:49 +01:00
}
2020-02-19 16:09:16 +01:00
ispayment ( user ) {
if ( user ) {
let ispaypal = false ;
if ( ! ! user . profile . paymenttypes ) {
if ( user . profile . paymenttypes . includes ( 'paypal' ) ) {
if ( user . profile . email _paypal ) {
ispaypal = true
}
}
if ( ! ! user . profile )
if ( ! ! user . profile . paymenttypes ) {
return ( user . profile . paymenttypes . length >= 1 ) && ispaypal ;
}
}
}
return false
}
async menuAccedi ( msg ) {
let status = this . getstatusInMemory ( msg ) ;
if ( status === Status . WAITFOR _USERNAME _BO ) {
await this . sendMsg ( msg . from . id , txt . MSG _ERRORE _USERNAME _NOT _FOUND , MenuNoLogin ) ;
}
}
async getLavagnaByUser ( user , msg ) {
2020-01-03 01:52:49 +01:00
let mystr = '' ;
2020-02-19 16:09:16 +01:00
const dashboard = await User . getDashboard ( this . idapp , user . aportador _solidario , user . username , user . aportador _solidario _name _surname ) ;
2020-01-03 01:52:49 +01:00
2020-02-19 16:09:16 +01:00
let numpersone = ( dashboard . downline ) ? dashboard . downline . length : 0 ;
let invitati _attivi = dashboard . myself . numinvitatiattivi ;
mystr = "" ;
// if (dashboard.aportador) {
// mystr = emoji.get('seedling') + ` Chi ti ha invitato: ${dashboard.aportador.username} (${dashboard.aportador.name} ${dashboard.aportador.surname})\n`;
// } else {
// mystr = 'Chi ti ha invitato: Sei il Primo! ';
// }
// mystr += `____________________________________________\n`;
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
let tuttie9 = false ;
2020-02-05 00:39:25 +01:00
2020-02-19 16:09:16 +01:00
if ( user ) {
mystr += tools . get _ _ ( 'BENVENUTO' , msg ) + ' ' + user . name + ' (' + user . username + ') ' + emo . DIZZY + '\n\n' ;
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
tuttie9 = dashboard . myself . qualified && ( numpersone >= 2 ) && invitati _attivi >= 2 ;
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
if ( ! tuttie9 ) {
mystr += dashboard . myself . qualified ? emo . SMILE _STAR + tools . get _ _ ( 'HAI_I_7_REQUISITI' , msg ) + emo . SMILE _STAR : emo . EXCLAMATION _MARK + tools . get _ _ ( 'NON_HAI_I_7_REQUISITI' , msg ) ;
mystr += '\n\n' ;
2020-01-03 01:52:49 +01:00
}
2020-02-19 16:09:16 +01:00
mystr += tuttie9 ? emo . SMILE _STAR + tools . get _ _ ( 'HAI_I_9_REQUISITI' , msg ) + emo . SMILE _STAR : emo . EXCLAMATION _MARK + tools . get _ _ ( 'NON_HAI_I_9_REQUISITI' , msg ) ;
mystr += '\n\n' ;
mystr += tools . get _ _ ( 'INFO_LA_MIA_LAVAGNA' , msg ) ;
mystr += '\n' + '1. ' + this . getsymb ( emo . ENVELOPE , user . verified _email ) ;
mystr += tools . get _ _ ( 'EMAIL' , msg ) + ' ' ;
mystr += user . verified _email ? tools . get _ _ ( 'VERIF' , msg ) : tools . get _ _ ( 'EMAIL_NON_VERIF' , msg ) ;
mystr += '\n2. ' + this . getsymb ( emo . ROBOT _FACE , true ) + tools . get _ _ ( 'BOT' , msg ) + ' ' ;
mystr += tools . get _ _ ( 'VERIF' , msg ) ;
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
mystr += '\n3. ' + this . getsymb ( emo . PENCIL , tools . isBitActive ( user . profile . saw _and _accepted , shared _consts . Accepted . CHECK _READ _GUIDELINES ) ) + tools . get _ _ ( 'LINEE_GUIDA' , msg ) ;
mystr += '\n4. ' + this . getsymb ( emo . TV , tools . isBitActive ( user . profile . saw _and _accepted , shared _consts . Accepted . CHECK _SEE _VIDEO _PRINCIPI ) ) + tools . get _ _ ( 'VIDEO_INTRO' , msg ) ;
mystr += '\n5. ' + this . getsymb ( emo . EYES , user . profile . saw _zoom _presentation ) + tools . get _ _ ( 'ZOOM_PARTECIPATO' , msg ) ;
mystr += '\n6. ' + this . getsymb ( emo . DREAM , this . isdreamset ( user ) ) + tools . get _ _ ( 'SCRITTO_SOGNO' , msg ) ;
mystr += '\n7. ' + this . getsymb ( emo . CREDIT _CARD , this . ispayment ( user ) ) + tools . get _ _ ( 'PAYMENTS' , msg ) ;
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
// } else{
// mystr += tools.get__('TELEGRAM_NOT_CONNECTED', msg) + ' ' + emoji.get('e-mail');
}
// numpersone = 2;
mystr += '\n8. ' + this . getsymb ( emo . INVITATI , numpersone >= 2 , numpersone , numpersone , numpersone >= 3 ) + tools . get _ _ ( 'INVITATI' , msg ) ;
mystr += '\n9. ' + this . getsymb ( emo . INVITATI , invitati _attivi >= 2 , invitati _attivi , invitati _attivi , invitati _attivi >= 3 ) + tools . get _ _ ( 'INVITATI_ATTIVI' , msg ) + '\n' + '\n' ;
if ( numpersone > 0 ) {
mystr += tools . get _ _ ( 'INVITATI_LISTA' ) + ':\n' ;
let index = 1 ;
dashboard . downline . forEach ( ( user ) => {
mystr += emoji . get ( 'star-struck' ) + ` ${ index } °: ` ;
mystr += ( user . _doc . qualified ) ? emo . CHECK _VERDE : emo . CROSS _ROSSA ;
mystr += ` ${ user . name } ${ user . surname } ( ${ user . username } ) \n ` ;
index ++ ;
} ) ;
} else {
mystr += tools . get _ _ ( 'NESSUN_INVITATO' ) + tools . ACAPO ;
}
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
// if (dashboard.downnotreg) {
// if (dashboard.downnotreg.length > 0) {
// mystr += '\n' + emo.QUESTION_MARK + ' ' + tools.get__('NONREG', msg) + ':' + emo.QUESTION_MARK + '\n';
// let index = 1;
// dashboard.downnotreg.forEach((user) => {
// mystr += ` - ${index}°: ${user.name} ${user.surname} (tel: ${user.cell_complete})\n`;
// index++;
// });
// }
// }
2020-01-03 01:52:49 +01:00
2020-02-19 16:09:16 +01:00
if ( tuttie9 )
mystr += '\n' + printf ( tools . get _ _ ( 'INFO_LAVAGNA_SITO' , msg ) ) ;
else
mystr += '\n' + printf ( tools . get _ _ ( 'INFO_LAVAGNA_SITO_COMPLETARE' , msg ) , tools . getHostByIdApp ( this . idapp ) ) ;
2020-01-03 01:52:49 +01:00
2020-02-19 16:09:16 +01:00
return mystr ;
}
2020-02-05 00:39:25 +01:00
2020-02-19 16:09:16 +01:00
async menuLavagna ( msg ) {
const rec = this . getRecInMem ( msg ) ;
let mystr = '' ;
if ( rec . user ) {
mystr = await this . getLavagnaByUser ( rec . user , msg )
2020-02-05 00:39:25 +01:00
2020-01-03 01:52:49 +01:00
}
if ( ! ! mystr )
2020-01-20 01:48:25 +01:00
await this . sendMsg ( msg . chat . id , mystr ) ;
2020-01-03 01:52:49 +01:00
}
2020-03-10 21:44:14 +01:00
async menuNave ( msg ) {
const rec = this . getRecInMem ( msg ) ;
let mystr = '' ;
if ( ! rec . user )
return "" ;
let ind _order _to _check = rec . user . ind _order ;
let arrstringa = msg . text . split ( " " ) ;
if ( ! ! arrstringa ) {
if ( arrstringa . length > 1 ) {
let last = arrstringa . slice ( - 1 ) [ 0 ] ;
if ( ! isNaN ( last ) ) {
ind _order _to _check = last ;
}
}
}
mystr = await Nave . getNaveByUser ( this . idapp , ind _order _to _check , rec . user . lang , true ) ;
if ( ! ! mystr )
await this . sendMsg ( msg . chat . id , mystr ) ;
}
2020-01-03 01:52:49 +01:00
async menuLinkCondividere ( msg ) {
const rec = this . getRecInMem ( msg ) ;
2020-02-05 00:39:25 +01:00
let mystr = '' ;
2020-01-03 01:52:49 +01:00
if ( rec . user ) {
2020-02-05 00:39:25 +01:00
mystr += printf ( tools . get _ _ ( 'INFO_LINK_DA_CONDIVIDERE' , msg ) , tools . getHostByIdApp ( this . idapp ) + '/signup/' + rec . user . username , tools . getlinkzoom ( '' ) ) ;
2020-01-20 01:48:25 +01:00
await this . sendMsg ( msg . chat . id , mystr ) ;
2020-01-03 01:52:49 +01:00
}
}
2020-01-03 22:02:18 +01:00
async menuExitToTelegram ( msg ) {
const rec = this . getRecInMem ( msg ) ;
if ( rec . user ) {
2020-02-19 16:09:16 +01:00
await User . SetTelegramIdSuccess ( this . idapp , rec . user . _id , 0 ) . then ( ( recuser ) => {
2020-01-03 22:02:18 +01:00
if ( recuser ) {
this . deleteRecInMem ( msg ) ;
this . sendMsg ( msg . chat . id , txt . MSG _EXIT _TELEGRAM ) ;
}
} )
2020-02-19 16:09:16 +01:00
} else {
this . deleteRecInMem ( msg ) ;
2020-01-03 22:02:18 +01:00
}
}
2020-01-03 01:52:49 +01:00
async menuInformazioni ( msg ) {
const mystr = 'Informazioni Aggiuntive: ...' ;
2020-01-20 01:48:25 +01:00
await this . sendMsg ( msg . chat . id , mystr ) ;
}
2020-02-19 16:09:16 +01:00
async getNextZoom ( ) {
2020-01-21 01:37:15 +01:00
const listazoom = await CalZoom . findAllIdApp ( this . idapp ) ;
const nextzoom = await CalZoom . getNextZoom ( this . idapp ) ;
2020-02-19 16:09:16 +01:00
let mystr = '' ;
2020-02-05 00:39:25 +01:00
mystr += emo . STARS + tools . get _ _ ( 'ZOOM_CONFERENCE' ) + emo . STARS + '\n\n' ;
2020-01-21 01:37:15 +01:00
let index = 1 ;
listazoom . forEach ( ( evento ) => {
2020-01-27 15:07:53 +01:00
let iniziata = false ;
if ( nextzoom )
iniziata = ( nextzoom . _id . toString ( ) === evento . _id . toString ( ) ) ;
2020-01-21 01:37:15 +01:00
2020-01-27 15:07:53 +01:00
if ( iniziata ) {
2020-03-10 21:44:14 +01:00
mystr += emo . CHECK _VERDE + ' ' + tools . get _ _ ( 'ZOOM_INIZIATO' ) + ' ' + emo . CHECK _VERDE + '\n' ;
2020-01-27 15:07:53 +01:00
}
mystr += ` ${ emo . EYES } ${ tools . getstrDateTimeShort ( evento . date _start ) } ${ emo . EYES } ` ;
mystr += ` \n ${ evento . title } \n ( ${ evento . note } ) \n \n ` ;
if ( nextzoom ) {
2020-01-21 01:37:15 +01:00
if ( iniziata ) {
2020-02-19 16:09:16 +01:00
mystr += emo . FIRE + tools . get _ _ ( 'CLICCA_ENTRA' ) + ' ' + emo . FIRE + '\n' ;
2020-01-27 15:07:53 +01:00
mystr += tools . getlinkzoom ( evento . id _conf _zoom ) + '\n\n' ;
2020-01-21 01:37:15 +01:00
}
2020-01-27 15:07:53 +01:00
}
2020-01-21 01:37:15 +01:00
2020-01-27 15:07:53 +01:00
index ++ ;
} ) ;
if ( ! nextzoom && index > 1 ) {
2020-02-19 16:09:16 +01:00
mystr += "✨✨✨✨✨✨✨✨✨✨✨✨\n" +
tools . get _ _ ( 'CLICCA_PER_ZOOM' ) + ':\n' + tools . getlinkzoom ( listazoom [ 0 ] . id _conf _zoom ) + '\n' + "✨✨✨✨✨✨✨✨✨✨✨✨\n" + '\n' ;
2020-01-27 15:07:53 +01:00
}
2020-01-21 01:37:15 +01:00
2020-02-19 16:09:16 +01:00
return mystr
}
async menuZoom ( msg ) {
let mystr = await this . getNextZoom ( ) ;
2020-01-21 01:37:15 +01:00
2020-02-07 22:08:46 +01:00
await this . sendMsg ( msg . chat . id , mystr ) ;
2020-01-21 01:37:15 +01:00
}
2020-01-20 01:48:25 +01:00
async menuAdmin ( msg ) {
2020-02-19 16:09:16 +01:00
const mystr = tools . get _ _ ( 'SCEGLI_VOCE' ) ;
2020-01-21 01:37:15 +01:00
await
this . sendMsg ( msg . chat . id , mystr , MenuAdmin ) ;
2020-01-20 01:48:25 +01:00
}
2020-03-10 21:44:14 +01:00
getDestinStr ( msg , destin , rec ) {
if ( destin === Destin . TUTTI )
return 'TUTTI' ;
else if ( destin === Destin . STAFF )
return 'STAFF' ;
else if ( destin === Destin . NO _7 _REQ )
return 'No 7 Requisiti' ;
else if ( destin === Destin . NO _9 _REQ )
return 'No 9 Requisiti' ;
else if ( destin === Destin . SI _INVITATI _NO _7REQ _INVITATI )
return '2 Invitati ma NO Requisiti' ;
else if ( destin === Destin . MSG _TO _NAVE )
return 'Nave ' + rec . extraparam ;
else if ( destin === Destin . A _UTENTE ) {
const rec = this . getRecInMem ( msg ) ;
return rec . msgall _username _specifico
2020-02-07 22:08:46 +01:00
}
2020-03-10 21:44:14 +01:00
}
async menumsgAll ( msg ) {
await this . menumsgGenerico ( msg , Destin . TUTTI ) ;
2020-02-07 22:08:46 +01:00
}
async menumsgStaff ( msg ) {
2020-03-10 21:44:14 +01:00
await this . menumsgGenerico ( msg , Destin . STAFF ) ;
}
async menumsg _No _7 _Req ( msg ) {
await this . menumsgGenerico ( msg , Destin . NO _7 _REQ ) ;
}
async menumsg _No _9 _Req ( msg ) {
await this . menumsgGenerico ( msg , Destin . NO _9 _REQ ) ;
}
async menumsg _to _Nave ( msg , nave ) {
await this . menumsgGenerico ( msg , Destin . MSG _TO _NAVE , undefined , nave ) ;
}
async menumsg _Si _Invitati _No _7Req ( msg ) {
await this . menumsgGenerico ( msg , Destin . SI _INVITATI _NO _7REQ _INVITATI ) ;
}
async menumsg _A _Utente ( msg ) {
const arr = msg . text . split ( ' ' ) ;
if ( ! ! arr && arr . length > 1 ) {
const username = arr [ 1 ] ;
const rec = this . getRecInMem ( msg ) ;
rec . msg _wait = true ;
await this . SendMsgToUser ( msg , rec , username , msg . text ) ;
}
}
async menumsgGenerico ( msg , dest , username , extraparam ) {
2020-02-07 22:08:46 +01:00
const rec = this . getRecInMem ( msg ) ;
if ( rec . user ) {
rec . msgall _status = StatusMSGALL . ASK ;
2020-03-10 21:44:14 +01:00
rec . msgall _achi = dest ;
rec . extraparam = extraparam ;
if ( ! ! username ) {
rec . msgall _username _specifico = username ;
}
const mystr = 'Scrivi qui un Messaggio da inviare a' + ' [' + this . getDestinStr ( msg , dest , rec ) + ']:' ;
await this . sendMsg ( msg . chat . id , mystr , MenuSend ) ;
2020-01-20 01:48:25 +01:00
}
2020-01-03 01:52:49 +01:00
}
async menuAssistenza ( msg ) {
2020-01-20 01:48:25 +01:00
const mytext = tools . get _ _ ( 'TESTO_ASSISTENZA' , msg ) ;
2020-02-19 16:09:16 +01:00
let menu = null ;
const rec = this . getRecInMem ( msg ) ;
if ( ! rec . user ) {
menu = MenuNoLogin
}
2020-01-21 01:37:15 +01:00
await
2020-02-19 16:09:16 +01:00
this . sendMsg ( msg . chat . id , mytext , menu ) ;
2020-01-03 01:52:49 +01:00
}
existInMemory ( msg ) {
const rec = this . getRecInMem ( msg ) ;
return ! ! rec
}
2020-01-20 01:48:25 +01:00
getstatus ( rec ) {
2020-01-03 01:52:49 +01:00
if ( ! ! rec )
return rec . status ;
else
return Status . NONE ;
}
2020-01-20 01:48:25 +01:00
getstatusInMemory ( msg ) {
const rec = this . getRecInMem ( msg ) ;
return this . getstatus ( rec ) ;
}
2020-01-03 01:52:49 +01:00
getRecInMem ( msg ) {
return this . arrUsers . find ( ( rec ) => rec . id === msg . from . id ) ;
}
2020-02-19 16:09:16 +01:00
getRecInMemById ( id ) {
return this . arrUsers . find ( ( rec ) => rec . id === id ) ;
}
2020-03-10 21:44:14 +01:00
getRecByUsername ( username ) {
return this . arrUsers . find ( ( rec ) => rec . username _bo === username ) ;
}
getRecInMemById ( id ) {
return this . arrUsers . find ( ( rec ) => rec . id === id ) ;
}
2020-01-03 22:02:18 +01:00
deleteRecInMem ( msg ) {
this . arrUsers = this . arrUsers . filter ( ( rec ) => rec . id !== msg . from . id ) ;
}
2020-02-19 16:09:16 +01:00
async getUser ( msg , rec , conmsg ) {
let myid = 0 ;
let ok = false ;
2020-03-10 21:44:14 +01:00
let mystruser = tools . getFirstWord ( msg . text . trim ( ) ) ;
const user = await User . findByUsername ( this . idapp , mystruser , true ) ;
2020-02-19 16:09:16 +01:00
if ( ! user ) {
if ( conmsg ) {
await this . sendMsg ( msg . from . id , txt . MSG _ERRORE _USERNAME _NOT _FOUND , MenuNoLogin ) ;
const textman = msg . chat . first _name + ' ' + msg . chat . last _name + ' sta tentando di autenticarsi con il BOT (username che scrive: ' + msg . text + ') ' ;
await local _sendMsgTelegramToTheManagers ( this . idapp , textman , msg ) ;
rec . username _bo = '' ;
}
} else {
rec . username _bo = user . username ;
myid = user . _id ;
ok = true ;
}
return { rec , user , myid , ok } ;
}
2020-01-03 01:52:49 +01:00
async setUsernameBo ( msg ) {
try {
2020-02-19 16:09:16 +01:00
let rec = this . getRecInMem ( msg ) ;
2020-01-27 15:07:53 +01:00
if ( msg . text === undefined )
return false ;
2020-01-03 01:52:49 +01:00
console . log ( 'msg.text' , msg . text ) ;
const text = msg . text ;
2020-02-19 16:09:16 +01:00
if ( text . length < 40 ) {
2020-01-03 01:52:49 +01:00
if ( rec ) {
2020-02-19 16:09:16 +01:00
let ris = await this . getUser ( msg , rec , true ) ;
rec = ris . rec ;
2020-01-27 15:07:53 +01:00
2020-02-19 16:09:16 +01:00
if ( ris . ok ) {
rec . user = ris . user ;
await User . SetTelegramCheckCode ( this . idapp , ris . myid . toString ( ) , rec . code ) ;
rec . status = Status . WAITFOR _VERIFY _CODE ;
await this . sendMsg ( msg . from . id , printf ( txt . MSG _VERIFY _CODE , tools . getHostByIdApp ( this . idapp ) ) , MenuNoLogin )
2020-01-03 01:52:49 +01:00
}
}
} else if ( text . length === 0 ) {
if ( rec )
rec . status = Status . NONE ;
2020-02-19 16:09:16 +01:00
await this . sendMsg ( msg . from . id , txt . MSG _ERRORE _USERNAME _ANNULLA ) ;
2020-01-20 01:48:25 +01:00
this . deleteRecInMem ( msg )
2020-01-03 01:52:49 +01:00
} else {
2020-02-19 16:09:16 +01:00
await this . sendMsg ( msg . from . id , txt . MSG _ERRORE _USERNAME )
2020-01-03 01:52:49 +01:00
}
} catch ( e ) {
console . error ( 'Error setUsernameBo:' , e )
}
}
async setVerifyCode ( msg ) {
try {
const code = msg . text . toString ( ) . trim ( ) ;
2020-02-19 16:09:16 +01:00
const rec = this . getRecInMem ( msg ) ;
const user = await User . findByUsername ( this . idapp , rec . username _bo , true ) ;
2020-01-03 22:02:18 +01:00
let telegcode = 0 ;
if ( user ) {
telegcode = user . profile . teleg _checkcode . toString ( ) ;
} else {
2020-01-21 01:37:15 +01:00
await
2020-02-19 16:09:16 +01:00
this . sendMsg ( msg . from . id , txt . MSG _ERRORE _USERNAME _NOT _FOUND , MenuNoLogin ) ;
2020-01-03 22:02:18 +01:00
return
}
2020-02-19 16:09:16 +01:00
if ( code . length < 7 ) {
2020-01-03 01:52:49 +01:00
if ( rec ) {
2020-01-03 22:02:18 +01:00
if ( code === telegcode ) {
2020-02-19 16:09:16 +01:00
// let ris = await this.getUser(msg, rec, false);
2020-01-03 01:52:49 +01:00
rec . status = Status . VERIFIED ;
2020-02-19 16:09:16 +01:00
await User . SetTelegramIdSuccess ( this . idapp , user . _id , msg . from . id ) . then ( ( recuser ) => {
if ( recuser ) {
let name = recuser . name ;
this . sendMsg ( msg . from . id , printf ( txt . MSG _VERIFY _OK , name ) ) ;
local _sendMsgTelegramToTheManagers ( this . idapp , recuser . name + ' ' + recuser . surname + ' si è Verificato a Telegram BOT!' + emo . STARS , msg ) ;
} else {
this . sendMsg ( msg . from . id , txt . MSG _ERR _UNKNOWN _VERIFY _CODE ) ;
}
} ) ;
2020-01-03 01:52:49 +01:00
} else {
2020-01-20 01:48:25 +01:00
if ( rec . retry < 2 ) {
rec . retry ++ ;
2020-01-21 01:37:15 +01:00
await
2020-02-05 00:39:25 +01:00
this . sendMsg ( msg . from . id , printf ( txt . MSG _ERR _VERIFY _CODE , tools . getHostByIdApp ( this . idapp ) ) ) ;
2020-01-20 01:48:25 +01:00
} else {
rec . status = Status . NONE ;
2020-01-21 01:37:15 +01:00
await
this . sendMsg ( msg . from . id , txt . MSG _ERRORE _USERNAME _ANNULLA ) ;
2020-01-20 01:48:25 +01:00
this . deleteRecInMem ( msg ) ;
}
2020-01-03 01:52:49 +01:00
}
}
} else if ( msg . text . length === 0 ) {
if ( rec )
rec . status = Status . NONE ;
2020-01-21 01:37:15 +01:00
await
this . sendMsg ( msg . from . id , txt . MSG _ERRORE _USERNAME _ANNULLA )
2020-01-03 01:52:49 +01:00
} else {
2020-01-21 01:37:15 +01:00
await
this . sendMsg ( msg . from . id , txt . MSG _ERRORE _VERIFY _CODE _MAXLEN )
2020-01-03 01:52:49 +01:00
}
} catch ( e ) {
console . error ( 'Error setVerifyCode' , e ) ;
}
}
2020-03-10 21:44:14 +01:00
async sistemaRecDest ( rec , msg ) {
let recdest = this . getRecByUsername ( rec . msgall _username _specifico ) ;
if ( ! recdest ) {
const userdest = await User . findByUsername ( this . idapp , rec . msgall _username _specifico ) ;
if ( ! ! userdest ) {
let msgdest = msg ;
msgdest . from . id = userdest . profile . teleg _id ;
await this . createIfNotExist ( msgdest ) ;
recdest = this . getRecByUsername ( rec . msgall _username _specifico ) ;
}
}
if ( ! ! recdest ) {
recdest . msgall _username _specifico = rec . username _bo ;
2020-01-20 01:48:25 +01:00
} else {
2020-03-10 21:44:14 +01:00
rec . msgall _username _specifico = '' ;
}
2020-01-20 01:48:25 +01:00
2020-03-10 21:44:14 +01:00
return recdest
}
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
async sendMsgToAll ( rec , msg , texttosend , destin ) {
try {
if ( ( texttosend . length < 3 ) && ( destin !== Destin . A _UTENTE ) ) {
} else {
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
let usersall = null ;
if ( destin === Destin . A _UTENTE )
usersall = await User . getUsersTelegALL ( rec . user . idapp , rec . msgall _username _specifico ) ;
2020-02-19 16:09:16 +01:00
else
2020-03-10 21:44:14 +01:00
usersall = await User . getUsersTelegALL ( rec . user . idapp ) ;
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
let nummsgsent = 0 ;
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
let textdainviare = "" ;
let preparatesto = '' ;
let myid = '' ;
if ( texttosend === Menu . ZOOM ) {
texttosend = await this . getNextZoom ( )
}
const cmd = texttosend . toLowerCase ( ) ;
if ( usersall ) {
if ( cmd === Menu . INDIETRO ) {
rec . msgall _status = StatusMSGALL . NONE ;
return
2020-02-07 22:08:46 +01:00
}
2020-03-10 21:44:14 +01:00
tools . writeEventsLog ( this . getDestinStr ( msg , destin , rec ) + ':\n' + texttosend ) ;
for ( const utente of usersall ) {
if ( texttosend === Menu . LAVAGNA ) {
textdainviare = await this . getLavagnaByUser ( utente , msg ) ;
} else if ( destin === Destin . A _UTENTE ) {
textdainviare = texttosend ;
} else {
textdainviare = texttosend ;
}
let invia = false ;
if ( destin === Destin . STAFF ) {
invia = User . isManager ( utente . perm ) ;
} else if ( destin === Destin . TUTTI ) {
invia = true ;
} else if ( destin === Destin . A _UTENTE ) {
invia = utente . username === rec . msgall _username _specifico ;
} else if ( destin === Destin . NO _7 _REQ ) {
invia = ! await User . isUserQualified7 ( this . idapp , utente . username ) ;
} else if ( destin === Destin . NO _9 _REQ ) {
invia = ! await User . isUserQualified9 ( this . idapp , utente . username ) ;
} else if ( destin === Destin . MSG _TO _NAVE ) {
invia = ! await Nave . findDonatoreByNave ( this . idapp , rec . extraparam ) ;
} else if ( destin === Destin . SI _INVITATI _NO _7REQ _INVITATI ) {
const numinvitati = await User . getnumInvitati ( this . idapp , utente . username ) ;
const numinvitatiattivi = await User . getnumInvitatiAttivi ( this . idapp , utente . username ) ;
invia = ( numinvitati >= 2 ) && ( numinvitatiattivi < 2 ) ;
}
if ( invia ) {
if ( cmd === RICEVI _EMAIL ) {
preparatesto += utente . email + ', ' ;
} else if ( cmd === CONTA _SOLO ) {
// Niente
} else {
if ( destin === Destin . A _UTENTE ) {
await this . sistemaRecDest ( rec , msg ) ;
await this . sendMsg ( utente . profile . teleg _id , '[' + rec . username _bo + ' ti scrive]:\n' + textdainviare , MenuChat ) ;
} else {
await this . sendMsg ( utente . profile . teleg _id , textdainviare ) ;
}
await tools . snooze ( 300 )
}
nummsgsent ++ ;
if ( ! SendMsgCmd . includes ( cmd ) ) {
if ( ( nummsgsent % 50 ) === 0 ) {
myid = await this . sendMsg ( msg . chat . id , nummsgsent + ' ' + getstr ( msg . from . language _code , txt . MSG _MSG _INCORSO ) , null , { message _id : myid } ) ;
await tools . snooze ( 300 )
}
}
}
2020-02-07 22:08:46 +01:00
}
2020-03-10 21:44:14 +01:00
}
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
let msgris = "" ;
if ( cmd === CONTA _SOLO ) {
msgris = nummsgsent + ' ' + getstr ( msg . from . language _code , txt . MSG _MSG _TOSENT ) ;
} else if ( cmd === RICEVI _EMAIL ) {
msgris = nummsgsent + ' ' + 'Email' ;
await this . sendMsg ( msg . chat . id , msgris ) ;
msgris = preparatesto ;
} else {
msgris = nummsgsent + ' ' + getstr ( msg . from . language _code , txt . MSG _MSG _SENT ) ;
}
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
if ( destin === Destin . A _UTENTE ) {
const recdest = await this . sistemaRecDest ( rec ) ;
if ( ! ! recdest ) {
await this . sendMsg ( msg . chat . id , 'Conversazione Iniziata con ' + rec . msgall _username _specifico + ' !' , MenuChat ) ;
} else {
await this . sendMsg ( msg . chat . id , 'Utente ' + rec . msgall _username _specifico + ' non presente sul BOT !' ) ;
}
} else {
tools . writeEventsLog ( msgris ) ;
await this . sendMsg ( msg . chat . id , msgris ) ;
2020-01-20 01:48:25 +01:00
}
2020-03-10 21:44:14 +01:00
}
rec . start _write _msgall = false ;
} catch ( e ) {
console . error ( e ) ;
2020-01-20 01:48:25 +01:00
}
}
2020-03-10 21:44:14 +01:00
2020-01-20 01:48:25 +01:00
selectMenuHelp ( msg ) {
return ( ( msg . text === Menu . INFO ) || ( msg . text === Menu . ASSISTENZA ) )
}
2020-01-03 01:52:49 +01:00
async receiveMsg ( msg ) {
let status = this . getstatusInMemory ( msg ) ;
if ( status === Status . NONE ) {
2020-02-19 16:09:16 +01:00
await this . start ( msg ) ;
2020-01-03 22:02:18 +01:00
let status = this . getstatusInMemory ( msg ) ;
if ( status !== Status . VERIFIED )
return
2020-01-20 01:48:25 +01:00
} else {
2020-02-19 16:09:16 +01:00
await this . setUser ( msg )
2020-01-03 01:52:49 +01:00
}
2020-01-20 01:48:25 +01:00
const rec = this . getRecInMem ( msg ) ;
status = this . getstatus ( rec ) ;
if ( status === Status . WAITFOR _USERNAME _BO && ! this . selectMenuHelp ( msg ) ) {
2020-02-19 16:09:16 +01:00
await this . setUsernameBo ( msg )
2020-01-03 01:52:49 +01:00
} else if ( status === Status . WAITFOR _VERIFY _CODE ) {
2020-02-19 16:09:16 +01:00
await this . setVerifyCode ( msg )
2020-01-03 01:52:49 +01:00
} else if ( status === Status . NONE ) {
2020-02-19 16:09:16 +01:00
await this . start ( msg ) ;
2020-01-03 01:52:49 +01:00
} else if ( status === Status . VERIFIED ) {
2020-01-20 01:48:25 +01:00
let normale = true ;
if ( rec . msgall _status === StatusMSGALL . CONFIRM ) {
if ( msg . text === Menu . SI ) {
// Take msg to send to ALL
2020-03-10 21:44:14 +01:00
await this . sendMsgToAll ( rec , msg , rec . msgtosent , rec . msgall _achi )
2020-01-20 01:48:25 +01:00
} else {
this . sendMsg ( msg . chat . id , txt . MSG _OPERAZ _ANNULLATA ) ;
}
rec . msgall _status = StatusMSGALL . NONE ;
normale = false ;
} else if ( rec . msgall _status === StatusMSGALL . ASK ) {
if ( msg . text !== Menu . INDIETRO ) {
rec . msgtosent = msg . text ;
rec . msgall _status = StatusMSGALL . CONFIRM ;
2020-03-10 21:44:14 +01:00
const cmd = rec . msgtosent . toLowerCase ( ) ;
let achi = this . getDestinStr ( msg , rec . msgall _achi , rec ) ;
let domanda = '' ;
if ( cmd === CONTA _SOLO )
domanda = 'Confermi di vedere a quante persone arriverebbe questo messaggio, a ' + achi + ' ?\n' + rec . msgtosent ;
else if ( cmd === RICEVI _EMAIL )
domanda = 'Confermi di vedere la lista delle email di ' + achi + '?' ;
else {
if ( rec . msgall _achi === Destin . A _UTENTE )
domanda = 'Confermi d\'Iniziare una Chat messaggi con ' + achi + ' ?\n' + rec . msgtosent ;
else
domanda = 'Confermi d\'Inviare questo messaggio a ' + achi + ' ?\n' + rec . msgtosent ;
}
2020-01-20 01:48:25 +01:00
this . ChiediSINO ( msg , domanda ) ;
} else {
rec . msgall _status = StatusMSGALL . NONE ;
2020-01-21 01:37:15 +01:00
await
this . msgScegliMenu ( msg ) ;
2020-01-20 01:48:25 +01:00
}
normale = false
}
if ( normale ) {
// Check Menu
2020-02-19 16:09:16 +01:00
await this . isMenu ( rec , msg ) ;
2020-01-20 01:48:25 +01:00
}
} else {
2020-01-21 01:37:15 +01:00
await
this . isMenuNotVerified ( rec , msg ) ;
2020-01-03 01:52:49 +01:00
}
}
async askVerifiedCode ( msg ) {
const rec = this . arrUsers . find ( ( rec ) => rec . id === msg . from . id ) ;
if ( ! rec ) {
2020-02-19 16:09:16 +01:00
await this . addUser ( msg ) ;
2020-01-03 01:52:49 +01:00
2020-02-05 00:39:25 +01:00
// await this.sendMsg(msg.chat.id, getstr(msg.from.language_code, printf(txt.MSG_ASK_USERNAME_BO, tools.getHostByIdApp(this.idapp))));
2020-02-19 16:09:16 +01:00
await this . sendMsg ( msg . chat . id , getstr ( msg . from . language _code , printf ( txt . MSG _ASK _USERNAME _BO , tools . getNomeAppByIdApp ( this . idapp ) ) ) , MenuNoLogin ) ;
2020-01-20 01:48:25 +01:00
return false ;
2020-01-03 01:52:49 +01:00
}
2020-01-20 01:48:25 +01:00
return true ;
2020-01-03 01:52:49 +01:00
}
2020-01-20 01:48:25 +01:00
async setUser ( msg ) {
2020-01-03 01:52:49 +01:00
const id = msg . from . id ;
2020-03-10 21:44:14 +01:00
const user = await User . UserByIdTelegram ( this . idapp , id ) ;
2020-01-03 01:52:49 +01:00
let rec = this . arrUsers . find ( ( rec ) => rec . id === msg . from . id ) ;
2020-01-20 01:48:25 +01:00
if ( user && rec ) {
2020-01-03 01:52:49 +01:00
rec . user = user ;
2020-01-20 01:48:25 +01:00
}
}
2020-03-10 21:44:14 +01:00
async setUserbyUsername ( username ) {
const user = await User . findByUsername ( this . idapp , username ) ;
let rec = this . arrUsers . find ( ( rec ) => rec . username _bo === username ) ;
if ( user && rec ) {
rec . user = user ;
}
}
2020-01-20 01:48:25 +01:00
async alreadyExist ( msg ) {
const id = msg . from . id ;
let rec = null ;
try {
2020-02-19 16:09:16 +01:00
const user = await User . UserByIdTelegram ( this . idapp , id ) ;
2020-01-20 01:48:25 +01:00
let rec = this . arrUsers . find ( ( rec ) => rec . id === msg . from . id ) ;
if ( user && ! rec ) {
rec = this . addUser ( msg ) ;
}
if ( rec ) {
rec . user = user ;
if ( user )
rec . username _bo = user . username ;
else
rec . username _bo = ''
}
} catch ( e ) {
console . error ( 'Error: ' , e ) ;
2020-01-03 22:02:18 +01:00
}
2020-01-03 01:52:49 +01:00
return ! ! rec
}
addUser ( msg ) {
const lang = msg . from . language _code ;
const code = 100000 + Math . round ( Math . random ( ) * 899999 ) ;
const rec = {
id : msg . from . id ,
code ,
lang ,
status : Status . WAITFOR _USERNAME _BO ,
2020-02-19 16:09:16 +01:00
statusmsg : 0 ,
msgcodeprec : '' ,
sex : 0 ,
numdomande : 0 ,
2020-01-03 01:52:49 +01:00
retry : 0 ,
2020-01-20 01:48:25 +01:00
username _bo : '' ,
msgall _status : StatusMSGALL . NONE ,
2020-03-10 21:44:14 +01:00
msgall _achi : 0 ,
msgall _username _specifico : '' ,
extraparam : '' ,
2020-01-20 01:48:25 +01:00
msgtosent : '' ,
2020-03-10 21:44:14 +01:00
msg _wait : false ,
lastmenu : null ,
2020-01-03 01:52:49 +01:00
} ;
this . arrUsers . push ( rec ) ;
return rec ;
}
2020-02-19 16:09:16 +01:00
async insertIntoDB ( msg ) {
2020-01-03 01:52:49 +01:00
2020-02-19 16:09:16 +01:00
return await this . askVerifiedCode ( msg ) ;
2020-01-20 01:48:25 +01:00
}
async getKeyboard ( id , menu ) {
let keyb = MenuStandard ;
// Check if you are Admin
2020-03-10 21:44:14 +01:00
const ismanager = await User . isAdminByIdTeleg ( this . idapp , id ) ;
if ( ismanager && menu !== MenuChat )
2020-01-20 01:48:25 +01:00
keyb = MenuPerAdmin ;
if ( menu ) {
keyb = menu
}
2020-01-03 01:52:49 +01:00
2020-01-20 01:48:25 +01:00
return keyb
2020-01-03 01:52:49 +01:00
}
2020-02-19 16:09:16 +01:00
modificaMsg ( chatid , idmodif , text ) {
const form = {
"chat_id" : chatid ,
"message_id" : idmodif ,
} ;
try {
return this . bot . editMessageText ( text , form ) ;
} catch ( e ) {
console . log ( 'Err Telegram: ' + e ) ;
}
}
2020-03-10 21:44:14 +01:00
async _inviaMsg ( id , text , form , menu , msg _id , chat _id , ripr _menuPrec ) {
2020-01-20 01:48:25 +01:00
if ( ! text )
2020-02-19 16:09:16 +01:00
return 0 ;
2020-01-20 01:48:25 +01:00
2020-02-19 16:09:16 +01:00
if ( ! ! msg _id ) {
return this . modificaMsg ( chat _id , msg _id , text ) ;
}
2020-03-10 21:44:14 +01:00
const recmem = this . getRecInMemById ( id ) ;
if ( ! menu ) {
if ( recmem ) {
if ( recmem . msgall _username _specifico !== '' ) {
menu = MenuChat
}
}
}
if ( recmem ) {
recmem . lastmenu = menu
}
if ( ripr _menuPrec ) {
if ( recmem && ! ! recmem . lastmenu ) {
menu = recmem . lastmenu
}
}
2020-02-19 16:09:16 +01:00
try {
if ( ! form ) {
form = {
"message_id" : msg _id ,
"reply_markup" : {
"resize_keyboard" : true ,
"keyboard" : await this . getKeyboard ( id , menu )
}
} ;
2020-01-03 01:52:49 +01:00
}
2020-02-19 16:09:16 +01:00
const res = this . bot . sendMessage ( id , text , form )
. catch ( ( e ) => {
let blocked = false ;
if ( ( e . message . indexOf ( 'Forbidden' ) > 0 ) || ( e . message . indexOf ( 'chat not found' ) > 0 ) ) {
blocked = true ;
}
if ( ! blocked ) {
console . error ( e . message ) ;
}
if ( blocked ) {
User . SetTelegramWasBlocked ( this . idapp , id ) ;
}
return 0 ;
} ) ;
return res ;
} catch ( e ) {
return 0
}
2020-01-03 01:52:49 +01:00
}
2020-03-10 21:44:14 +01:00
async SendMsgToUser ( msg , rec , username , text ) {
if ( rec . msg _wait ) {
await this . menumsgGenerico ( msg , Destin . A _UTENTE , username ) ;
rec . msg _wait = false ;
} else {
const telegid = await User . TelegIdByUsername ( this . idapp , username ) ;
if ( telegid > 0 ) {
await this . sistemaRecDest ( rec , msg ) ;
// await this.sendMsg(msg.chat.id, '[Msg inviato a ' + username + ']: ');
await this . sendMsg ( telegid , Menu . CHAT _PERSONALE + '[' + rec . username _bo + ' ti scrive]:\n' + text , MenuChat ) ;
} else {
await this . sendMsg ( msg . chat . id , 'Username non valido' ) ;
rec . msgall _username _specifico = ''
}
}
}
async sendMsg ( id , text , menu , form , msg _id , chat _id , ripr _menuPrec ) {
2020-02-19 16:09:16 +01:00
2020-03-10 21:44:14 +01:00
return this . _inviaMsg ( id , text , form , menu , msg _id , chat _id , ripr _menuPrec ) ;
2020-01-03 01:52:49 +01:00
2020-02-19 16:09:16 +01:00
}
async msgBenvenuto ( id ) {
return this . _inviaMsg ( id , Benvenuto , {
2020-01-03 01:52:49 +01:00
"reply_markup" : {
2020-01-20 01:48:25 +01:00
"resize_keyboard" : true ,
"keyboard" : await this . getKeyboard ( id )
}
2020-02-19 16:09:16 +01:00
} ) ;
2020-01-20 01:48:25 +01:00
}
async ChiediSINO ( msg , domanda ) {
2020-02-19 16:09:16 +01:00
this . _inviaMsg ( msg . from . id , domanda , {
2020-01-20 01:48:25 +01:00
"reply_markup" : {
"resize_keyboard" : true ,
'one_time_keyboard' : true ,
"keyboard" : MenuYesNo
2020-01-03 01:52:49 +01:00
}
} ) ;
}
2020-01-03 22:02:18 +01:00
2020-01-20 01:48:25 +01:00
async msgScegliMenu ( msg ) {
// const rec = this.getRecInMem(msg);
2020-02-19 16:09:16 +01:00
this . _inviaMsg ( msg . from . id , txt . MSG _SCEGLI _MENU , {
2020-01-03 22:02:18 +01:00
"reply_markup" : {
2020-01-20 01:48:25 +01:00
"resize_keyboard" : true ,
"keyboard" : await this . getKeyboard ( msg . from . id )
2020-01-03 22:02:18 +01:00
}
2020-01-21 01:37:15 +01:00
} )
;
2020-01-03 22:02:18 +01:00
}
2020-01-03 01:52:49 +01:00
}
const arrTelegram = [ ] ;
function getclTelegBytoken ( token ) {
2020-01-03 22:02:18 +01:00
const rec = arrTelegram . find ( ( rec ) => rec . cl . token === token ) ;
if ( ! ! rec )
return rec . cl ;
else
return null ;
}
function getclTelegByidapp ( idapp ) {
2020-02-07 22:08:46 +01:00
// ****************************
if ( appTelegramFinti . includes ( idapp ) ) {
const ind = appTelegramFinti . indexOf ( idapp ) ;
if ( ind >= 0 )
idapp = appTelegramDest [ ind ] ; // Invia
}
2020-01-03 22:02:18 +01:00
const rec = arrTelegram . find ( ( rec ) => rec . idapp === idapp ) ;
2020-01-03 01:52:49 +01:00
if ( ! ! rec )
return rec . cl ;
else
return null ;
}
2020-01-13 23:52:51 +01:00
if ( ! tools . testing ( ) ) {
console . log ( 'TELEGRAM STARTING.... ' ) ;
for ( const idapp of appTelegram ) {
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
const token = tools . getTelegramKeyByIdApp ( idapp ) ;
// console.log('idapp', idapp, 'token', token);
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
if ( ! ! token ) {
const bot = new TelegramBot ( token , { polling : true } ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
arrTelegram . push ( { idapp , cl : new Telegram ( idapp , bot ) } ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
bot . onText ( /\/start/ , ( msg ) => {
const myclTelegram = getclTelegBytoken ( bot . token ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
myclTelegram . start ( msg ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
} ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
// Matches "/echo [whatever]"
bot . onText ( /\/echo (.+)/ , ( msg , match ) => {
// 'msg' is the received Message from Telegram
// 'match' is the result of executing the regexp above on the text content
// of the message
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
const chatId = msg . chat . id ;
const resp = match [ 1 ] ; // the captured "whatever"
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
// send back the matched "whatever" to the chat
bot . sendMessage ( chatId , resp ) ;
} ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
// Listen for any kind of message. There are different kinds of
// messages.
bot . on ( 'message' , ( msg ) => {
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
const myclTelegram = getclTelegBytoken ( bot . token ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
// console.log('msg', msg);
const chatId = msg . chat . id ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
myclTelegram . receiveMsg ( msg ) ;
// var bye = "bye";
// if (msg.text.toString().toLowerCase().includes(bye)) {
// bot.sendMessage(msg.chat.id, "Hope to see you around again , Bye");
// }
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
// send a message to the chat acknowledging receipt of their message
// bot.sendMessage(chatId, 'Received your message');
} ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
// Handle callback queries
bot . on ( 'callback_query' , function onCallbackQuery ( callbackQuery ) {
console . log ( 'callback_query' , callbackQuery ) ;
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
bot . answerCallbackQuery ( callbackQuery . id , { url } ) ;
} ) ;
}
2020-01-03 01:52:49 +01:00
2020-01-13 23:52:51 +01:00
}
2020-01-03 01:52:49 +01:00
}