-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (44 loc) · 1.34 KB
/
app.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
const TelegramBot = require("node-telegram-bot-api");
require("dotenv").config();
const express = require("express");
const token = `${process.env.API}`;
const port = process.env.PORT;
const app = express();
// Create a bot that uses your token
const bot = new TelegramBot(token, { polling: true });
// Listen for commands
bot.onText(/\/start/, (msg) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, "Hello! Welcome to my bot.");
});
bot.onText(/\/open/, (msg) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, "Opening...");
});
bot.onText(/\/close/, (msg) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, "Closing...");
});
bot.onText(/\/clear/, (msg) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, "Clearing...");
});
bot.onText(/\/help/, (msg) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, "LOl OK.");
});
// Listen for any kind of message
bot.on("message", (msg) => {
const chatId = msg.chat.id;
// Respond to 'hello' or 'hi'
if (
msg.text.toString().toLowerCase().indexOf("hello") === 0 ||
msg.text.toString().toLowerCase().indexOf("hi") === 0 ||
msg.text.toString().toLowerCase().indexOf("hey") === 0
) {
bot.sendMessage(chatId, "Hello!, Welcome.");
}
});
app.listen(port, function listen() {
console.log(`Server is listening at http://localhost:${port}`);
});