-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
123 lines (110 loc) · 3.78 KB
/
Copy pathindex.js
File metadata and controls
123 lines (110 loc) · 3.78 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
import TelegramBot from "node-telegram-bot-api";
import "dotenv/config";
import express from "express";
const app = express();
import cors from "cors";
app.use(
cors({
origin: "*",
})
);
app.get("/", (req, res) => {
res.send("<h1>Bot is running...🤖</h1>");
});
app.listen(process.env.PORT, () => {
console.log(`Server running at port: ${process.env.PORT}`);
});
const bot = new TelegramBot(process.env.BOT_API_TOKEN, { polling: true });
if (bot) {
console.log("Bot is running...🤖");
}
const waitingForSecretMessage = {};
bot.on("text", (msg) => {
const chatId = msg.chat.id;
switch (msg.text) {
case "/start":
waitingForSecretMessage[chatId] = false;
bot.sendMessage(chatId, "Hello! ... I'm Subhranil's Bot!");
break;
case "/secretMessage":
bot.sendMessage(
chatId,
`Please send me a secret message for Master ... 😋
Or if you want to cancel sending message please click - /cancel`
);
waitingForSecretMessage[chatId] = true;
break;
case "/cancel":
if (waitingForSecretMessage[chatId]) {
waitingForSecretMessage[chatId] = false;
bot.sendMessage(
chatId,
`I cancelled sending message to Master ... 😔`
);
} else {
bot.sendMessage(
chatId,
`I don't understand that... 😔 ... But, Master surely does 🙃 ... Try sending a secret message to Master (Subhranil) 😋
Use - /secretMessage
Or - /help`
);
}
break;
case "/contact":
waitingForSecretMessage[chatId] = false;
bot.sendMessage(
chatId,
`
Linkedin - https://www.linkedin.com/in/subhranilchakraborty/
GitHub - https://github.com/subhranil002
Facebook - https://www.facebook.com/TheSubhranilChakraborty/
I Hope This Helps :)
`
);
break;
case "/help":
waitingForSecretMessage[chatId] = false;
bot.sendMessage(
chatId,
`
Hi there! Here are some activities we can do :)
Please follow the commands -
/start - to start conversation
/secretMessage - to send a secret message to Subhranil
/contact - contact details of Subhranil
/help - to get this menu
I Hope This Helps :)
`
);
break;
default:
if (waitingForSecretMessage[chatId]) {
bot.sendMessage(
process.env.ADMIN_CHAT_ID,
`New Secret Message:
${msg.text}`
)
.then(() => {
bot.sendMessage(chatId, "Sent to Master! 🎉");
waitingForSecretMessage[chatId] = false;
})
.catch((error) => {
console.error("Error sending message to admin:", error);
bot.sendMessage(
chatId,
"There was an error while sending your message. Please try again later."
);
waitingForSecretMessage[chatId] = false;
});
} else {
bot.sendMessage(
chatId,
`I don't understand that... 😔 ... But, Master surely does 🙃 ... Try sending a secret message to Master (Subhranil) 😋
Use - /secretMessage
Or - /help`
);
}
break;
}
});
export default app;