forked from AutoFTbot/Qris-OrderKuota
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkodebot.js
More file actions
133 lines (123 loc) · 5.09 KB
/
Copy pathkodebot.js
File metadata and controls
133 lines (123 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const TelegramBot = require('node-telegram-bot-api');
const { processApiRequest } = require('./lib/orderkuota-logic');
const TELEGRAM_TOKEN = '#';
const bot = new TelegramBot(TELEGRAM_TOKEN, { polling: true });
const userStates = {};
async function deleteLastBotMessage(chatId) {
const state = userStates[chatId];
if (state && state.lastBotMessageId) {
try {
await bot.deleteMessage(chatId, state.lastBotMessageId);
} catch (e) {
}
state.lastBotMessageId = null;
}
}
bot.onText(/\/start/, async (msg) => {
await deleteLastBotMessage(msg.chat.id);
const sent = await bot.sendMessage(
msg.chat.id,
'Selamat datang di OrderKuota Bot!\nKetik /otp untuk login OrderKuota.\n\n*Privasi Anda aman!* Semua proses dan data yang Anda kirim _tidak disimpan di database manapun_. Hanya Anda dan bot yang tahu data yang dikirimkan.',
{ parse_mode: 'Markdown' }
);
userStates[msg.chat.id] = { lastBotMessageId: sent.message_id };
});
bot.onText(/\/otp/, async (msg) => {
await deleteLastBotMessage(msg.chat.id);
userStates[msg.chat.id] = { step: 'awaiting_username' };
const sent = await bot.sendMessage(msg.chat.id, 'Masukkan username OrderKuota Anda untuk request OTP:');
userStates[msg.chat.id].lastBotMessageId = sent.message_id;
});
bot.onText(/\/verify/, async (msg) => {
await deleteLastBotMessage(msg.chat.id);
userStates[msg.chat.id] = { step: 'verify_awaiting_username' };
const sent = await bot.sendMessage(msg.chat.id, 'Masukkan username OrderKuota Anda untuk verifikasi OTP:');
userStates[msg.chat.id].lastBotMessageId = sent.message_id;
});
bot.on('message', async (msg) => {
const chatId = msg.chat.id;
const state = userStates[chatId];
if (!state) return;
// OTP flow
if (state.step === 'awaiting_username' && !msg.text.startsWith('/')) {
state.username = msg.text.trim();
state.step = 'awaiting_password';
await deleteLastBotMessage(chatId);
const sent = await bot.sendMessage(chatId, 'Masukkan password OrderKuota Anda:');
state.lastBotMessageId = sent.message_id;
return;
}
if (state.step === 'awaiting_password' && !msg.text.startsWith('/')) {
state.password = msg.text.trim();
state.step = 'processing_otp';
await deleteLastBotMessage(chatId);
const sentReq = await bot.sendMessage(chatId, 'Meminta OTP...');
state.lastBotMessageId = sentReq.message_id;
try {
const result = await processApiRequest({
action: 'request_otp',
username: state.username,
password: state.password
});
if (result && result.success === false) {
await deleteLastBotMessage(chatId);
const sent = await bot.sendMessage(chatId, `❌ *Gagal request OTP!*
_${result.message || 'Terjadi kesalahan.'}_`, { parse_mode: 'Markdown' });
state.lastBotMessageId = sent.message_id;
delete userStates[chatId];
return;
}
await deleteLastBotMessage(chatId);
const sent = await bot.sendMessage(chatId, `✅ *OTP berhasil dikirim!*
Silakan cek email/nomor Anda dan masukkan kode OTP di bawah ini.\n\n_Respon server:_ \`${JSON.stringify(result)}\``, { parse_mode: 'Markdown' });
state.lastBotMessageId = sent.message_id;
state.step = 'verify_awaiting_otp';
const sentOtp = await bot.sendMessage(chatId, 'Masukkan kode OTP yang Anda terima:');
state.lastBotMessageId = sentOtp.message_id;
} catch (err) {
await deleteLastBotMessage(chatId);
const sent = await bot.sendMessage(chatId, `❌ *Gagal request OTP!*
_${err.message}_`, { parse_mode: 'Markdown' });
state.lastBotMessageId = sent.message_id;
delete userStates[chatId];
}
return;
}
if (state.step === 'verify_awaiting_otp' && !msg.text.startsWith('/')) {
state.otp = msg.text.trim();
state.step = 'processing_verify';
await deleteLastBotMessage(chatId);
const sentVer = await bot.sendMessage(chatId, '🔄 Memverifikasi OTP...');
state.lastBotMessageId = sentVer.message_id;
try {
const result = await processApiRequest({
action: 'verify_otp',
username: state.username,
otp: state.otp
});
if (result && result.success === false) {
await deleteLastBotMessage(chatId);
const sent = await bot.sendMessage(chatId, `❌ *Gagal verifikasi OTP!*
_${result.message || 'Terjadi kesalahan.'}_`, { parse_mode: 'Markdown' });
state.lastBotMessageId = sent.message_id;
delete userStates[chatId];
return;
}
await deleteLastBotMessage(chatId);
const token = result?.results?.token || '-';
const sent = await bot.sendMessage(chatId, `🎉 *Verifikasi Berhasil!*
Berikut token Anda (jaga kerahasiaannya):
\`${token}\`
\n_Respon server:_ \`${JSON.stringify(result)}\``, { parse_mode: 'Markdown' });
state.lastBotMessageId = sent.message_id;
} catch (err) {
await deleteLastBotMessage(chatId);
const sent = await bot.sendMessage(chatId, `❌ *Gagal verifikasi OTP!*
_${err.message}_`, { parse_mode: 'Markdown' });
state.lastBotMessageId = sent.message_id;
}
delete userStates[chatId];
return;
}
});