iobroker.telegram-menu 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/admin/index_m.html +314 -0
- package/admin/js/component.js +28 -0
- package/admin/js/main.js +104 -0
- package/admin/style.css +62 -0
- package/admin/telegram-menu.png +0 -0
- package/admin/words.js +43 -0
- package/io-package.json +117 -0
- package/lib/adapter-config.d.ts +19 -0
- package/main.js +170 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 MiRo1310 <michael.roling@gmx.de>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+

|
|
2
|
+
# ioBroker.telegram-menu
|
|
3
|
+
|
|
4
|
+
[](https://www.npmjs.com/package/iobroker.telegram-menu)
|
|
5
|
+
[](https://www.npmjs.com/package/iobroker.telegram-menu)
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
[](https://nodei.co/npm/iobroker.telegram-menu/)
|
|
10
|
+
|
|
11
|
+
**Tests:** 
|
|
12
|
+
|
|
13
|
+
## telegram-menu adapter for ioBroker
|
|
14
|
+
|
|
15
|
+
Easily create Telegram Menus
|
|
16
|
+
|
|
17
|
+
## Developer manual
|
|
18
|
+
This section is intended for the developer. It can be deleted later.
|
|
19
|
+
|
|
20
|
+
### DISCLAIMER
|
|
21
|
+
|
|
22
|
+
Please make sure that you consider copyrights and trademarks when you use names or logos of a company and add a disclaimer to your README.
|
|
23
|
+
You can check other adapters for examples or ask in the developer community. Using a name or logo of a company without permission may cause legal problems for you.
|
|
24
|
+
|
|
25
|
+
### Getting started
|
|
26
|
+
|
|
27
|
+
You are almost done, only a few steps left:
|
|
28
|
+
1. Create a new repository on GitHub with the name `ioBroker.telegram-menu`
|
|
29
|
+
|
|
30
|
+
1. Push all files to the GitHub repo. The creator has already set up the local repository for you:
|
|
31
|
+
```bash
|
|
32
|
+
git push origin main
|
|
33
|
+
```
|
|
34
|
+
1. Add a new secret under https://github.com/MiRo1310/ioBroker.telegram-menu/settings/secrets. It must be named `AUTO_MERGE_TOKEN` and contain a personal access token with push access to the repository, e.g. yours. You can create a new token under https://github.com/settings/tokens.
|
|
35
|
+
|
|
36
|
+
1. Head over to [main.js](main.js) and start programming!
|
|
37
|
+
|
|
38
|
+
### Best Practices
|
|
39
|
+
We've collected some [best practices](https://github.com/ioBroker/ioBroker.repositories#development-and-coding-best-practices) regarding ioBroker development and coding in general. If you're new to ioBroker or Node.js, you should
|
|
40
|
+
check them out. If you're already experienced, you should also take a look at them - you might learn something new :)
|
|
41
|
+
|
|
42
|
+
### Scripts in `package.json`
|
|
43
|
+
Several npm scripts are predefined for your convenience. You can run them using `npm run <scriptname>`
|
|
44
|
+
| Script name | Description |
|
|
45
|
+
|-------------|-------------|
|
|
46
|
+
| `test:js` | Executes the tests you defined in `*.test.js` files. |
|
|
47
|
+
| `test:package` | Ensures your `package.json` and `io-package.json` are valid. |
|
|
48
|
+
| `test:integration` | Tests the adapter startup with an actual instance of ioBroker. |
|
|
49
|
+
| `test` | Performs a minimal test run on package files and your tests. |
|
|
50
|
+
| `check` | Performs a type-check on your code (without compiling anything). |
|
|
51
|
+
| `lint` | Runs `ESLint` to check your code for formatting errors and potential bugs. |
|
|
52
|
+
| `translate` | Translates texts in your adapter to all required languages, see [`@iobroker/adapter-dev`](https://github.com/ioBroker/adapter-dev#manage-translations) for more details. |
|
|
53
|
+
| `release` | Creates a new release, see [`@alcalzone/release-script`](https://github.com/AlCalzone/release-script#usage) for more details. |
|
|
54
|
+
|
|
55
|
+
### Writing tests
|
|
56
|
+
When done right, testing code is invaluable, because it gives you the
|
|
57
|
+
confidence to change your code while knowing exactly if and when
|
|
58
|
+
something breaks. A good read on the topic of test-driven development
|
|
59
|
+
is https://hackernoon.com/introduction-to-test-driven-development-tdd-61a13bc92d92.
|
|
60
|
+
Although writing tests before the code might seem strange at first, but it has very
|
|
61
|
+
clear upsides.
|
|
62
|
+
|
|
63
|
+
The template provides you with basic tests for the adapter startup and package files.
|
|
64
|
+
It is recommended that you add your own tests into the mix.
|
|
65
|
+
|
|
66
|
+
### Publishing the adapter
|
|
67
|
+
Using GitHub Actions, you can enable automatic releases on npm whenever you push a new git tag that matches the form
|
|
68
|
+
`v<major>.<minor>.<patch>`. We **strongly recommend** that you do. The necessary steps are described in `.github/workflows/test-and-release.yml`.
|
|
69
|
+
|
|
70
|
+
Since you installed the release script, you can create a new
|
|
71
|
+
release simply by calling:
|
|
72
|
+
```bash
|
|
73
|
+
npm run release
|
|
74
|
+
```
|
|
75
|
+
Additional command line options for the release script are explained in the
|
|
76
|
+
[release-script documentation](https://github.com/AlCalzone/release-script#command-line).
|
|
77
|
+
|
|
78
|
+
To get your adapter released in ioBroker, please refer to the documentation
|
|
79
|
+
of [ioBroker.repositories](https://github.com/ioBroker/ioBroker.repositories#requirements-for-adapter-to-get-added-to-the-latest-repository).
|
|
80
|
+
|
|
81
|
+
### Test the adapter manually with dev-server
|
|
82
|
+
Since you set up `dev-server`, you can use it to run, test and debug your adapter.
|
|
83
|
+
|
|
84
|
+
You may start `dev-server` by calling from your dev directory:
|
|
85
|
+
```bash
|
|
86
|
+
dev-server watch
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The ioBroker.admin interface will then be available at http://localhost:8081/
|
|
90
|
+
|
|
91
|
+
Please refer to the [`dev-server` documentation](https://github.com/ioBroker/dev-server#command-line) for more details.
|
|
92
|
+
|
|
93
|
+
## Changelog
|
|
94
|
+
<!--
|
|
95
|
+
Placeholder for the next version (at the beginning of the line):
|
|
96
|
+
### **WORK IN PROGRESS**
|
|
97
|
+
-->
|
|
98
|
+
|
|
99
|
+
### **WORK IN PROGRESS**
|
|
100
|
+
* (MiRo1310) initial release
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
MIT License
|
|
104
|
+
|
|
105
|
+
Copyright (c) 2023 MiRo1310 <michael.roling@gmx.de>
|
|
106
|
+
|
|
107
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
108
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
109
|
+
in the Software without restriction, including without limitation the rights
|
|
110
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
111
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
112
|
+
furnished to do so, subject to the following conditions:
|
|
113
|
+
|
|
114
|
+
The above copyright notice and this permission notice shall be included in all
|
|
115
|
+
copies or substantial portions of the Software.
|
|
116
|
+
|
|
117
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
118
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
119
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
120
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
121
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
122
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
123
|
+
SOFTWARE.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<!-- Load ioBroker scripts and styles-->
|
|
5
|
+
<link rel="stylesheet" type="text/css" href="../../css/adapter.css" />
|
|
6
|
+
<link rel="stylesheet" type="text/css" href="../../lib/css/materialize.css">
|
|
7
|
+
|
|
8
|
+
<script type="text/javascript" src="../../lib/js/jquery-3.2.1.min.js"></script>
|
|
9
|
+
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
|
|
10
|
+
<script type="text/javascript" src="./js/main.js"></script>
|
|
11
|
+
<script type="text/javascript" src="./js/component.js"></script>
|
|
12
|
+
|
|
13
|
+
<script type="text/javascript" src="../../js/translate.js"></script>
|
|
14
|
+
<script type="text/javascript" src="../../lib/js/materialize.js"></script>
|
|
15
|
+
<script type="text/javascript" src="../../js/adapter-settings.js"></script>
|
|
16
|
+
|
|
17
|
+
<!-- Load our own files -->
|
|
18
|
+
<link rel="stylesheet" type="text/css" href="style.css" />
|
|
19
|
+
<script type="text/javascript" src="words.js"></script>
|
|
20
|
+
|
|
21
|
+
<script type="text/javascript">
|
|
22
|
+
let _onChange
|
|
23
|
+
let users = []
|
|
24
|
+
let activeUser;
|
|
25
|
+
// This will be called by the admin adapter when the settings page loads
|
|
26
|
+
function load(settings, onChange) {
|
|
27
|
+
// example: select elements with id=key and class=value and insert value
|
|
28
|
+
if (!settings) return;
|
|
29
|
+
_onChange = onChange
|
|
30
|
+
users = settings.users
|
|
31
|
+
activeUser = settings.users[0]
|
|
32
|
+
createUser("#user_list", settings.users)
|
|
33
|
+
fillTable("#navigation", settings.nav, newTableRow, users)
|
|
34
|
+
showHideNav(activeUser)
|
|
35
|
+
setCheckbox(settings.checkbox)
|
|
36
|
+
|
|
37
|
+
$('.value').each(function () {
|
|
38
|
+
var $key = $(this);
|
|
39
|
+
var id = $key.attr('id');
|
|
40
|
+
if ($key.attr('type') === 'checkbox') {
|
|
41
|
+
// do not call onChange direct, because onChange could expect some arguments
|
|
42
|
+
$key.prop('checked', settings[id])
|
|
43
|
+
.on('change', () => onChange())
|
|
44
|
+
;
|
|
45
|
+
} else {
|
|
46
|
+
// do not call onChange direct, because onChange could expect some arguments
|
|
47
|
+
$key.val(settings[id])
|
|
48
|
+
.on('change', () => onChange())
|
|
49
|
+
.on('keyup', () => onChange())
|
|
50
|
+
;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
onChange(false);
|
|
55
|
+
// reinitialize all the Materialize labels on the page if you are dynamically adding inputs:
|
|
56
|
+
if (M) M.updateTextFields();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// This will be called by the admin adapter when the user presses the save button
|
|
60
|
+
function save(callback) {
|
|
61
|
+
// example: select elements with class=value and build settings object
|
|
62
|
+
var obj = {};
|
|
63
|
+
obj.checkbox = []
|
|
64
|
+
$('.value').each(function () {
|
|
65
|
+
var $this = $(this);
|
|
66
|
+
if ($this.attr('type') === 'checkbox') {
|
|
67
|
+
obj[$this.attr('id')] = $this.prop('checked');
|
|
68
|
+
} else if ($this.attr('type') === 'number') {
|
|
69
|
+
obj[$this.attr('id')] = parseFloat($this.val());
|
|
70
|
+
} else if (!$this.attr("data-nosave")) {
|
|
71
|
+
obj[$this.attr('id')] = $this.val();
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
$(".valCheckbox").each(function () {
|
|
76
|
+
var $this = $(this);
|
|
77
|
+
if ($this.attr('type') === 'checkbox') {
|
|
78
|
+
obj.checkbox.push({ [$this.attr('id')]: $this.prop('checked') });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
})
|
|
82
|
+
const tableDevices = table2Values("#navigation");
|
|
83
|
+
console.log(tableDevices)
|
|
84
|
+
|
|
85
|
+
if (isStringEmty(".isString")) {
|
|
86
|
+
console.log(isStringEmty(".isString"))
|
|
87
|
+
obj.nav = tableDevices;
|
|
88
|
+
obj.users = users
|
|
89
|
+
|
|
90
|
+
console.log(obj)
|
|
91
|
+
callback(obj);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
$(function () {
|
|
98
|
+
// New User Show Button
|
|
99
|
+
$("#username").keyup(function () {
|
|
100
|
+
if ($(this).val() !== "" && users.indexOf($("#username").val()) == -1) {
|
|
101
|
+
$("#addNewUser").removeClass("disabled")
|
|
102
|
+
} else $("#addNewUser").addClass("disabled")
|
|
103
|
+
})
|
|
104
|
+
// Eventhander click add User
|
|
105
|
+
|
|
106
|
+
$("#addNewUser").click(() => {
|
|
107
|
+
let newUser = $("#username").val()
|
|
108
|
+
|
|
109
|
+
if (users.indexOf(newUser) == -1) {
|
|
110
|
+
users.push(newUser)
|
|
111
|
+
createUser("#user_list", [newUser])
|
|
112
|
+
_onChange()
|
|
113
|
+
$("#username").val("")
|
|
114
|
+
$("#addNewUser").addClass("disabled")
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
// Delete User
|
|
118
|
+
$("#user_menu").on("click", "#deleteUser", function () {
|
|
119
|
+
let userdelete = $("#user_list .active").attr("name")
|
|
120
|
+
users.splice(users.indexOf(userdelete), 1)
|
|
121
|
+
$("#user_list .active").parent().remove()
|
|
122
|
+
$(`#tabel_nav tbody[name="${userdelete}"]`)
|
|
123
|
+
$(`#${userdelete}`).remove()
|
|
124
|
+
_onChange()
|
|
125
|
+
|
|
126
|
+
})
|
|
127
|
+
// Click User, Show Navigation
|
|
128
|
+
$("#user_list").on("click", ".click_user", function () {
|
|
129
|
+
console.log("test")
|
|
130
|
+
activeUser = $(this).attr("name")
|
|
131
|
+
showHideNav(activeUser)
|
|
132
|
+
})
|
|
133
|
+
// New Row in UserNavigation
|
|
134
|
+
$("#addNewNav").click(function () {
|
|
135
|
+
$(`#${activeUser}`).append(newTableRow(activeUser, users))
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// Eventhandler for deleting row in Nav
|
|
140
|
+
$("#table_nav").on("click", ".delete", function () {
|
|
141
|
+
$(this).parent().parent().remove()
|
|
142
|
+
_onChange()
|
|
143
|
+
generateNav()
|
|
144
|
+
})
|
|
145
|
+
// Eventhandler for save change
|
|
146
|
+
|
|
147
|
+
$("#user_list").on("click", ".click-user", function () {
|
|
148
|
+
activeUser = $(this).attr("name")
|
|
149
|
+
$("#btn-nav").attr("href", `#tab-nav-user-${activeUser}`)
|
|
150
|
+
$("#btn-todo").attr("href", `#tab-todo-user-${activeUser}`)
|
|
151
|
+
$("adapter-container").load(`#tab-nav-user-${activeUser}`)
|
|
152
|
+
})
|
|
153
|
+
// update
|
|
154
|
+
$("#navigation").change(".value", function () {
|
|
155
|
+
_onChange()
|
|
156
|
+
})
|
|
157
|
+
$(".valCheckbox").change(function () {
|
|
158
|
+
_onChange()
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
})
|
|
163
|
+
function fillTable(id, data, newTableRow, users) {
|
|
164
|
+
for (const name in data) {
|
|
165
|
+
const nav = data[name].nav
|
|
166
|
+
nav.forEach(function (element, key) {
|
|
167
|
+
$(`#${name}`).append(newTableRow(name, users))
|
|
168
|
+
if (element.call) $(`#${name} tr input.nav-call`)[key].value = element.call
|
|
169
|
+
if (element.value) $(`#${name} tr input.nav-value`)[key].value = element.value
|
|
170
|
+
if (element.text) $(`#${name} tr input.nav-text`)[key].value = element.text
|
|
171
|
+
if (element.radio) $(`#${name} tr input.nav-radio:radio`)[key].checked = element.radio
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
</script>
|
|
176
|
+
|
|
177
|
+
</head>
|
|
178
|
+
|
|
179
|
+
<body>
|
|
180
|
+
<div class="m adapter-container">
|
|
181
|
+
<div class="row">
|
|
182
|
+
<div class="col s12 m4 l2">
|
|
183
|
+
<img src="telegram-menu.png" class="logo">
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
<div class="row">
|
|
187
|
+
<div class="col s12">
|
|
188
|
+
<ul class="tabs">
|
|
189
|
+
<li class="tab col s3"><a class="active" id="btn-nav" href="#tab-nav">Navigation</a></li>
|
|
190
|
+
<li class="tab col s3"><a id="btn-todo" href="#tab-todo-user-all">Action</a></li>
|
|
191
|
+
<li class="tab col s3"><a id="btn-settings" href="#tab-settings">Settings</a></li>
|
|
192
|
+
</ul>
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
<div class="row">
|
|
196
|
+
<div class="col s12">
|
|
197
|
+
<div id="popup">
|
|
198
|
+
<p>Test</p>
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
<div class="row" id="user_menu">
|
|
203
|
+
<a class="btn-add btn-floating btn-small waves-effect waves-light blue disabled " id="addNewUser"
|
|
204
|
+
title="Add new User"><i class="material-icons">add</i></a>
|
|
205
|
+
<a class="delete btn-floating btn-small waves-effect waves-light red" id="deleteUser"><i
|
|
206
|
+
class="material-icons">delete</i></a>
|
|
207
|
+
<div class="col s3">
|
|
208
|
+
<input id="username" type="text" placeholder="Add new UserName">
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
<div class="row">
|
|
212
|
+
<div class="col s12">
|
|
213
|
+
<ul class="tabs" id="user_list">
|
|
214
|
+
</ul>
|
|
215
|
+
</div>
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
<div class="row">
|
|
220
|
+
<div class="col s12">
|
|
221
|
+
<a class="btn-add btn-floating btn-small waves-effect waves-light blue" id="addNewNav"
|
|
222
|
+
title="Add new Navigation"><i class="material-icons">add</i></a>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
<div id="tab-nav" class="page">
|
|
226
|
+
<div class="row">
|
|
227
|
+
<div class="col s12">
|
|
228
|
+
<div class="table-values-div" id="navigation" class="value">
|
|
229
|
+
<table id="table_nav" class="" style="width: 100%;">
|
|
230
|
+
<thead>
|
|
231
|
+
<tr>
|
|
232
|
+
<th data-name="name" style="width: 20%; background: #64b5f6 " class="translate">Call
|
|
233
|
+
Text
|
|
234
|
+
</th>
|
|
235
|
+
<th data-name="nav" data-type="string" style="background: #64b5f6">
|
|
236
|
+
Navigation</th>
|
|
237
|
+
<th data-name="text" data-type="string" style="background: #64b5f6; width: 20%;">
|
|
238
|
+
Text</th>
|
|
239
|
+
<th data-name="startside" data-type="string"
|
|
240
|
+
style="background: #64b5f6 ; width: 5%;">
|
|
241
|
+
Startside</th>
|
|
242
|
+
<th style="background: #64b5f6; width: 5%;"></th>
|
|
243
|
+
</tr>
|
|
244
|
+
</thead>
|
|
245
|
+
<!-- <tbody id="" class="table_entry value table-lines table-values">
|
|
246
|
+
</tbody> -->
|
|
247
|
+
</table>
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
<div id="tab-todo-user-all" class="page">
|
|
254
|
+
<div class=" row">
|
|
255
|
+
<div class="col s12">
|
|
256
|
+
<table id="table_todo" class="" style="width: 100%;">
|
|
257
|
+
<thead>
|
|
258
|
+
<tr>
|
|
259
|
+
<th data-name="name" style="width: 20%; background: #64b5f6 " class="translate">Action
|
|
260
|
+
</th>
|
|
261
|
+
<th data-name="nav" data-type="string" style="background: #64b5f6">
|
|
262
|
+
Navigation</th>
|
|
263
|
+
<th data-name="text" data-type="string" style="background: #64b5f6; width: 20%;">
|
|
264
|
+
Text</th>
|
|
265
|
+
<th data-name="startside" data-type="string" style="background: #64b5f6 ; width: 5%;">
|
|
266
|
+
Startside</th>
|
|
267
|
+
<th style="background: #64b5f6; width: 5%;"></th>
|
|
268
|
+
</tr>
|
|
269
|
+
</thead>
|
|
270
|
+
</table>
|
|
271
|
+
</div>
|
|
272
|
+
</div>
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
</div>
|
|
276
|
+
|
|
277
|
+
<div id="tab-settings" class="page">
|
|
278
|
+
<div class=" row">
|
|
279
|
+
<div class="col s12">
|
|
280
|
+
<h1>Settings</h1>
|
|
281
|
+
<div class="row">
|
|
282
|
+
<div class="input-field col s2">
|
|
283
|
+
<input placeholder="," id="sepBtn" type="text" class="validate center-align value">
|
|
284
|
+
<label for="sepBtn">Separation buttons</label>
|
|
285
|
+
</div>
|
|
286
|
+
<div class="input-field col s2">
|
|
287
|
+
<input placeholder="%%" id="sepRow" type="text" class="validate center-align value">
|
|
288
|
+
<label for="sepRow">Separation Row</label>
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
<div class="row">
|
|
292
|
+
<div class="input-field col s3">
|
|
293
|
+
<label>
|
|
294
|
+
<input id="resKey" type="checkbox" class="filled-in valCheckbox" checked />
|
|
295
|
+
<span>Resize Keyboard</span>
|
|
296
|
+
</label>
|
|
297
|
+
</div>
|
|
298
|
+
<div class="input-field col s3">
|
|
299
|
+
<label>
|
|
300
|
+
<input id="oneTiKey" class="filled-in valCheckbox" type="checkbox" checked>
|
|
301
|
+
<span>One Time Keyboard</span>
|
|
302
|
+
</label>
|
|
303
|
+
|
|
304
|
+
</div>
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
</div>
|
|
309
|
+
|
|
310
|
+
</div>
|
|
311
|
+
|
|
312
|
+
</body>
|
|
313
|
+
|
|
314
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {string} activuser Active User
|
|
4
|
+
* @param {array} users List of Users
|
|
5
|
+
*/
|
|
6
|
+
function newTableRow(activuser, users) {
|
|
7
|
+
let userIndex = users.indexOf(activuser);
|
|
8
|
+
return `<tr>
|
|
9
|
+
<td><input type="text" data-name="call" class="isString nav-call "></td>
|
|
10
|
+
<td><input type="text" data-name="value" class="isString nav-value "></td>
|
|
11
|
+
<td><input type="text" data-name="text" class="isString nav-text "></td>
|
|
12
|
+
<td><p>
|
|
13
|
+
<label>
|
|
14
|
+
<input name="group${userIndex}" type="radio" class="nav-radio" />
|
|
15
|
+
<span></span>
|
|
16
|
+
</label>
|
|
17
|
+
</p></td>
|
|
18
|
+
<td style="width: 5%;"><a class="delete btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td>
|
|
19
|
+
</tr>`;
|
|
20
|
+
}
|
|
21
|
+
function newUserBtn(user) {
|
|
22
|
+
return `<li class="tab col s1 bg-nav-user"><a name="${user}" class="click_user" href="#">${user}</a></li>`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function navElement(user) {
|
|
26
|
+
return `<tbody id="${user}" data-nosave="true" class="table_entry value table-lines table-values">
|
|
27
|
+
</tbody>`;
|
|
28
|
+
}
|
package/admin/js/main.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {string} classes Class to browse for empty String
|
|
4
|
+
* @returns boolean True Everything is ok
|
|
5
|
+
*/
|
|
6
|
+
function isStringEmty(classes) {
|
|
7
|
+
let allOk;
|
|
8
|
+
$(classes).each(function (key, element) {
|
|
9
|
+
if (element.value == "") {
|
|
10
|
+
console.log(this);
|
|
11
|
+
$(element).parent().addClass("bg-error");
|
|
12
|
+
allOk = false;
|
|
13
|
+
} else {
|
|
14
|
+
$(element).parent().removeClass("bg-error");
|
|
15
|
+
allOk = true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return allOk;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function generateNav() {
|
|
22
|
+
let navigationArray = {};
|
|
23
|
+
let ids = [];
|
|
24
|
+
let nav = [];
|
|
25
|
+
$(".nav-id").each((key, element) => {
|
|
26
|
+
ids.push(element.value);
|
|
27
|
+
});
|
|
28
|
+
$(".nav-value").each((key, element) => {
|
|
29
|
+
nav.push(element.value);
|
|
30
|
+
});
|
|
31
|
+
ids.forEach((element, key) => {
|
|
32
|
+
let arrayRows = [];
|
|
33
|
+
let arrayItems = nav[key].split(":");
|
|
34
|
+
arrayItems.forEach((e) => {
|
|
35
|
+
arrayRows.push([e]);
|
|
36
|
+
});
|
|
37
|
+
let arrayNew = [];
|
|
38
|
+
arrayRows.forEach((element, k) => {
|
|
39
|
+
arrayNew.push([element[0].split(",")]);
|
|
40
|
+
});
|
|
41
|
+
navigationArray[element] = { nav: [arrayNew] };
|
|
42
|
+
return navigationArray;
|
|
43
|
+
|
|
44
|
+
// sendTo(instance, "send", navigationArray, function (result) {
|
|
45
|
+
// console.log(result)
|
|
46
|
+
// })
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {string} id Where to create
|
|
52
|
+
* @param {Array} users Array of Users
|
|
53
|
+
*/
|
|
54
|
+
function createUser(id, users) {
|
|
55
|
+
users.forEach((user) => {
|
|
56
|
+
$(id).append(newUserBtn(user));
|
|
57
|
+
createNav("#table_nav", user);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function createNav(id, user) {
|
|
61
|
+
$(id).append(navElement(user));
|
|
62
|
+
}
|
|
63
|
+
function table2Values(id) {
|
|
64
|
+
let $div = $(id);
|
|
65
|
+
let $tbodys = $div.find("tbody");
|
|
66
|
+
let object = {};
|
|
67
|
+
|
|
68
|
+
$tbodys.each(function () {
|
|
69
|
+
let nav = [];
|
|
70
|
+
let $tbody = $(this);
|
|
71
|
+
let $trs = $tbody.find("tr");
|
|
72
|
+
let user;
|
|
73
|
+
$trs.each(function () {
|
|
74
|
+
user = $tbody.attr("id");
|
|
75
|
+
let call = $(this).find("td input[data-name='call']").val();
|
|
76
|
+
let value = $(this).find("td input[data-name='value']").val();
|
|
77
|
+
let text = $(this).find("td input[data-name='text']").val();
|
|
78
|
+
let radio;
|
|
79
|
+
if ($(this).find("td input.nav-radio:radio:checked").val()) radio = true;
|
|
80
|
+
else radio = false;
|
|
81
|
+
|
|
82
|
+
nav.push({ call: call, value: value, text: text, radio: radio });
|
|
83
|
+
});
|
|
84
|
+
object[user] = { nav: nav };
|
|
85
|
+
});
|
|
86
|
+
return object;
|
|
87
|
+
}
|
|
88
|
+
function showHideNav(activeUser) {
|
|
89
|
+
$("#navigation tbody").hide();
|
|
90
|
+
$(`tbody#${activeUser}`).show();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
* @param {Array} checkbox Entrys with Checkbox Values
|
|
95
|
+
*/
|
|
96
|
+
function setCheckbox(checkbox) {
|
|
97
|
+
checkbox.forEach((element) => {
|
|
98
|
+
for (const id in element) {
|
|
99
|
+
if (element[id]) {
|
|
100
|
+
$(`#${id}`).prop("checked", true);
|
|
101
|
+
} else $(`#${id}`).prop("checked", false);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
package/admin/style.css
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* You can delete those if you want. I just found them very helpful */
|
|
2
|
+
* {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
}
|
|
5
|
+
.m {
|
|
6
|
+
/* Don't cut off dropdowns! */
|
|
7
|
+
overflow: initial;
|
|
8
|
+
}
|
|
9
|
+
.m.adapter-container,
|
|
10
|
+
.m.adapter-container > div.App {
|
|
11
|
+
/* Fix layout/scrolling issues with tabs */
|
|
12
|
+
height: 100%;
|
|
13
|
+
width: 100%;
|
|
14
|
+
position: relative;
|
|
15
|
+
}
|
|
16
|
+
.m .select-wrapper + label {
|
|
17
|
+
/* The positioning for dropdown labels is messed up */
|
|
18
|
+
transform: none !important;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
label > i[title] {
|
|
22
|
+
/* Display the help cursor for the tooltip icons and fix their positioning */
|
|
23
|
+
cursor: help;
|
|
24
|
+
margin-left: 0.25em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.dropdown-content {
|
|
28
|
+
/* Don't wrap text in dropdowns */
|
|
29
|
+
white-space: nowrap;
|
|
30
|
+
}
|
|
31
|
+
.btn-add {
|
|
32
|
+
margin-left: 20px;
|
|
33
|
+
}
|
|
34
|
+
.bg-error {
|
|
35
|
+
background-color: rgb(243, 96, 96);
|
|
36
|
+
}
|
|
37
|
+
.bg-nav-user {
|
|
38
|
+
background-color: #ddd;
|
|
39
|
+
|
|
40
|
+
margin-right: 20px !important;
|
|
41
|
+
}
|
|
42
|
+
#user_list .tab {
|
|
43
|
+
text-transform: none;
|
|
44
|
+
}
|
|
45
|
+
h1 {
|
|
46
|
+
font-size: x-large !important;
|
|
47
|
+
text-decoration: underline;
|
|
48
|
+
margin-top: 10px !important;
|
|
49
|
+
}
|
|
50
|
+
#popup {
|
|
51
|
+
background-color: bisque;
|
|
52
|
+
width: 95%;
|
|
53
|
+
height: 400px;
|
|
54
|
+
z-index: 100;
|
|
55
|
+
position: absolute;
|
|
56
|
+
left: 0;
|
|
57
|
+
right: 0;
|
|
58
|
+
margin-left: auto;
|
|
59
|
+
margin-right: auto;
|
|
60
|
+
display: none;
|
|
61
|
+
}
|
|
62
|
+
/* Add your styles here */
|
|
Binary file
|
package/admin/words.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* eslint no-unused-vars: off */
|
|
2
|
+
/* eslint no-global-assign: off */
|
|
3
|
+
/* global systemDictionary */
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
systemDictionary = {
|
|
7
|
+
"telegram-menu adapter settings": {
|
|
8
|
+
en: "Adapter settings for telegram-menu",
|
|
9
|
+
de: "Adaptereinstellungen für telegram-menu",
|
|
10
|
+
ru: "Настройки адаптера для telegram-menu",
|
|
11
|
+
pt: "Configurações do adaptador para telegram-menu",
|
|
12
|
+
nl: "Adapterinstellingen voor telegram-menu",
|
|
13
|
+
fr: "Paramètres d'adaptateur pour telegram-menu",
|
|
14
|
+
it: "Impostazioni dell'adattatore per telegram-menu",
|
|
15
|
+
es: "Ajustes del adaptador para telegram-menu",
|
|
16
|
+
pl: "Ustawienia adaptera dla telegram-menu",
|
|
17
|
+
"zh-cn": "telegram-menu的适配器设置",
|
|
18
|
+
},
|
|
19
|
+
option1: {
|
|
20
|
+
en: "option1",
|
|
21
|
+
de: "Option 1",
|
|
22
|
+
ru: "Опция 1",
|
|
23
|
+
pt: "Opção 1",
|
|
24
|
+
nl: "Optie 1",
|
|
25
|
+
fr: "Option 1",
|
|
26
|
+
it: "opzione 1",
|
|
27
|
+
es: "Opción 1",
|
|
28
|
+
pl: "opcja 1",
|
|
29
|
+
"zh-cn": "选项1",
|
|
30
|
+
},
|
|
31
|
+
option2: {
|
|
32
|
+
en: "option2",
|
|
33
|
+
de: "Option 2",
|
|
34
|
+
ru: "вариант 2",
|
|
35
|
+
pt: "opção 2",
|
|
36
|
+
nl: "Optie 2",
|
|
37
|
+
fr: "Option 2",
|
|
38
|
+
it: "opzione 2",
|
|
39
|
+
es: "opcion 2",
|
|
40
|
+
pl: "Opcja 2",
|
|
41
|
+
"zh-cn": "选项2",
|
|
42
|
+
},
|
|
43
|
+
};
|
package/io-package.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"common": {
|
|
3
|
+
"name": "telegram-menu",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"news": {
|
|
6
|
+
"0.0.1": {
|
|
7
|
+
"en": "initial release",
|
|
8
|
+
"de": "Erstveröffentlichung",
|
|
9
|
+
"ru": "Начальная версия",
|
|
10
|
+
"pt": "lançamento inicial",
|
|
11
|
+
"nl": "Eerste uitgave",
|
|
12
|
+
"fr": "Première version",
|
|
13
|
+
"it": "Versione iniziale",
|
|
14
|
+
"es": "Versión inicial",
|
|
15
|
+
"pl": "Pierwsze wydanie",
|
|
16
|
+
"zh-cn": "首次出版"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"title": "Telegram Menu",
|
|
20
|
+
"titleLang": {
|
|
21
|
+
"en": "Telegram Menu",
|
|
22
|
+
"de": "Telegramm-Menü",
|
|
23
|
+
"ru": "Меню телеграммы",
|
|
24
|
+
"pt": "Menu Telegram",
|
|
25
|
+
"nl": "Telegram-menu",
|
|
26
|
+
"fr": "Menu Télégramme",
|
|
27
|
+
"it": "Menù telegramma",
|
|
28
|
+
"es": "Menú de telegramas",
|
|
29
|
+
"pl": "menu telegramu",
|
|
30
|
+
"zh-cn": "电报菜单"
|
|
31
|
+
},
|
|
32
|
+
"desc": {
|
|
33
|
+
"en": "Easily create Telegram Menus",
|
|
34
|
+
"de": "Erstellen Sie ganz einfach Telegrammmenüs",
|
|
35
|
+
"ru": "Легко создавать меню Telegram",
|
|
36
|
+
"pt": "Crie facilmente menus de telegrama",
|
|
37
|
+
"nl": "Maak eenvoudig Telegram-menu's",
|
|
38
|
+
"fr": "Créez facilement des menus de télégramme",
|
|
39
|
+
"it": "Crea facilmente menu di Telegram",
|
|
40
|
+
"es": "Crea fácilmente menús de Telegram",
|
|
41
|
+
"pl": "Z łatwością twórz menu telegramu",
|
|
42
|
+
"zh-cn": "轻松创建电报菜单"
|
|
43
|
+
},
|
|
44
|
+
"authors": ["MiRo1310 <michael.roling@gmx.de>"],
|
|
45
|
+
"keywords": ["iobroker", "telegram", "menu"],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"platform": "Javascript/Node.js",
|
|
48
|
+
"main": "main.js",
|
|
49
|
+
"icon": "telegram-menu.png",
|
|
50
|
+
"enabled": true,
|
|
51
|
+
"messagebox": true,
|
|
52
|
+
"extIcon": "https://raw.githubusercontent.com/MiRo1310/ioBroker.telegram-menu/main/admin/telegram-menu.png",
|
|
53
|
+
"readme": "https://github.com/MiRo1310/ioBroker.telegram-menu/blob/main/README.md",
|
|
54
|
+
"loglevel": "info",
|
|
55
|
+
"mode": "daemon",
|
|
56
|
+
"type": "messaging",
|
|
57
|
+
"compact": true,
|
|
58
|
+
"connectionType": "local",
|
|
59
|
+
"dataSource": "poll",
|
|
60
|
+
"adminUI": {
|
|
61
|
+
"config": "materialize"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": [
|
|
64
|
+
{
|
|
65
|
+
"js-controller": ">=3.3.22"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"globalDependencies": [
|
|
69
|
+
{
|
|
70
|
+
"admin": ">=5.0.0"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"native": {
|
|
75
|
+
"devices": null,
|
|
76
|
+
"table_nav": null,
|
|
77
|
+
"nav_entry": null,
|
|
78
|
+
"users": null
|
|
79
|
+
},
|
|
80
|
+
"objects": [],
|
|
81
|
+
"instanceObjects": [
|
|
82
|
+
{
|
|
83
|
+
"_id": "info",
|
|
84
|
+
"type": "channel",
|
|
85
|
+
"common": {
|
|
86
|
+
"name": "Information"
|
|
87
|
+
},
|
|
88
|
+
"native": {}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"_id": "info.connection",
|
|
92
|
+
"type": "state",
|
|
93
|
+
"common": {
|
|
94
|
+
"role": "indicator.connected",
|
|
95
|
+
"name": "Device or service connected",
|
|
96
|
+
"type": "boolean",
|
|
97
|
+
"read": true,
|
|
98
|
+
"write": false,
|
|
99
|
+
"def": false
|
|
100
|
+
},
|
|
101
|
+
"native": {}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"_id": "navigation",
|
|
105
|
+
"type": "state",
|
|
106
|
+
"common": {
|
|
107
|
+
"role": "value",
|
|
108
|
+
"name": "Navigation",
|
|
109
|
+
"type": "json",
|
|
110
|
+
"read": true,
|
|
111
|
+
"write": false,
|
|
112
|
+
"def": {}
|
|
113
|
+
},
|
|
114
|
+
"native": {}
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// This file extends the AdapterConfig type from "@types/iobroker"
|
|
2
|
+
// using the actual properties present in io-package.json
|
|
3
|
+
// in order to provide typings for adapter.config properties
|
|
4
|
+
|
|
5
|
+
import { native } from "../io-package.json";
|
|
6
|
+
|
|
7
|
+
type _AdapterConfig = typeof native;
|
|
8
|
+
|
|
9
|
+
// Augment the globally declared type ioBroker.AdapterConfig
|
|
10
|
+
declare global {
|
|
11
|
+
namespace ioBroker {
|
|
12
|
+
interface AdapterConfig extends _AdapterConfig {
|
|
13
|
+
// Do not enter anything here!
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// this is required so the above AdapterConfig is found by TypeScript / type checking
|
|
19
|
+
export {};
|
package/main.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Created with @iobroker/create-adapter v2.3.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// The adapter-core module gives you access to the core ioBroker functions
|
|
8
|
+
// you need to create an adapter
|
|
9
|
+
const utils = require("@iobroker/adapter-core");
|
|
10
|
+
|
|
11
|
+
// Load your modules here, e.g.:
|
|
12
|
+
// const fs = require("fs");
|
|
13
|
+
|
|
14
|
+
class TelegramMenu extends utils.Adapter {
|
|
15
|
+
/**
|
|
16
|
+
* @param {Partial<utils.AdapterOptions>} [options={}]
|
|
17
|
+
*/
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super({
|
|
20
|
+
...options,
|
|
21
|
+
name: "telegram-menu",
|
|
22
|
+
});
|
|
23
|
+
this.on("ready", this.onReady.bind(this));
|
|
24
|
+
this.on("stateChange", this.onStateChange.bind(this));
|
|
25
|
+
// this.on("objectChange", this.onObjectChange.bind(this));
|
|
26
|
+
this.on("message", this.onMessage.bind(this));
|
|
27
|
+
this.on("unload", this.onUnload.bind(this));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Is called when databases are connected and adapter received configuration.
|
|
32
|
+
*/
|
|
33
|
+
async onReady() {
|
|
34
|
+
// Initialize your adapter here
|
|
35
|
+
|
|
36
|
+
// Reset the connection indicator during startup
|
|
37
|
+
this.setState("info.connection", false, true);
|
|
38
|
+
|
|
39
|
+
// The adapters config (in the instance object everything under the attribute "native") is accessible via
|
|
40
|
+
// this.config:
|
|
41
|
+
// this.log.info("config option1: " + this.config.option1);
|
|
42
|
+
// this.log.info("config option 22: " + this.config.option2);
|
|
43
|
+
this.log.info("test");
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
For every state in the system there has to be also an object of type state
|
|
47
|
+
Here a simple template for a boolean variable named "testVariable"
|
|
48
|
+
Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables
|
|
49
|
+
*/
|
|
50
|
+
await this.setObjectNotExistsAsync("testVariable", {
|
|
51
|
+
type: "state",
|
|
52
|
+
common: {
|
|
53
|
+
name: "testVariable",
|
|
54
|
+
type: "boolean",
|
|
55
|
+
role: "indicator",
|
|
56
|
+
read: true,
|
|
57
|
+
write: true,
|
|
58
|
+
},
|
|
59
|
+
native: {},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above.
|
|
63
|
+
this.subscribeStates("testVariable");
|
|
64
|
+
// You can also add a subscription for multiple states. The following line watches all states starting with "lights."
|
|
65
|
+
// this.subscribeStates("lights.*");
|
|
66
|
+
// Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system:
|
|
67
|
+
// this.subscribeStates("*");
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
setState examples
|
|
71
|
+
you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd)
|
|
72
|
+
*/
|
|
73
|
+
// the variable testVariable is set to true as command (ack=false)
|
|
74
|
+
await this.setStateAsync("testVariable", true);
|
|
75
|
+
|
|
76
|
+
// same thing, but the value is flagged "ack"
|
|
77
|
+
// ack should be always set to true if the value is received from or acknowledged from the target system
|
|
78
|
+
await this.setStateAsync("testVariable", { val: true, ack: true });
|
|
79
|
+
|
|
80
|
+
// same thing, but the state is deleted after 30s (getState will return null afterwards)
|
|
81
|
+
await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 });
|
|
82
|
+
|
|
83
|
+
// examples for the checkPassword/checkGroup functions
|
|
84
|
+
let result = await this.checkPasswordAsync("admin", "iobroker");
|
|
85
|
+
this.log.info("check user admin pw iobroker: " + result);
|
|
86
|
+
|
|
87
|
+
result = await this.checkGroupAsync("admin", "admin");
|
|
88
|
+
this.log.info("check group user admin group admin: " + result);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Is called when adapter shuts down - callback has to be called under any circumstances!
|
|
93
|
+
* @param {() => void} callback
|
|
94
|
+
*/
|
|
95
|
+
onUnload(callback) {
|
|
96
|
+
try {
|
|
97
|
+
// Here you must clear all timeouts or intervals that may still be active
|
|
98
|
+
// clearTimeout(timeout1);
|
|
99
|
+
// clearTimeout(timeout2);
|
|
100
|
+
// ...
|
|
101
|
+
// clearInterval(interval1);
|
|
102
|
+
|
|
103
|
+
callback();
|
|
104
|
+
} catch (e) {
|
|
105
|
+
callback();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// If you need to react to object changes, uncomment the following block and the corresponding line in the constructor.
|
|
110
|
+
// You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`.
|
|
111
|
+
// /**
|
|
112
|
+
// * Is called if a subscribed object changes
|
|
113
|
+
// * @param {string} id
|
|
114
|
+
// * @param {ioBroker.Object | null | undefined} obj
|
|
115
|
+
// */
|
|
116
|
+
// onObjectChange(id, obj) {
|
|
117
|
+
// if (obj) {
|
|
118
|
+
// // The object was changed
|
|
119
|
+
// this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`);
|
|
120
|
+
// } else {
|
|
121
|
+
// // The object was deleted
|
|
122
|
+
// this.log.info(`object ${id} deleted`);
|
|
123
|
+
// }
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Is called if a subscribed state changes
|
|
128
|
+
* @param {string} id
|
|
129
|
+
* @param {ioBroker.State | null | undefined} state
|
|
130
|
+
*/
|
|
131
|
+
onStateChange(id, state) {
|
|
132
|
+
if (state) {
|
|
133
|
+
// The state was changed
|
|
134
|
+
this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
|
|
135
|
+
} else {
|
|
136
|
+
// The state was deleted
|
|
137
|
+
this.log.info(`state ${id} deleted`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor.
|
|
142
|
+
// /**
|
|
143
|
+
// * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ...
|
|
144
|
+
// * Using this method requires "common.messagebox" property to be set to true in io-package.json
|
|
145
|
+
// * @param {ioBroker.Message} obj
|
|
146
|
+
// */
|
|
147
|
+
onMessage(obj) {
|
|
148
|
+
this.log.debug(obj);
|
|
149
|
+
if (typeof obj === "object" && obj.message) {
|
|
150
|
+
if (obj.command === "send") {
|
|
151
|
+
// e.g. send email or pushover or whatever
|
|
152
|
+
this.log.info("send command");
|
|
153
|
+
|
|
154
|
+
// Send response in callback if required
|
|
155
|
+
if (obj.callback) this.sendTo(obj.from, obj.command, "Message received", obj.callback);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (require.main !== module) {
|
|
162
|
+
// Export the constructor in compact mode
|
|
163
|
+
/**
|
|
164
|
+
* @param {Partial<utils.AdapterOptions>} [options={}]
|
|
165
|
+
*/
|
|
166
|
+
module.exports = (options) => new TelegramMenu(options);
|
|
167
|
+
} else {
|
|
168
|
+
// otherwise start the instance directly
|
|
169
|
+
new TelegramMenu();
|
|
170
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "iobroker.telegram-menu",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Easily create Telegram Menus",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "MiRo1310",
|
|
7
|
+
"email": "michael.roling@gmx.de"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/MiRo1310/ioBroker.telegram-menu",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"iobroker",
|
|
13
|
+
"telegram",
|
|
14
|
+
"menu"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/MiRo1310/ioBroker.telegram-menu.git"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">= 16"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@iobroker/adapter-core": "^2.6.8"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@alcalzone/release-script": "^3.5.9",
|
|
28
|
+
"@alcalzone/release-script-plugin-iobroker": "^3.5.9",
|
|
29
|
+
"@alcalzone/release-script-plugin-license": "^3.5.9",
|
|
30
|
+
"@alcalzone/release-script-plugin-manual-review": "^3.5.9",
|
|
31
|
+
"@iobroker/adapter-dev": "^1.2.0",
|
|
32
|
+
"@iobroker/testing": "^4.1.0",
|
|
33
|
+
"@tsconfig/node16": "^1.0.3",
|
|
34
|
+
"@types/chai": "^4.3.4",
|
|
35
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
36
|
+
"@types/jquery": "^3.5.16",
|
|
37
|
+
"@types/mocha": "^10.0.1",
|
|
38
|
+
"@types/node": "^16.18.20",
|
|
39
|
+
"@types/proxyquire": "^1.3.28",
|
|
40
|
+
"@types/sinon": "^10.0.13",
|
|
41
|
+
"@types/sinon-chai": "^3.2.9",
|
|
42
|
+
"chai": "^4.3.7",
|
|
43
|
+
"chai-as-promised": "^7.1.1",
|
|
44
|
+
"eslint": "^8.36.0",
|
|
45
|
+
"eslint-config-prettier": "^8.8.0",
|
|
46
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
47
|
+
"mocha": "^10.2.0",
|
|
48
|
+
"prettier": "^2.8.7",
|
|
49
|
+
"proxyquire": "^2.1.3",
|
|
50
|
+
"sinon": "^15.0.2",
|
|
51
|
+
"sinon-chai": "^3.7.0",
|
|
52
|
+
"typescript": "~4.6.4"
|
|
53
|
+
},
|
|
54
|
+
"main": "main.js",
|
|
55
|
+
"files": [
|
|
56
|
+
"admin{,/!(src)/**}/!(tsconfig|tsconfig.*|.eslintrc).json",
|
|
57
|
+
"admin{,/!(src)/**}/*.{html,css,png,svg,jpg,js}",
|
|
58
|
+
"lib/",
|
|
59
|
+
"www/",
|
|
60
|
+
"io-package.json",
|
|
61
|
+
"LICENSE",
|
|
62
|
+
"main.js"
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
|
|
66
|
+
"test:package": "mocha test/package --exit",
|
|
67
|
+
"test:integration": "mocha test/integration --exit",
|
|
68
|
+
"test": "npm run test:js && npm run test:package",
|
|
69
|
+
"check": "tsc --noEmit -p tsconfig.check.json",
|
|
70
|
+
"lint": "eslint .",
|
|
71
|
+
"translate": "translate-adapter",
|
|
72
|
+
"release": "release-script"
|
|
73
|
+
},
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/MiRo1310/ioBroker.telegram-menu/issues"
|
|
76
|
+
},
|
|
77
|
+
"readmeFilename": "README.md"
|
|
78
|
+
}
|