-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
137 lines (121 loc) · 3.31 KB
/
index.js
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
134
135
136
137
const TelegramBot = require("node-telegram-bot-api");
const express = require("express");
require("dotenv").config();
const data = require("./script");
const app = express();
const routeNumber = require('./routes/number')
const botToken = process.env.TELEGRAM_BOT_TOKEN || 'Not token';
const bot = new TelegramBot(botToken, { polling: true });
const port = process.env.PORT || 3000;
app.use(express.json());
app.get("/", (req, res) => {
res.send("hi");
});
app.use('/api/v1/details',routeNumber)
setInterval(()=>{
fetch(process.env.URL, {method:'GET'})
}, 20000)
const channelId = "-1001862686008";
async function getUserVerified(channelId, userId) {
try {
const user = await bot.getChatMember(channelId, userId);
console.log(user.status);
if (user.status == "member" || user.status == "creator") {
return true;
} else {
return false;
}
} catch (error) {
return false;
console.error("Error:", error.message);
}
}
async function joinChannel(chatId) {
const options = {
reply_markup: {
inline_keyboard: [[{ text: "Joined", callback_data: `3` }]],
},
};
await bot.sendMessage(
chatId,
"Please Join the channel first:@TalhaRiazC",
options
);
}
const commands = [
{ command: "/start", description: "Start the bot" },
// Add more commands as needed
];
bot.setMyCommands(commands);
bot.on("message", async (msg) => {
try {
console.log(msg);
if (!(await getUserVerified(channelId, msg.from.id, true)))
return joinChannel(msg.chat.id);
if (msg.text == "/delete") {
const res = await deleteUserId(msg.chat.id);
if (res) return bot.sendMessage(msg.chat.id, "Deleted id");
}
if (msg.text.startsWith("03")) {
const number = msg.text;
if (number.length > 11 || number.length < 11)
return bot.sendMessage(msg.chat.id, "Please write correct number");
let res;
try {
res = await data(number);
console.log(res);
} catch (error) {
bot.sendMessage(msg.chat.id, "Error");
return bot.sendMessage(msg.chat.id, error.message);
}
if (!res[0]) {
return bot.sendMessage(msg.chat.id, "Not found anything");
}
for (let i = 0; i < res.length; i++) {
let el = res[i];
bot.sendMessage(
msg.chat.id,
el.fullName +
"\n \n" +
el.phoneNumber +
"\n\n" +
el.cnicNumber +
"\n\n" +
el.address
);
}
}
} catch (error) {
console.log(error);
}
});
bot.onText(/\/start/, async (msg) => {
try {
const chatId = msg.chat.id;
if (!(await getUserVerified(channelId, msg.from.id, true)))
return joinChannel(msg.chat.id);
bot.sendMessage(msg.chat.id, "Send your number like this : 03...");
} catch (error) {
console.log(error);
}
});
bot.on("callback_query", async (query) => {
const chatId = query.message.chat.id;
const buttonClicked = query.data.split("_")[0];
if (!chatId) return;
if (buttonClicked == "3") {
if (await getUserVerified(channelId, chatId)) {
bot.sendMessage(chatId, "Send you number like this 03..");
}
}
});
const start = async () => {
try {
app.listen(port, () => {
console.log(`port is listening ${port}...`);
});
} catch (err) {
console.log(err);
}
};
start();