Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
04353bbba0 | |||
82cb07811c | |||
98408bed1d | |||
c206dfa424 | |||
611e101483 |
70
setup.sh
Normal file
70
setup.sh
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Überprüfen, ob Node.js installiert ist
|
||||||
|
if ! command -v node &> /dev/null; then
|
||||||
|
echo "Node.js ist nicht installiert. Installiere Node.js automatisch..."
|
||||||
|
|
||||||
|
# Automatische Installation von Node.js, abhängig vom Linux-System
|
||||||
|
if command -v apt &> /dev/null; then
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y nodejs
|
||||||
|
elif command -v yum &> /dev/null; then
|
||||||
|
sudo yum install -y nodejs
|
||||||
|
else
|
||||||
|
echo "Automatische Installation von Node.js wird nicht unterstützt. Bitte installieren Sie Node.js manuell und führen Sie das Skript erneut aus."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Überprüfen, ob npm installiert ist
|
||||||
|
if ! command -v npm &> /dev/null; then
|
||||||
|
echo "npm ist nicht installiert. Installiere npm automatisch..."
|
||||||
|
sudo apt install -y npm # Oder passen Sie dies an Ihr System an
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Laden Sie die Umgebungsvariablen aus der .env-Datei
|
||||||
|
source .env
|
||||||
|
|
||||||
|
# Erstellen Sie ein neues Node.js-Projekt mit npm init und verwenden Sie Umgebungsvariablen
|
||||||
|
echo -e "Creating a new Node.js project..."
|
||||||
|
echo -e "Project name: $PROJECT_NAME"
|
||||||
|
echo -e "Version: 1.0.0"
|
||||||
|
echo -e "Description: Node.js project"
|
||||||
|
echo -e "Entry point: support_bot.js" # Hier Dateinamen anpassen
|
||||||
|
echo -e "Test command: "
|
||||||
|
echo -e "Git repository: https://git.viper.ipv64.net/M_Viper/telegram_server_monitoring"
|
||||||
|
echo -e "Keywords: "
|
||||||
|
echo -e "Author: M_Viper"
|
||||||
|
echo -e "License: ISC"
|
||||||
|
|
||||||
|
# npm init -y sollte ohne sudo ausgeführt werden, um Probleme mit Dateiberechtigungen zu vermeiden
|
||||||
|
sudo npm init -y
|
||||||
|
|
||||||
|
# Installieren Sie die benötigten Pakete, einschließlich node-telegram-bot-api
|
||||||
|
sudo npm install
|
||||||
|
sudo npm install ping
|
||||||
|
sudo npm install node-telegram-bot-api
|
||||||
|
sudo npm install js-yaml
|
||||||
|
sudo npm install moment
|
||||||
|
sudo npm install yaml # Änderung: 'yaml' anstelle von 'yml'
|
||||||
|
sudo npm install dotenv
|
||||||
|
sudo npm install fs
|
||||||
|
sudo npm install request
|
||||||
|
sudo npm install nodemailer
|
||||||
|
sudo npm install axios
|
||||||
|
|
||||||
|
# Installieren Sie pm2, wenn es noch nicht installiert ist
|
||||||
|
if ! command -v pm2 &> /dev/null; then
|
||||||
|
sudo npm install -g pm2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Erstellen Sie ein Startskript für den Bot
|
||||||
|
echo -e "Creating start script..."
|
||||||
|
echo -e "#!/bin/bash\n\npm2 start support_bot.js" > start_bot.sh # Hier Dateinamen anpassen
|
||||||
|
chmod +x start_bot.sh
|
||||||
|
|
||||||
|
# Erstellen Sie ein Autostart-Skript für den Bot
|
||||||
|
echo -e "Creating autostart script..."
|
||||||
|
echo -e "[Unit]\nDescription=Telegram Support Bot\n\n[Service]\nExecStart=$(pwd)/start_bot.sh\n\n[Install]\nWantedBy=default.target" > telegram_bot.service
|
||||||
|
sudo mv telegram_bot.service /etc/systemd/system/
|
||||||
|
sudo systemctl enable telegram_bot
|
3
start_bot.sh
Normal file
3
start_bot.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
pm2 start support_bot.js
|
144
support_bot.js
144
support_bot.js
@ -13,15 +13,13 @@ const emailConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const botToken = process.env.BOT_TOKEN;
|
const botToken = process.env.BOT_TOKEN;
|
||||||
const ADMIN_ID = process.env.ADMIN_ID;
|
const adminChatId = process.env.ADMIN_CHAT_ID;
|
||||||
|
|
||||||
|
const allowedAdminIds = adminChatId.split(',');
|
||||||
// Lade die erlaubten Admin-IDs aus der .env-Datei
|
|
||||||
const allowedAdminIds = ADMIN_ID.split(',');
|
|
||||||
|
|
||||||
const botInfo = {
|
const botInfo = {
|
||||||
name: 'Telegram Support Bot',
|
name: 'Telegram Support Bot',
|
||||||
version: '1.0.0',
|
version: '1.0.7',
|
||||||
author: 'M_Viper',
|
author: 'M_Viper',
|
||||||
license: 'ISC',
|
license: 'ISC',
|
||||||
};
|
};
|
||||||
@ -32,7 +30,6 @@ const ticketCreationStatus = new Map();
|
|||||||
|
|
||||||
const logoPath = path.join(__dirname, 'logo.png');
|
const logoPath = path.join(__dirname, 'logo.png');
|
||||||
|
|
||||||
|
|
||||||
function sendErrorNotification(error) {
|
function sendErrorNotification(error) {
|
||||||
try {
|
try {
|
||||||
const adminChatId = 5507179337;
|
const adminChatId = 5507179337;
|
||||||
@ -46,24 +43,40 @@ function sendErrorNotification(error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkBotStatus(msg) {
|
||||||
async function checkBotStatus(chatId) {
|
|
||||||
try {
|
try {
|
||||||
const isBotOnline = true;
|
console.log('Received message:', msg);
|
||||||
|
|
||||||
|
// Überprüfe, ob der Befehl /status ausgeführt wurde
|
||||||
|
const isStatusCommand = msg && msg.text && msg.text.toLowerCase() === '/status';
|
||||||
|
|
||||||
|
console.log('Is /status command?', isStatusCommand);
|
||||||
|
|
||||||
|
const isBotOnline = true; // Hier sollte deine Logik stehen, um den Bot-Status zu überprüfen.
|
||||||
const statusMessage = isBotOnline ? 'Der Bot ist online.' : 'Der Bot ist offline.';
|
const statusMessage = isBotOnline ? 'Der Bot ist online.' : 'Der Bot ist offline.';
|
||||||
bot.sendMessage(chatId, statusMessage);
|
|
||||||
|
if (isStatusCommand) {
|
||||||
|
bot.sendMessage(msg.chat.id, statusMessage);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fehler beim Überprüfen des Bot-Status:', error);
|
console.error('Fehler beim Überprüfen des Bot-Status:', error);
|
||||||
sendErrorNotification(error);
|
sendErrorNotification(error);
|
||||||
bot.sendMessage(chatId, 'Fehler beim Überprüfen des Bot-Status.');
|
|
||||||
|
if (msg && msg.text && msg.text.toLowerCase() === '/status') {
|
||||||
|
bot.sendMessage(msg.chat.id, 'Fehler beim Überprüfen des Bot-Status.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkWebsiteStatus(chatId) {
|
/* bot.onText(/\/status/, checkBotStatus);
|
||||||
|
|
||||||
|
async function checkWebsiteStatus() {
|
||||||
|
const adminChatId = process.env.ADMIN_CHAT_ID;
|
||||||
|
|
||||||
const websites = [
|
const websites = [
|
||||||
{
|
{
|
||||||
name: process.env.WEBSITE_1_NAME,
|
name: process.env.WEBSITE_1_NAME,
|
||||||
url: process.env.WEBSITE_1_URL,
|
url: process.env.WEBSITE_1_URL,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: process.env.WEBSITE_2_NAME,
|
name: process.env.WEBSITE_2_NAME,
|
||||||
@ -75,18 +88,23 @@ async function checkWebsiteStatus(chatId) {
|
|||||||
try {
|
try {
|
||||||
const response = await axios.get(website.url);
|
const response = await axios.get(website.url);
|
||||||
const statusMessage = `✅ <b>${website.name}</b> ist <i>online</i>.`;
|
const statusMessage = `✅ <b>${website.name}</b> ist <i>online</i>.`;
|
||||||
bot.sendMessage(chatId, statusMessage, { parse_mode: 'HTML' });
|
if (!website.online) {
|
||||||
|
website.online = true;
|
||||||
|
bot.sendMessage(adminChatId, statusMessage, { parse_mode: 'HTML' });
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Fehler beim Zugriff auf ${website.name}:`, error);
|
console.error(`Fehler beim Zugriff auf ${website.name}:`, error);
|
||||||
const errorMessage = `❌ <b>${website.name}</b> ist <i>offline</i>. Fehler: ${error.message}`;
|
const errorMessage = `❌ <b>${website.name}</b> ist <i>offline</i>. Fehler: ${error.message}`;
|
||||||
sendErrorNotification(errorMessage);
|
if (website.online !== false) {
|
||||||
bot.sendMessage(chatId, errorMessage, { parse_mode: 'HTML' });
|
website.online = false;
|
||||||
|
sendErrorNotification(errorMessage);
|
||||||
|
bot.sendMessage(adminChatId, errorMessage, { parse_mode: 'HTML' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInterval(checkWebsiteStatus, 3600000); */
|
||||||
setInterval(checkWebsiteStatus, 30000);
|
|
||||||
|
|
||||||
async function loadFromYaml(filePath) {
|
async function loadFromYaml(filePath) {
|
||||||
try {
|
try {
|
||||||
@ -132,29 +150,50 @@ async function loadFragen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendWelcomeMessage(chatId) {
|
function sendWelcomeMessage(chatId, isStatusCommand = false) {
|
||||||
const welcomeMessage = `
|
const excludedCommands = ['/status', '/info', '/help', '/menu'];
|
||||||
**Herzlich willkommen beim Support!**
|
|
||||||
|
|
||||||
Wir freuen uns, dass Sie sich für unseren Support entschieden haben. Unser vorrangiges Ziel ist es, Ihnen bestmöglich zu helfen und Ihre Anliegen so schnell wie möglich zu klären. Falls Sie Unterstützung benötigen, bieten wir Ihnen verschiedene Optionen:
|
if (!isStatusCommand && !excludedCommands.includes('/' + chatId)) {
|
||||||
|
const welcomeMessage = `
|
||||||
|
Herzlich willkommen beim Support!
|
||||||
|
|
||||||
👉 Um unser Menü anzuzeigen, tippen Sie einfach "/menu" ein.
|
Wir freuen uns, dass Sie sich für unseren Support entschieden haben. Unser vorrangiges Ziel ist es, Ihnen bestmöglich zu helfen und Ihre Anliegen so schnell wie möglich zu klären. Falls Sie Unterstützung benötigen, bieten wir Ihnen verschiedene Optionen:
|
||||||
|
|
||||||
👉 Sollte Ihre Frage nicht beantwortet werden, können Sie unkompliziert ein Ticket erstellen, um spezifische Unterstützung zu erhalten.
|
👉 Um unser Menü anzuzeigen, tippen Sie einfach "/menu" ein.
|
||||||
|
|
||||||
Für weitere Hilfe steht Ihnen unser "/help"-Befehl zur Verfügung.
|
👉 Sollte Ihre Frage nicht beantwortet werden, können Sie unkompliziert ein Ticket erstellen, um spezifische Unterstützung zu erhalten.
|
||||||
|
|
||||||
Wir sind jederzeit für Sie da und bearbeiten gerne Ihre Anfragen. Bitte teilen Sie uns so viele Details wie möglich mit, damit wir Ihnen effektiv helfen können.
|
Für weitere Hilfe steht Ihnen unser "/help"-Befehl zur Verfügung.
|
||||||
|
|
||||||
Vielen Dank für Ihr Vertrauen.
|
Wir sind jederzeit für Sie da und bearbeiten gerne Ihre Anfragen. Bitte teilen Sie uns so viele Details wie möglich mit, damit wir Ihnen effektiv helfen können.
|
||||||
|
|
||||||
Herzliche Grüße,
|
Vielen Dank für Ihr Vertrauen.
|
||||||
Das Support-Team
|
|
||||||
|
Herzliche Grüße,
|
||||||
|
Das Support-Team
|
||||||
`;
|
`;
|
||||||
|
|
||||||
bot.sendMessage(chatId, welcomeMessage, { parse_mode: 'Markdown' });
|
bot.sendMessage(chatId, welcomeMessage, { parse_mode: 'Markdown' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function handleStatusCommand(msg) {
|
||||||
|
const chatId = msg.chat.id;
|
||||||
|
const userId = msg.from.id;
|
||||||
|
|
||||||
|
if (allowedAdminIds.includes(userId.toString())) {
|
||||||
|
bot.sendMessage(chatId, 'Aktueller Bot- und Webseitenstatus wird abgerufen...');
|
||||||
|
|
||||||
|
checkBotStatus(chatId);
|
||||||
|
checkWebsiteStatus(chatId);
|
||||||
|
} else {
|
||||||
|
bot.sendMessage(chatId, 'Du hast keine Berechtigung, diesen Befehl zu verwenden.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.onText(/\/status/, handleStatusCommand);
|
||||||
|
|
||||||
async function initializeBot() {
|
async function initializeBot() {
|
||||||
try {
|
try {
|
||||||
const linksData = await loadLinks();
|
const linksData = await loadLinks();
|
||||||
@ -170,7 +209,6 @@ async function initializeBot() {
|
|||||||
bot.on('message', async (msg) => {
|
bot.on('message', async (msg) => {
|
||||||
const chatId = msg.chat.id;
|
const chatId = msg.chat.id;
|
||||||
|
|
||||||
// Überprüfe, ob die Nachricht "/help" ist, und sende die Hilfe-Nachricht
|
|
||||||
if (msg.text && msg.text.toLowerCase() === '/help') {
|
if (msg.text && msg.text.toLowerCase() === '/help') {
|
||||||
const helpMessage = `
|
const helpMessage = `
|
||||||
🤖 ${botInfo.name} - Hilfe 🤖
|
🤖 ${botInfo.name} - Hilfe 🤖
|
||||||
@ -179,8 +217,8 @@ Verfügbare Befehle:
|
|||||||
|
|
||||||
1. /menu - Zeigt das Hauptmenü an.
|
1. /menu - Zeigt das Hauptmenü an.
|
||||||
2. /help - Zeigt diese Hilfe an.
|
2. /help - Zeigt diese Hilfe an.
|
||||||
2. /info - Zeigt Informationen zum Bot an.
|
3. /info - Zeigt Informationen zum Bot an.
|
||||||
3. /status - Überprüft den aktuellen Bot- und Webseitenstatus. "Nur für Administrator"
|
|
||||||
|
|
||||||
|
|
||||||
🎫 Ticket erstellen: 🎫
|
🎫 Ticket erstellen: 🎫
|
||||||
@ -190,9 +228,9 @@ Verfügbare Befehle:
|
|||||||
👉 Zeigt Links zu verschiedenen Kategorien an.
|
👉 Zeigt Links zu verschiedenen Kategorien an.
|
||||||
|
|
||||||
❓ Fragen: ❓
|
❓ Fragen: ❓
|
||||||
👉 Zeigt häufig gestellte Fragen (FAQs) an.
|
👉 Zeigt häufig gestellte Fragen (FAQs) an.
|
||||||
|
|
||||||
👮 Team: 👮
|
👮 Team: 👮
|
||||||
👉 Zeigt Informationen zum Support-Team an.
|
👉 Zeigt Informationen zum Support-Team an.
|
||||||
|
|
||||||
‼️ Hinweis: Weitere Funktionen werden folgen ‼️
|
‼️ Hinweis: Weitere Funktionen werden folgen ‼️
|
||||||
@ -206,44 +244,27 @@ Verfügbare Befehle:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Überprüfe, ob es sich um den Befehl /menu handelt
|
|
||||||
if (msg.text === '/menu') {
|
if (msg.text === '/menu') {
|
||||||
handleMainMenu(msg, chatId, linksData, fragenData);
|
handleMainMenu(msg, chatId, linksData, fragenData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Überprüfe, ob es sich um den Befehl /info handelt
|
|
||||||
if (msg.text && msg.text.toLowerCase() === '/info') {
|
if (msg.text && msg.text.toLowerCase() === '/info') {
|
||||||
// Code für den Befehl /info
|
// Code für den Befehl /info
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Überprüfe, ob sich der Benutzer im Ticketerstellungsstatus befindet
|
if (msg.text && msg.text.toLowerCase() === '/status') {
|
||||||
|
// Code für den Befehl /status
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ticketCreationStatus.has(chatId)) {
|
if (ticketCreationStatus.has(chatId)) {
|
||||||
handleTicketCreation(msg, chatId, linksData);
|
handleTicketCreation(msg, chatId, linksData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn keiner der speziellen Befehle erkannt wurde, sende die Willkommensnachricht
|
|
||||||
sendWelcomeMessage(chatId);
|
sendWelcomeMessage(chatId);
|
||||||
|
|
||||||
bot.onText(/\/status/, (msg) => {
|
|
||||||
const chatId = msg.chat.id;
|
|
||||||
const userId = msg.from.id;
|
|
||||||
|
|
||||||
// Prüfe, ob der Benutzer die Berechtigung hat, den /status-Befehl zu verwenden
|
|
||||||
if (allowedAdminIds.includes(userId.toString())) {
|
|
||||||
// Führe die Logik für den /status-Befehl aus
|
|
||||||
bot.sendMessage(chatId, 'Aktueller Bot- und Webseitenstatus wird abgerufen...');
|
|
||||||
|
|
||||||
// Hier kannst du die Logik für den Statusbefehl implementieren
|
|
||||||
// Z.B., rufe Funktionen auf, um den aktuellen Bot- und Webseitenstatus zu überprüfen
|
|
||||||
checkBotStatus(chatId);
|
|
||||||
checkWebsiteStatus(chatId);
|
|
||||||
} else {
|
|
||||||
bot.sendMessage(chatId, 'Du hast keine Berechtigung, diesen Befehl zu verwenden.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('callback_query', (callbackQuery) => {
|
bot.on('callback_query', (callbackQuery) => {
|
||||||
@ -276,7 +297,7 @@ Verfügbare Befehle:
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.startPolling();
|
|
||||||
|
|
||||||
console.log(`
|
console.log(`
|
||||||
*Bot Information:*
|
*Bot Information:*
|
||||||
@ -288,7 +309,6 @@ Verfügbare Befehle:
|
|||||||
`);
|
`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fehler beim Initialisieren des Bots:', error);
|
console.error('Fehler beim Initialisieren des Bots:', error);
|
||||||
|
|
||||||
sendErrorNotification(error);
|
sendErrorNotification(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,13 +317,13 @@ function showBotInfo(chatId) {
|
|||||||
bot.sendPhoto(chatId, logoPath, { caption: '*Der Bot wurde am 08.01.2024 erstellt*' })
|
bot.sendPhoto(chatId, logoPath, { caption: '*Der Bot wurde am 08.01.2024 erstellt*' })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const botInfoMessage = `
|
const botInfoMessage = `
|
||||||
🤖Bot Information:🤖
|
🤖Bot Information:
|
||||||
- *Name:* ${escapeMarkdown(botInfo.name)}
|
- *Name:* ${escapeMarkdown(botInfo.name)}
|
||||||
- *Author:* ${escapeMarkdown(botInfo.author)}
|
- *Author:* ${escapeMarkdown(botInfo.author)}
|
||||||
- *License:* ${escapeMarkdown(botInfo.license)}
|
- *License:* ${escapeMarkdown(botInfo.license)}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
return bot.sendMessage(chatId, botInfoMessage, { parse_mode: 'Markdown' });
|
bot.sendMessage(chatId, botInfoMessage, { parse_mode: 'Markdown' });
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Bot-Informationen erfolgreich gesendet.');
|
console.log('Bot-Informationen erfolgreich gesendet.');
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
"profil": "https://example.com"
|
"profil": "https://example.com"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Florian",
|
"name": "Name",
|
||||||
"position": "Moderator",
|
"position": "Moderator",
|
||||||
"zustaendig": "Support ",
|
"zustaendig": "Support ",
|
||||||
"profil": "https://example.com"
|
"profil": "https://example.com"
|
||||||
|
Reference in New Issue
Block a user