-
Notifications
You must be signed in to change notification settings - Fork 0
/
tel.js
executable file
·117 lines (83 loc) · 2.35 KB
/
tel.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
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var L1 = new Gpio(2, 'out');
var L2 = new Gpio(3, 'out');
var L3 = new Gpio(4, 'out');
var L4 = new Gpio(17, 'out');
var F1 = new Gpio(27, 'out');
var F2 = new Gpio(22, 'out');
var F3 = new Gpio(10, 'out');
var F4 = new Gpio(9, 'out');
var TelegramBot= require('node-telegram-bot-api');
var token = '1214378525:AAF97FN3YPVQ5AfOiUGt-P5TLH876ARPyO8';
var bot = new TelegramBot(token,{polling:true});
bot.onText(/\/start/, ( msg) => {
bot.sendMessage(msg.chat.id, "what d u wanna turn on??",{
"reply_markup": {
"keyboard" : [["L1_ON","L1_OFF"],["L2_ON","L2_OFF"],["L3_ON","L3_OFF"],["L4_ON","L4_OFF"],["F1_ON","F1_OFF"],["F2_ON","F2_OFF"],["F3_ON","F3_OFF"],["F4_ON","F4_OFF"]]
}
});
});
bot.onText(/\L1_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "L1 turned ON")
L1.writeSync(1);
});
bot.onText(/\L1_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "L1 turned OFF")
L1.writeSync(0);
});
bot.onText(/\L2_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "L2 turned ON")
L2.writeSync(1);
});
bot.onText(/\L2_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "L2 turned OFF")
L2.writeSync(0);
});
bot.onText(/\L3_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "L3 turned ON")
L3.writeSync(1);
});
bot.onText(/\L3_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "L3 turned OFF")
L3.writeSync(0);
});
bot.onText(/\L4_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "L4 turned ON")
L4.writeSync(1);
});
bot.onText(/\L4_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "L4 turned OFF")
L4.writeSync(0);
});
bot.onText(/\F1_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "F1 turned ON")
F1.writeSync(1);
});
bot.onText(/\F1_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "F1 turned OFF")
F1.writeSync(0);
});
bot.onText(/\F2_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "F2 turned ON")
F2.writeSync(1);
});
bot.onText(/\F2_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "F2 turned OFF")
F2.writeSync(0);
});
bot.onText(/\F3_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "F3 turned ON")
F3.writeSync(1);
});
bot.onText(/\F3_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "F3 turned OFF")
F3.writeSync(0);
});
bot.onText(/\F4_ON/, ( msg) => {
bot.sendMessage(msg.chat.id, "F4 turned ON")
F4.writeSync(1);
});
bot.onText(/\F4_OFF/, ( msg) => {
bot.sendMessage(msg.chat.id, "F4 turned OFF")
F4.writeSync(0);
});