Abilitazione del BOT
This commit is contained in:
12
filelog.txt
12
filelog.txt
@@ -93,3 +93,15 @@ Gio 12/10 ORE 15:06: USER [paoloar77]: bottone
|
|||||||
Ven 13/10 ORE 11:05: USER [SuryaArena]: bottone
|
Ven 13/10 ORE 11:05: USER [SuryaArena]: bottone
|
||||||
|
|
||||||
Ven 13/10 ORE 11:40: USER [SuryaArena]: bottone
|
Ven 13/10 ORE 11:40: USER [SuryaArena]: bottone
|
||||||
|
|
||||||
|
Dom 17/12 ORE 15:38: USER [admin]: prova
|
||||||
|
|
||||||
|
Dom 17/12 ORE 16:18: USER [admin]: vai al sito
|
||||||
|
|
||||||
|
Dom 17/12 ORE 16:19: USER [admin]: vai al sito
|
||||||
|
|
||||||
|
Dom 17/12 ORE 16:19: USER [admin]: il mio profilo
|
||||||
|
|
||||||
|
Dom 17/12 ORE 16:19: USER [admin]: prova
|
||||||
|
|
||||||
|
Dom 17/12 ORE 16:19: USER [admin]: link da condividere
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ const BotSchema = new Schema({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
BotSchema.statics.getFieldsForSearch = function() {
|
BotSchema.statics.getFieldsForSearch = function () {
|
||||||
return [{ field: 'label', type: tools.FieldType.string }]
|
return [{ field: 'label', type: tools.FieldType.string }]
|
||||||
};
|
};
|
||||||
|
|
||||||
BotSchema.statics.executeQueryTable = function(idapp, params) {
|
BotSchema.statics.executeQueryTable = function (idapp, params) {
|
||||||
params.fieldsearch = this.getFieldsForSearch();
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
return tools.executeQueryTable(this, idapp, params);
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
};
|
};
|
||||||
@@ -66,12 +66,141 @@ BotSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
BotSchema.statics.findAllIdApp = async function(idapp) {
|
BotSchema.statics.generateBotMenuRecords = async function (idapp) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
let arrrec = [
|
||||||
|
{
|
||||||
|
"page": 1,
|
||||||
|
"index": 1,
|
||||||
|
"riga": 1,
|
||||||
|
"active": true,
|
||||||
|
"label": "Vai al Sito",
|
||||||
|
"type": 3,
|
||||||
|
"value": "{host}",
|
||||||
|
"visibility": 0,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
"main": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 1,
|
||||||
|
"index": 1,
|
||||||
|
"riga": 2,
|
||||||
|
"active": true,
|
||||||
|
"label": "Il mio Profilo",
|
||||||
|
"type": 3,
|
||||||
|
"value": "{host}/my/{username}",
|
||||||
|
"visibility": 1,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
"main": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 1,
|
||||||
|
"index": 1,
|
||||||
|
"riga": 3,
|
||||||
|
"active": true,
|
||||||
|
"label": "Link da Condividere",
|
||||||
|
"type": 2,
|
||||||
|
"value": "{host}/registrati/{username}",
|
||||||
|
"visibility": 1,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
"main": true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 1,
|
||||||
|
"index": 2,
|
||||||
|
"riga": 1,
|
||||||
|
"active": true,
|
||||||
|
"label": "🔮 Help",
|
||||||
|
"type": 4,
|
||||||
|
"value": "",
|
||||||
|
"visibility": 0,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
"main": true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 1,
|
||||||
|
"index": 1,
|
||||||
|
"riga": 3,
|
||||||
|
"active": true,
|
||||||
|
"label": "💁♀️ Admin",
|
||||||
|
"type": 4,
|
||||||
|
"value": "",
|
||||||
|
"visibility": 5,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
"main": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 1,
|
||||||
|
"index": 2,
|
||||||
|
"riga": 2,
|
||||||
|
"active": true,
|
||||||
|
"label": "Imposta Foto Profilo",
|
||||||
|
"type": 4,
|
||||||
|
"value": "🖼 SetPicProfile",
|
||||||
|
"visibility": 1,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
"main": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 1,
|
||||||
|
"index": 2,
|
||||||
|
"riga": 3,
|
||||||
|
"active": true,
|
||||||
|
"label": "🛠 Strumenti",
|
||||||
|
"type": 1,
|
||||||
|
"value": "2",
|
||||||
|
"visibility": 1,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
"main": true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 2,
|
||||||
|
"index": 1,
|
||||||
|
"riga": 1,
|
||||||
|
"active": true,
|
||||||
|
"label": "🔑 Cambio Password",
|
||||||
|
"type": 4,
|
||||||
|
"value": "🔑 SetResetPwd",
|
||||||
|
"visibility": 1,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"page": 2,
|
||||||
|
"index": 1,
|
||||||
|
"riga": 2,
|
||||||
|
"active": true,
|
||||||
|
"label": "👉🏻 Indietro",
|
||||||
|
"type": 1,
|
||||||
|
"value": "1",
|
||||||
|
"visibility": 1,
|
||||||
|
idapp,
|
||||||
|
"lang": "it",
|
||||||
|
}];
|
||||||
|
|
||||||
|
const ris = await MyBot.insertMany(arrrec);
|
||||||
|
|
||||||
|
return ris;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err:', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
BotSchema.statics.findAllIdApp = async function (idapp) {
|
||||||
const Bot = this;
|
const Bot = this;
|
||||||
|
|
||||||
const myfind = {idapp};
|
const myfind = { idapp };
|
||||||
|
|
||||||
return await Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1}).lean();
|
return await Bot.find(myfind).sort({ page: 1, lang: 1, riga: 1, index: 1 }).lean();
|
||||||
};
|
};
|
||||||
|
|
||||||
const MyBot = mongoose.model('Bot', BotSchema);
|
const MyBot = mongoose.model('Bot', BotSchema);
|
||||||
@@ -80,4 +209,4 @@ MyBot.createIndexes((err) => {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {MyBot};
|
module.exports = { MyBot };
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
|||||||
return order;
|
return order;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('*** Num myorderscart ', myorderscart.length);
|
||||||
return myorderscart
|
return myorderscart
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err:', e);
|
console.error('Err:', e);
|
||||||
|
|||||||
@@ -64,6 +64,12 @@ const SiteSchema = new Schema({
|
|||||||
telegram_key_test: {
|
telegram_key_test: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
load_process_telegram: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
|
load_process_telegram_test: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
teleg_cfg: {
|
teleg_cfg: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const i18n = require('i18n');
|
|||||||
|
|
||||||
const shared_consts = require('../tools/shared_nodejs');
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
|
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
|
|
||||||
mongoose.level = 'F';
|
mongoose.level = 'F';
|
||||||
@@ -5387,6 +5388,8 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (arrSite && arrSite.length === 1 && numutenti < 2) {
|
if (arrSite && arrSite.length === 1 && numutenti < 2) {
|
||||||
|
const MyTelegramBot = require('../telegram/telegrambot');
|
||||||
|
|
||||||
// Nessun Sito Installato e Nessun Utente installato !
|
// Nessun Sito Installato e Nessun Utente installato !
|
||||||
let myuser = new User();
|
let myuser = new User();
|
||||||
myuser._id = new ObjectID();
|
myuser._id = new ObjectID();
|
||||||
@@ -5403,11 +5406,19 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
|
|||||||
myuser.perm = '3';
|
myuser.perm = '3';
|
||||||
myuser.profile.special_req = true;
|
myuser.profile.special_req = true;
|
||||||
myuser.profile.nationality = 'IT';
|
myuser.profile.nationality = 'IT';
|
||||||
|
myuser.profile.manage_telegram = true;
|
||||||
|
myuser.profile.teleg_id = MyTelegramBot.ADMIN_IDTELEGRAM_SERVER;
|
||||||
|
myuser.profile.username_telegram = MyTelegramBot.ADMIN_USERNAME_TELEGRAM;
|
||||||
myuser.lasttimeonline = new Date();
|
myuser.lasttimeonline = new Date();
|
||||||
myuser.date_reg = new Date();
|
myuser.date_reg = new Date();
|
||||||
|
|
||||||
await myuser.save();
|
await myuser.save();
|
||||||
|
|
||||||
|
const { MyBot } = require('../models/bot');
|
||||||
|
|
||||||
|
// Genera il Menu del BOT:
|
||||||
|
await MyBot.generateBotMenuRecords(idapp);
|
||||||
|
|
||||||
return { code: server_constants.RIS_CODE_OK, idapp };
|
return { code: server_constants.RIS_CODE_OK, idapp };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ const { Settings } = require('../models/settings');
|
|||||||
|
|
||||||
const { SendNotif } = require('../models/sendnotif');
|
const { SendNotif } = require('../models/sendnotif');
|
||||||
|
|
||||||
|
const { MyBot } = require('../models/bot');
|
||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
const shared_consts = require('../tools/shared_nodejs');
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
@@ -1409,6 +1411,11 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
} else if (mydata.dbop === 'updateSaldoAndTransato_AllAccounts') {
|
} else if (mydata.dbop === 'updateSaldoAndTransato_AllAccounts') {
|
||||||
|
|
||||||
await Account.updateSaldoAndTransato_AllAccounts(idapp);
|
await Account.updateSaldoAndTransato_AllAccounts(idapp);
|
||||||
|
} else if (mydata.dbop === 'generateBotMenuRecords') {
|
||||||
|
|
||||||
|
|
||||||
|
await MyBot.generateBotMenuRecords(idapp);
|
||||||
|
|
||||||
} else if (mydata.dbop === 'GenerateVapiKey') {
|
} else if (mydata.dbop === 'GenerateVapiKey') {
|
||||||
|
|
||||||
await tools.generateVapiKey();
|
await tools.generateVapiKey();
|
||||||
|
|||||||
@@ -695,6 +695,7 @@ const ADMIN_IDTELEGRAM_TEST = 5356627050; // 5022837609; //Surya Arena
|
|||||||
const MyTelegramBot = {
|
const MyTelegramBot = {
|
||||||
|
|
||||||
ADMIN_IDTELEGRAM_SERVER: '12429864', //Paolo
|
ADMIN_IDTELEGRAM_SERVER: '12429864', //Paolo
|
||||||
|
ADMIN_USERNAME_TELEGRAM: 'surya1977', //Paolo
|
||||||
ADMIN_USER_SERVER: 'paoloar77',
|
ADMIN_USER_SERVER: 'paoloar77',
|
||||||
ADMIN_USER_NAME_SERVER: 'Paolo',
|
ADMIN_USER_NAME_SERVER: 'Paolo',
|
||||||
|
|
||||||
@@ -710,7 +711,7 @@ const MyTelegramBot = {
|
|||||||
} else {
|
} else {
|
||||||
return appTelegram;
|
return appTelegram;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getAppTelegramTest: function () {
|
getAppTelegramTest: function () {
|
||||||
@@ -719,7 +720,7 @@ const MyTelegramBot = {
|
|||||||
} else {
|
} else {
|
||||||
return appTelegram_TEST;
|
return appTelegram_TEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
local_sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text,
|
local_sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text,
|
||||||
@@ -978,7 +979,7 @@ const MyTelegramBot = {
|
|||||||
|
|
||||||
if (send_notif && msg_notifpush) {
|
if (send_notif && msg_notifpush) {
|
||||||
// SEND PUSH NOTIFICATION
|
// SEND PUSH NOTIFICATION
|
||||||
await tools.sendNotificationToUser(userId, title, msg_notifpush, openUrl, '', tag, actions);
|
await tools.sendNotificationToUser(userId, title, msg_notifpush, openUrl, '', tag, actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3435,15 +3436,26 @@ class Telegram {
|
|||||||
rec.status = Status.NONE;
|
rec.status = Status.NONE;
|
||||||
|
|
||||||
if (!msg.from.username) {
|
if (!msg.from.username) {
|
||||||
|
// Non ha l'Username:
|
||||||
|
|
||||||
|
// Chiedi l'username sul Bot:
|
||||||
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskUsernameSulBot)) {
|
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskUsernameSulBot)) {
|
||||||
rec.status = Status.WAITFOR_USERNAME_TELEGRAM;
|
rec.status = Status.WAITFOR_USERNAME_TELEGRAM;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Ha l'Username
|
||||||
|
|
||||||
|
// Chiedi l'invitante ?
|
||||||
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
|
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
|
||||||
rec.status = Status.WAITFOR_USERNAME_INVITANTE;
|
rec.status = Status.WAITFOR_USERNAME_INVITANTE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rec.status === Status.NONE) {
|
||||||
|
// Se il Sito non chiede di autenticarsi o l'invitante, allora lo Verifico direttamente !
|
||||||
|
rec.status = Status.VERIFIED;
|
||||||
|
}
|
||||||
|
|
||||||
this.arrUsers.push(rec);
|
this.arrUsers.push(rec);
|
||||||
|
|
||||||
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
|
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
|
||||||
@@ -4065,11 +4077,16 @@ if (true) {
|
|||||||
else if (process.env.NODE_ENV === 'test')
|
else if (process.env.NODE_ENV === 'test')
|
||||||
arrTeleg = MyTelegramBot.getAppTelegramTest();
|
arrTeleg = MyTelegramBot.getAppTelegramTest();
|
||||||
|
|
||||||
|
const arrTelegFromSite = tools.getArrTelegramFromSite();
|
||||||
|
if (arrTelegFromSite.length > 0) {
|
||||||
|
arrTeleg = arrTelegFromSite;
|
||||||
|
}
|
||||||
|
|
||||||
var internetAvailable = require('internet-available');
|
var internetAvailable = require('internet-available');
|
||||||
|
|
||||||
internetAvailable().then(() => {
|
internetAvailable().then(() => {
|
||||||
// ..
|
// ..
|
||||||
console.log('TELEGRAM STARTING.... NODE_ENV:' + process.env.NODE_ENV);
|
console.log('TELEGRAM STARTING.... ' + process.env.NODE_ENV);
|
||||||
|
|
||||||
for (const idapp of arrTeleg) {
|
for (const idapp of arrTeleg) {
|
||||||
|
|
||||||
@@ -4080,7 +4097,9 @@ if (true) {
|
|||||||
// console.log('idapp', idapp, 'token', token);
|
// console.log('idapp', idapp, 'token', token);
|
||||||
|
|
||||||
if (!!token) {
|
if (!!token) {
|
||||||
console.log('*** START BOT ' + nomebot);
|
console.log('-------------------------------------');
|
||||||
|
console.log('*** STARTING BOT ' + nomebot);
|
||||||
|
console.log('-------------------------------------');
|
||||||
const bot = new TelegramBot(token, { polling: true });
|
const bot = new TelegramBot(token, { polling: true });
|
||||||
|
|
||||||
if (url === '0') {
|
if (url === '0') {
|
||||||
@@ -4095,6 +4114,7 @@ if (true) {
|
|||||||
arrTelegram.push({ idapp, cl: new Telegram(idapp, bot) });
|
arrTelegram.push({ idapp, cl: new Telegram(idapp, bot) });
|
||||||
|
|
||||||
bot.onText(/\/start/, (msg) => {
|
bot.onText(/\/start/, (msg) => {
|
||||||
|
console.log('*** BOT PARTITO CORRETTAMENTE !!! (Start Cmd)');
|
||||||
const myclTelegram = getclTelegBytoken(bot.token);
|
const myclTelegram = getclTelegBytoken(bot.token);
|
||||||
|
|
||||||
myclTelegram.start(msg);
|
myclTelegram.start(msg);
|
||||||
|
|||||||
@@ -1804,7 +1804,7 @@ module.exports = {
|
|||||||
|
|
||||||
getTelegramBotNameByIdApp: function (idapp) {
|
getTelegramBotNameByIdApp: function (idapp) {
|
||||||
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
|
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
|
||||||
if (process.env.NODE_ENV === 'test')
|
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development')
|
||||||
return (myapp) ? myapp.telegram_bot_name_test : '';
|
return (myapp) ? myapp.telegram_bot_name_test : '';
|
||||||
else
|
else
|
||||||
return (myapp) ? myapp.telegram_bot_name : '';
|
return (myapp) ? myapp.telegram_bot_name : '';
|
||||||
@@ -1823,12 +1823,30 @@ module.exports = {
|
|||||||
|
|
||||||
getTelegramKeyByIdApp: function (idapp) {
|
getTelegramKeyByIdApp: function (idapp) {
|
||||||
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
|
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
|
||||||
if (process.env.NODE_ENV === 'test')
|
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development')
|
||||||
return (myapp) ? myapp.telegram_key_test : '';
|
return (myapp) ? myapp.telegram_key_test : '';
|
||||||
else
|
else
|
||||||
return (myapp) ? myapp.telegram_key : '';
|
return (myapp) ? myapp.telegram_key : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getArrTelegramFromSite: function () {
|
||||||
|
const myapp = this.MYAPPS;
|
||||||
|
let arrteleg = []
|
||||||
|
for (const site of myapp) {
|
||||||
|
if (site.active) {
|
||||||
|
if (process.env.NODE_ENV === 'test') {
|
||||||
|
if (myapp.load_process_telegram_test)
|
||||||
|
arrteleg.push(myapp.idapp)
|
||||||
|
} else {
|
||||||
|
if (myapp.load_process_telegram)
|
||||||
|
arrteleg.push(myapp.idapp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrteleg;
|
||||||
|
},
|
||||||
|
|
||||||
getLookupPipeLine(params, proj) {
|
getLookupPipeLine(params, proj) {
|
||||||
|
|
||||||
let myquery = [
|
let myquery = [
|
||||||
@@ -4025,7 +4043,11 @@ module.exports = {
|
|||||||
if (!msg)
|
if (!msg)
|
||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
|
|
||||||
if (!!user) {
|
if (!!user) {
|
||||||
|
if (msg.includes('{host}')) {
|
||||||
|
msg = msg.replace('{host}', this.getHostByIdApp(user.idapp));
|
||||||
|
}
|
||||||
if (msg.includes('{appname}'))
|
if (msg.includes('{appname}'))
|
||||||
msg = msg.replace('{appname}', this.getNomeAppByIdApp(user.idapp));
|
msg = msg.replace('{appname}', this.getNomeAppByIdApp(user.idapp));
|
||||||
msg = msg.replace('{username}', user.username);
|
msg = msg.replace('{username}', user.username);
|
||||||
|
|||||||
Reference in New Issue
Block a user