iobroker.telegram-menu
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,3 @@ | ||
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "e" }]*/ | ||
/** | ||
@@ -6,24 +8,168 @@ * | ||
*/ | ||
function newTableRow(activuser, users) { | ||
let userIndex = users.indexOf(activuser); | ||
return `<tr> | ||
function newTableRow_Nav(activuser, users) { | ||
const userIndex = users.indexOf(activuser); | ||
return /*html*/ `<tr> | ||
<td><input type="text" data-name="call" class="isString nav-call "></td> | ||
<td><input type="text" data-name="value" class="isString nav-value "></td> | ||
<td><input type="text" data-name="text" class="isString nav-text "></td> | ||
<td><p> | ||
<label> | ||
<input name="group${userIndex}" type="radio" class="nav-radio" /> | ||
<span></span> | ||
</label> | ||
</p></td> | ||
<td style="width: 5%;"><a class="delete btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td> | ||
<td><input type="text" data-name="text" class="isString nav-text "></td> | ||
<td style="width: 5%;"><a class="deleteRow btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td> | ||
</tr>`; | ||
} | ||
/** | ||
* | ||
* @param {string} user User Name | ||
* @returns HTML Element | ||
*/ | ||
function newUserBtn(user) { | ||
return `<li class="tab col s1 bg-nav-user"><a name="${user}" class="click_user" href="#">${user}</a></li>`; | ||
return /*html*/ `<li class="tab col s2 bg-nav-user"><a name="${user}" class="click_user" href="#">${user}</a></li>`; | ||
} | ||
/** | ||
* | ||
* @param {string} user User Name | ||
* @returns HTML Element | ||
*/ | ||
function navElement(user) { | ||
return `<tbody id="${user}" data-nosave="true" class="table_entry value table-lines table-values"> | ||
return /*html*/ `<tbody id="${user}"name="${user}" data-name="nav" data-nosave="true" class="user_${user} table_switch_user table_entry value table-lines table-values" style="display:none"> | ||
<tr class="startRow"> | ||
<td><input type="text" data-name="call" class="isString nav-call translateV startside" value="Startside" ></td> | ||
<td><input type="text" data-name="value" class="isString nav-value " value="Licht, Steckdose && Iobroker, Heizung"></td> | ||
<td><input type="text" data-name="text" class="isString nav-text" value="Wählen Sie eine Aktion"></td> | ||
<td style="width: 5%;"></td> | ||
</tr> | ||
</tbody>`; | ||
} | ||
function createSelectTrigger(list) { | ||
let element = '<option value="" disabled selected>Choose a trigger</option>'; | ||
list.forEach(function (e) { | ||
const dynamicChild = `<option value="${e}" >${e}</option>`; | ||
element += dynamicChild; | ||
}); | ||
return element; | ||
} | ||
// Row in Action Popup | ||
function newTrInAction(val, array) { | ||
if (!array) { | ||
array = ["", "", "checked", "", ""]; | ||
} | ||
if (val === "get") | ||
return /*html*/ `<tr class="onResetDelete"> | ||
<td> <input class="get_id checkValue" value="${array[0]}" type="text"> | ||
</td> | ||
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_getID" | ||
title="Get ID"><i class="material-icons">edit</i></a></td> | ||
<td> | ||
<input class="get_text checkValue" type="text" value="${array[1]}"> | ||
</td> | ||
<td><label> | ||
<input type="checkbox" class="filled-in newline_checkbox" ${array[2]} /> | ||
<span></span> | ||
</label></td> | ||
<td><a class="deleteRow btn-floating btn-small waves-effect waves-light red" ><i | ||
class="material-icons">delete</i></a></td> | ||
</td> | ||
</tr>`; | ||
if (val === "set") | ||
return /*html*/ `<tr class="onResetDelete"> | ||
<td> <input class="set_id checkValue" type="text" value="${array[0]}"> | ||
</td> | ||
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_getID" | ||
title="Get ID"><i class="material-icons">edit</i></a></td> | ||
<td> | ||
<input class="set_value checkValue" type="text" value="${array[3]}"> | ||
</td> | ||
<td><label> | ||
<input type="checkbox" class="filled-in switch_checkbox" ${array[4]}/> | ||
<span></span> | ||
</label></td> | ||
<td><a class="deleteRow btn-floating btn-small waves-effect waves-light red"><i | ||
class="material-icons">delete</i></a></td> | ||
</td> | ||
</tr>`; | ||
} | ||
function actionElement(user) { | ||
return /*html*/ `<div class="row user_${user} saveTable"> | ||
<div class="col s12"> | ||
<div > | ||
<p class="showHideMenu" style="width: 100%; background: #64b5f6"><i class="material-icons">chevron_right</i>GetState</p> | ||
<table style="display: none;" class="text-small"> | ||
<thead> | ||
<tr> | ||
<th style="width: 10%">Trigger</th> | ||
<th data-name="id" data-type="string" style="width: 25%;"> | ||
ID</th> | ||
<th data-name="value" data-type="string" > | ||
Text</th> | ||
<th data-name="edit" style="width: 2%;">Newline | ||
</th> | ||
<th style="width: 2%"></th> | ||
<th data-name="delete" style="width: 2%;"> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody name=${user} data-name="get" class="table_get table-lines table-values"> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div > | ||
<p class="showHideMenu" style="width: 100%; background: #64b5f6"><i class="material-icons">chevron_right</i>SetState</p> | ||
<table style="display: none;" class="text-small"> | ||
<thead> | ||
<tr> | ||
<th data-name="trigger" style="width: 10%">Trigger</th> | ||
<th data-name="id" data-type="string" style="width: 25%;"> | ||
ID</th> | ||
<th data-name="value" data-type="string" > | ||
Value</th> | ||
<th data-name="switch" data-type="string" style="width: 2%;"> | ||
Switch</th> | ||
<th data-name="edit" style="width: 2%;"> | ||
</th> | ||
<th data-name="delete" style="width: 2%;"> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody name=${user} data-name="set" class="table_set table-lines table-values"> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div>`; | ||
} | ||
function newTableRow_Action(action, result) { | ||
if (action === "get") { | ||
return /*html*/ `<tr> | ||
<td data-name="trigger">${result.trigger}</td> | ||
<td>${insertVal(result, "IDs")}</td> | ||
<td>${insertVal(result, "text")}</td> | ||
<td>${insertVal(result, "checkboxes")}</td> | ||
${actionDeleteButton} | ||
${editButton} | ||
</tr>`; | ||
} | ||
if (action === "set") | ||
return /*html*/ `<tr> | ||
<td data-name="trigger">${result.trigger}</td> | ||
<td>${insertVal(result, "IDs")}</td> | ||
<td>${insertVal(result, "values")}</td> | ||
<td>${insertVal(result, "checkboxes")}</td> | ||
${actionDeleteButton} | ||
${editButton} | ||
</tr>`; | ||
} | ||
const actionDeleteButton = `<td><a class="deleteEveryRow btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td>`; | ||
const editButton = `<td><a data-target="tab_action" class="editEntry modal-trigger btn-floating btn-small waves-effect waves-light green"><i class="material-icons">edit</i></a></td>`; | ||
function insertVal(result, entry) { | ||
let newEntry = ""; | ||
result[entry].forEach(function (element) { | ||
newEntry += /*html*/ `<p data-name=${entry}> ${element}</p>`; | ||
}); | ||
return newEntry; | ||
} |
@@ -0,1 +1,3 @@ | ||
/*global newUserBtn,navElement ,actionElement,createSelectTrigger,newTableRow_Action,newTableRow_Action,newTrInAction, $*/ | ||
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "isStringEmty|generate|create|set|fill|reset|add|show|ins|table"}]*/ | ||
/** | ||
@@ -7,6 +9,5 @@ * | ||
function isStringEmty(classes) { | ||
let allOk; | ||
let allOk = true; | ||
$(classes).each(function (key, element) { | ||
if (element.value == "") { | ||
console.log(this); | ||
$(element).parent().addClass("bg-error"); | ||
@@ -16,3 +17,2 @@ allOk = false; | ||
$(element).parent().removeClass("bg-error"); | ||
allOk = true; | ||
} | ||
@@ -24,5 +24,5 @@ }); | ||
function generateNav() { | ||
let navigationArray = {}; | ||
let ids = []; | ||
let nav = []; | ||
const navigationArray = {}; | ||
const ids = []; | ||
const nav = []; | ||
$(".nav-id").each((key, element) => { | ||
@@ -35,9 +35,9 @@ ids.push(element.value); | ||
ids.forEach((element, key) => { | ||
let arrayRows = []; | ||
let arrayItems = nav[key].split(":"); | ||
const arrayRows = []; | ||
const arrayItems = nav[key].split(":"); | ||
arrayItems.forEach((e) => { | ||
arrayRows.push([e]); | ||
}); | ||
let arrayNew = []; | ||
arrayRows.forEach((element, k) => { | ||
const arrayNew = []; | ||
arrayRows.forEach((element) => { | ||
arrayNew.push([element[0].split(",")]); | ||
@@ -47,8 +47,5 @@ }); | ||
return navigationArray; | ||
// sendTo(instance, "send", navigationArray, function (result) { | ||
// console.log(result) | ||
// }) | ||
}); | ||
} | ||
/** | ||
@@ -62,37 +59,88 @@ * | ||
$(id).append(newUserBtn(user)); | ||
createNav("#table_nav", user); | ||
$("#table_nav").append(navElement(user)); | ||
$("#tab-action").append(actionElement(user)); | ||
}); | ||
} | ||
function createNav(id, user) { | ||
$(id).append(navElement(user)); | ||
} | ||
function table2Values(id) { | ||
let $div = $(id); | ||
let $tbodys = $div.find("tbody"); | ||
let object = {}; | ||
const $tbodys = $(id).find("tbody"); | ||
const object = { | ||
nav: {}, | ||
action: {}, | ||
}; | ||
// console.log("Anzahl Tables " + $tbodys.length); | ||
let i = 0; | ||
$tbodys.each(function () { | ||
const nav = []; | ||
let actionSet, actionGet; | ||
const $tbody = $(this); | ||
$tbodys.each(function () { | ||
let nav = []; | ||
let $tbody = $(this); | ||
let $trs = $tbody.find("tr"); | ||
let user; | ||
const $trs = $tbody.find("tr"); | ||
const saveName = $tbody.attr("name"); | ||
if (i == 0) { | ||
object.action[saveName] = { set: [], get: [] }; | ||
} | ||
i++; | ||
$trs.each(function () { | ||
user = $tbody.attr("id"); | ||
let call = $(this).find("td input[data-name='call']").val(); | ||
let value = $(this).find("td input[data-name='value']").val(); | ||
let text = $(this).find("td input[data-name='text']").val(); | ||
let radio; | ||
if ($(this).find("td input.nav-radio:radio:checked").val()) radio = true; | ||
else radio = false; | ||
const dataName = $tbody.attr("data-name"); | ||
if (dataName === "nav") { | ||
nav.push({ | ||
call: $(this).find("td input[data-name='call']").val(), | ||
value: $(this).find("td input[data-name='value']").val(), | ||
text: $(this).find("td input[data-name='text']").val(), | ||
// radio: $(this).find("td input.nav-radio").is(":checked"), | ||
}); | ||
object.nav[saveName] = nav; | ||
} | ||
nav.push({ call: call, value: value, text: text, radio: radio }); | ||
if (dataName === "set") { | ||
actionSet = { | ||
IDs: dataToArray(this, "p[data-name='IDs']"), | ||
checkboxes: dataToArray(this, "p[data-name='checkboxes']"), | ||
trigger: dataToArray(this, "td[data-name='trigger']"), | ||
values: dataToArray(this, "p[data-name='values']"), | ||
}; | ||
} | ||
if (dataName === "get") { | ||
actionGet = { | ||
IDs: dataToArray(this, "p[data-name='IDs']"), | ||
checkboxes: dataToArray(this, "p[data-name='checkboxes']"), | ||
trigger: dataToArray(this, "td[data-name='trigger']"), | ||
text: dataToArray(this, "p[data-name='text']"), | ||
}; | ||
} | ||
if (actionSet) { | ||
object.action[saveName].set.push(actionSet); | ||
} | ||
if (actionGet) { | ||
object.action[saveName].get.push(actionGet); | ||
} | ||
}); | ||
object[user] = { nav: nav }; | ||
}); | ||
return object; | ||
} | ||
function showHideNav(activeUser) { | ||
$("#navigation tbody").hide(); | ||
$(`tbody#${activeUser}`).show(); | ||
/** | ||
* | ||
* @param {*} _this | ||
* @param {string} selector | ||
* @returns | ||
*/ | ||
function dataToArray(_this, selector) { | ||
const val = []; | ||
$(_this) | ||
.find(selector) | ||
.each(function () { | ||
val.push($(this).html().trim()); | ||
}); | ||
return val; | ||
} | ||
function showHideUserEntry(activeUser) { | ||
$("tbody.table_switch_user").hide(); | ||
$("#tab-action>div").hide(); | ||
$(`tbody.table_switch_user.user_${activeUser}`).show(); | ||
$(`#tab-action>div.user_${activeUser}`).show(); | ||
} | ||
/** | ||
@@ -111,1 +159,184 @@ * | ||
} | ||
function splitTextInArray(activeUser) { | ||
const value_list = []; | ||
$(`#${activeUser} input[data-name="value"]`).each(function () { | ||
let value = $(this).val(); | ||
if (typeof value == "string") { | ||
value = value.replace(/&&/g, ","); | ||
const array = value.split(","); | ||
array.forEach((element) => { | ||
value_list.push(element.trim()); | ||
}); | ||
} | ||
}); | ||
return value_list; | ||
} | ||
function generateSelectTrigger(activeUser) { | ||
const list = splitTextInArray(activeUser); | ||
// HTML Elemente löschen und neu aufbauen | ||
$("#select_trigger").empty().append(createSelectTrigger(list)); | ||
} | ||
function fillTable(id, data, newTableRow_Nav, users) { | ||
if (data) { | ||
for (const name in data) { | ||
const nav = data[name]; | ||
nav.forEach(function (element, key) { | ||
// Erst bei Key 1 starten, da eine Row statisch ist | ||
if (key != 0) $(`#${name}`).append(newTableRow_Nav(name, users)); | ||
if (element.call) $(`#${name} tr input.nav-call`)[key].value = element.call; | ||
if (element.value) $(`#${name} tr input.nav-value`)[key].value = element.value; | ||
if (element.text) $(`#${name} tr input.nav-text`)[key].value = element.text; | ||
if (element.radio) $(`#${name} tr input.nav-radio:radio`)[key].checked = element.radio; | ||
}); | ||
} | ||
} | ||
} | ||
function fillTableAction(data) { | ||
if (data) { | ||
for (const name in data) { | ||
for (const todo in data[name]) { | ||
data[name][todo].forEach(function (element) { | ||
generatActionRow(name, todo, element); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
function generatActionRow(user, action, result, rowToUpdate) { | ||
if (rowToUpdate) { | ||
$(rowToUpdate).empty().html(newTableRow_Action(action, result)?.replace("<tr>", "").replace("</tr>", "")); | ||
} else $(`.user_${user} .table_${action}`).append(newTableRow_Action(action, result)); | ||
} | ||
function resetModal() { | ||
$(".reset").each(function () { | ||
$(this).val(""); | ||
$(this).select(); | ||
}); | ||
$(".resetInput").each(function () { | ||
$(this).val(""); | ||
}); | ||
$(".resetHide").each(function () { | ||
$(this).hide(); | ||
}); | ||
$(".onResetDelete").each(function () { | ||
$(this).remove(); | ||
}); | ||
} | ||
/** | ||
* Show and Hide Select Button in Modal | ||
* @param {boolean} showTrigger | ||
* @param {boolean} show | ||
*/ | ||
function showSelectModal(showTrigger, show) { | ||
if (show && showTrigger) $("#btn_action_set").removeAttr("disabled"); | ||
else $("#btn_action_set").attr("disabled", "disabled"); | ||
} | ||
function insertEditValues(action, $this) { | ||
const IDs = valuesToArray($this, "p[data-name='IDs']"); | ||
let newline, switchs, values, texts; | ||
if (action == "set") { | ||
switchs = valuesToArray($this, "p[data-name='checkboxes']"); | ||
values = valuesToArray($this, "p[data-name='values']"); | ||
} | ||
if (action == "get") { | ||
newline = valuesToArray($this, "p[data-name='checkboxes']"); | ||
texts = valuesToArray($this, "p[data-name='text']"); | ||
} | ||
IDs.forEach(function (element, key) { | ||
if (key == 0) { | ||
$(`#tab_${action} tbody input.set_id`).val(IDs[0].trim()); | ||
$(`#tab_${action} tbody input.get_id`).val(IDs[0].trim()); | ||
if (values) $(`#tab_${action} tbody input.set_value`).val(values[0].trim()); | ||
if (texts) $(`#tab_${action} tbody input.get_text`).val(texts[0].trim()); | ||
if (switchs && switchs[0].trim() == "true") { | ||
$(`#tab_${action} tbody input.switch_checkbox`).attr("checked", "checked"); | ||
} else $(`#tab_${action} tbody input.switch_checkbox`).removeAttr("checked"); | ||
if (newline && newline[0].trim() == "true") | ||
$(`#tab_${action} tbody input.newline_checkbox`).attr("checked", "checked"); | ||
else $(`#tab_${action} tbody input.newline_checkbox`).removeAttr("checked"); | ||
} else { | ||
let _newline = "", | ||
_switch = "", | ||
_values = "", | ||
_texts = ""; | ||
if (newline && newline[key].trim() == "true") _newline = "checked"; | ||
if (switchs && switchs[key].trim() == "true") _switch = "checked"; | ||
if (values) _values = values[key].trim(); | ||
if (texts) _texts = texts[key].trim(); | ||
const array = [IDs[key].trim(), _texts, _newline, _values, _switch]; | ||
$(`#tab_${$("#select_action").val()} tbody`).append(newTrInAction($("#select_action").val(), array)); | ||
} | ||
}); | ||
} | ||
function valuesToArray($this, selector) { | ||
const val = []; | ||
$($this) | ||
.parent() | ||
.siblings() | ||
.find(selector) | ||
.each(function () { | ||
val.push($(this).html()); | ||
}); | ||
return val; | ||
} | ||
function showAddGlobalUser(users) { | ||
if (users.indexOf("Global") == -1) { | ||
$("#addGlobalUser").removeClass("disabled"); | ||
} | ||
} | ||
function addNewUser(users, newUser, _onChange) { | ||
users.push(newUser); | ||
createUser("#user_list", [newUser]); | ||
_onChange(); | ||
$("#username").val(""); | ||
$("#addNewUser").addClass("disabled"); | ||
} | ||
function showGlobalUserSettings(activeUser) { | ||
if (activeUser == "Global") $(".showGlobal").show(); | ||
else $(".showGlobal").hide(); | ||
} | ||
/** | ||
* | ||
* @param {array} users Array of Users | ||
*/ | ||
function generateStartside(users) { | ||
const obj = {}; | ||
users.forEach(function (user) { | ||
obj[user] = $(`#${user} input.startside`).val(); | ||
}); | ||
return obj; | ||
} | ||
// function getAllHistoryInstances(value) { | ||
// socket.emit('getObjectView', 'system', 'instance', {startkey: 'system.adapter.', endkey: 'system.adapter.\u9999'}, function (err, doc) { | ||
// if (!err && doc.rows.length) { | ||
// var $select = $('#history'); | ||
// for (var i = 0; i < doc.rows.length; i++) { | ||
// if (doc.rows[i].value && doc.rows[i].value.common && doc.rows[i].value.common.getHistory) { | ||
// var id = doc.rows[i].id.replace(/^system\.adapter\./, ''); | ||
// $select.append('<option value="' + id + '">' + id + '</option>'); | ||
// } | ||
// } | ||
// } | ||
// $select.val(value || ''); | ||
// $select.select(); | ||
// }); | ||
// } |
@@ -1,43 +0,220 @@ | ||
/* eslint no-unused-vars: off */ | ||
/* eslint no-global-assign: off */ | ||
/* global systemDictionary */ | ||
/* exported systemDictionary*/ | ||
/*global systemDictionary:true */ | ||
/* | ||
+===================== DO NOT MODIFY ======================+ | ||
| This file was generated by translate-adapter, please use | | ||
| `translate-adapter adminLanguages2words` to update it. | | ||
+===================== DO NOT MODIFY ======================+ | ||
*/ | ||
"use strict"; | ||
systemDictionary = { | ||
Action: { | ||
en: "Action", | ||
de: "Aktion", | ||
ru: "Действие", | ||
pt: "Ação", | ||
nl: "Actie", | ||
fr: "Action", | ||
it: "Azione", | ||
es: "Acción", | ||
pl: "Działanie", | ||
uk: "Дія", | ||
"zh-cn": "行动", | ||
}, | ||
Add: { | ||
en: "add", | ||
de: "hinzufügen", | ||
ru: "добавлять", | ||
pt: "adicionar", | ||
nl: "toevoegen", | ||
fr: "ajouter", | ||
it: "aggiungere", | ||
es: "agregar", | ||
pl: "dodać", | ||
uk: "додати", | ||
"zh-cn": "添加", | ||
}, | ||
"Add new Navigation": { | ||
en: "Add new Navigation", | ||
de: "Neue Navigation hinzufügen", | ||
ru: "Добавить новую навигацию", | ||
pt: "Adicionar nova navegação", | ||
nl: "Nieuwe navigatie toevoegen", | ||
fr: "Ajouter une nouvelle navigation", | ||
it: "Aggiungi nuova navigazione", | ||
es: "Agregar nueva navegación", | ||
pl: "Dodaj nową Nawigację", | ||
uk: "Додати нову навігацію", | ||
"zh-cn": "添加新导航", | ||
}, | ||
"Add new Username": { | ||
en: "Add new Username", | ||
de: "Neuen Benutzernamen hinzufügen", | ||
ru: "Добавить новое имя пользователя", | ||
pt: "Adicionar novo nome de usuário", | ||
nl: "Nieuwe gebruikersnaam toevoegen", | ||
fr: "Ajouter un nouveau nom d'utilisateur", | ||
it: "Aggiungi nuovo nome utente", | ||
es: "Agregar nuevo nombre de usuario", | ||
pl: "Dodaj nową nazwę użytkownika", | ||
uk: "Додайте нове ім'я користувача", | ||
"zh-cn": "添加新用户名", | ||
}, | ||
"All User from Telegram, seperate with": { | ||
en: "All User from Telegram, seperate with", | ||
de: "Alle Benutzer von Telegram, getrennt mit", | ||
ru: "Все пользователи из Telegram, отдельно от", | ||
pt: "Todos os usuários do Telegram, separados por", | ||
nl: "Alle gebruikers van Telegram, gescheiden met", | ||
fr: "Tous les utilisateurs de Telegram, séparés par", | ||
it: "Tutti gli utenti di Telegram, separati da", | ||
es: "Todos los usuarios de Telegram, separados con", | ||
pl: "Wszyscy użytkownicy z Telegramu, oddzielni od", | ||
uk: "Всі користувачі з Telegram, окремо від", | ||
"zh-cn": "来自 Telegram 的所有用户,与", | ||
}, | ||
Cancel: { | ||
en: "Cancel", | ||
de: "Stornieren", | ||
ru: "Отмена", | ||
pt: "Cancelar", | ||
nl: "Annuleren", | ||
fr: "Annuler", | ||
it: "Annulla", | ||
es: "Cancelar", | ||
pl: "Anulować", | ||
uk: "Скасувати", | ||
"zh-cn": "取消", | ||
}, | ||
Close: { | ||
en: "Close", | ||
de: "Schließen", | ||
ru: "Закрывать", | ||
pt: "Fechar", | ||
nl: "Dichtbij", | ||
fr: "Fermer", | ||
it: "Vicino", | ||
es: "Cerca", | ||
pl: "Zamknąć", | ||
uk: "Закрити", | ||
"zh-cn": "关闭", | ||
}, | ||
"Global User activ": { | ||
en: "Global user activ", | ||
de: "Globaler Benutzer aktiv", | ||
ru: "Активность глобального пользователя", | ||
pt: "Atividade global do usuário", | ||
nl: "Globale gebruiker actief", | ||
fr: "Activation globale de l'utilisateur", | ||
it: "Utente globale attivo", | ||
es: "Actividad de usuario global", | ||
pl: "Globalna aktywność użytkowników", | ||
uk: "Глобальна активність користувачів", | ||
"zh-cn": "全球用户活跃度", | ||
}, | ||
Instanze: { | ||
en: "Instanze", | ||
de: "Instanz", | ||
ru: "Инстанц", | ||
pt: "instância", | ||
nl: "Instanze", | ||
fr: "Instantané", | ||
it: "Istanza", | ||
es: "Instancia", | ||
pl: "Instancja", | ||
uk: "Instanze", | ||
"zh-cn": "瞬间", | ||
}, | ||
Navigation: { | ||
en: "Navigation", | ||
de: "Navigation", | ||
ru: "Навигация", | ||
pt: "Navegação", | ||
nl: "Navigatie", | ||
fr: "La navigation", | ||
it: "Navigazione", | ||
es: "Navegación", | ||
pl: "Nawigacja", | ||
uk: "Навігація", | ||
"zh-cn": "导航", | ||
}, | ||
Save: { | ||
en: "Save", | ||
de: "Speichern", | ||
ru: "Сохранять", | ||
pt: "Salvar", | ||
nl: "Redden", | ||
fr: "Sauvegarder", | ||
it: "Salva", | ||
es: "Ahorrar", | ||
pl: "Ratować", | ||
uk: "зберегти", | ||
"zh-cn": "节省", | ||
}, | ||
Settings: { | ||
en: "Settings", | ||
de: "Einstellungen", | ||
ru: "Настройки", | ||
pt: "Configurações", | ||
nl: "Instellingen", | ||
fr: "Paramètres", | ||
it: "Impostazioni", | ||
es: "Ajustes", | ||
pl: "Ustawienia", | ||
uk: "Налаштування", | ||
"zh-cn": "设置", | ||
}, | ||
Startside: { | ||
en: "Startside", | ||
de: "Startseite", | ||
ru: "Стартовая сторона", | ||
pt: "Startside", | ||
nl: "Startzijde", | ||
fr: "Côté départ", | ||
it: "Lato iniziale", | ||
es: "Lado de salida", | ||
pl: "Strona startowa", | ||
uk: "Стартова сторона", | ||
"zh-cn": "起跑线", | ||
}, | ||
"telegram-menu adapter settings": { | ||
en: "Adapter settings for telegram-menu", | ||
de: "Adaptereinstellungen für telegram-menu", | ||
ru: "Настройки адаптера для telegram-menu", | ||
pt: "Configurações do adaptador para telegram-menu", | ||
nl: "Adapterinstellingen voor telegram-menu", | ||
fr: "Paramètres d'adaptateur pour telegram-menu", | ||
it: "Impostazioni dell'adattatore per telegram-menu", | ||
es: "Ajustes del adaptador para telegram-menu", | ||
pl: "Ustawienia adaptera dla telegram-menu", | ||
"zh-cn": "telegram-menu的适配器设置", | ||
de: "Adaptereinstellungen für Telegram-Menü", | ||
ru: "Настройки адаптера для телеграм-меню", | ||
pt: "Configurações do adaptador para menu de telegrama", | ||
nl: "Adapterinstellingen voor telegrammenu", | ||
fr: "Paramètres de l'adaptateur pour le menu télégramme", | ||
it: "Impostazioni dell'adattatore per il menu del telegramma", | ||
es: "Configuración del adaptador para el menú de telegramas", | ||
pl: "Ustawienia adaptera dla menu telegramu", | ||
uk: "Налаштування адаптера для telegram-меню", | ||
"zh-cn": "电报菜单的适配器设置", | ||
}, | ||
option1: { | ||
en: "option1", | ||
de: "Option 1", | ||
ru: "Опция 1", | ||
pt: "Opção 1", | ||
nl: "Optie 1", | ||
fr: "Option 1", | ||
it: "opzione 1", | ||
es: "Opción 1", | ||
pl: "opcja 1", | ||
"zh-cn": "选项1", | ||
Select: { | ||
en: "Select", | ||
de: "Wählen", | ||
ru: "Выбирать", | ||
pt: "Selecione", | ||
nl: "Selecteer", | ||
fr: "Sélectionner", | ||
it: "Selezionare", | ||
es: "Seleccionar", | ||
pl: "Wybierać", | ||
uk: "Виберіть", | ||
"zh-cn": "选择", | ||
}, | ||
option2: { | ||
en: "option2", | ||
de: "Option 2", | ||
ru: "вариант 2", | ||
pt: "opção 2", | ||
nl: "Optie 2", | ||
fr: "Option 2", | ||
it: "opzione 2", | ||
es: "opcion 2", | ||
pl: "Opcja 2", | ||
"zh-cn": "选项2", | ||
Call: { | ||
en: "Call", | ||
de: "Forderung", | ||
ru: "Вызов", | ||
pt: "Chamar", | ||
nl: "Telefoongesprek", | ||
fr: "Appel", | ||
it: "Chiamata", | ||
es: "Llamar", | ||
pl: "Dzwonić", | ||
uk: "Телефонуйте", | ||
"zh-cn": "称呼", | ||
}, | ||
}; |
{ | ||
"common": { | ||
"name": "telegram-menu", | ||
"version": "0.0.1", | ||
"news": { | ||
"0.0.1": { | ||
"en": "initial release", | ||
"de": "Erstveröffentlichung", | ||
"ru": "Начальная версия", | ||
"pt": "lançamento inicial", | ||
"nl": "Eerste uitgave", | ||
"fr": "Première version", | ||
"it": "Versione iniziale", | ||
"es": "Versión inicial", | ||
"pl": "Pierwsze wydanie", | ||
"zh-cn": "首次出版" | ||
} | ||
}, | ||
"title": "Telegram Menu", | ||
"titleLang": { | ||
"en": "Telegram Menu", | ||
"de": "Telegramm-Menü", | ||
"ru": "Меню телеграммы", | ||
"pt": "Menu Telegram", | ||
"nl": "Telegram-menu", | ||
"fr": "Menu Télégramme", | ||
"it": "Menù telegramma", | ||
"es": "Menú de telegramas", | ||
"pl": "menu telegramu", | ||
"zh-cn": "电报菜单" | ||
}, | ||
"desc": { | ||
"en": "Easily create Telegram Menus", | ||
"de": "Erstellen Sie ganz einfach Telegrammmenüs", | ||
"ru": "Легко создавать меню Telegram", | ||
"pt": "Crie facilmente menus de telegrama", | ||
"nl": "Maak eenvoudig Telegram-menu's", | ||
"fr": "Créez facilement des menus de télégramme", | ||
"it": "Crea facilmente menu di Telegram", | ||
"es": "Crea fácilmente menús de Telegram", | ||
"pl": "Z łatwością twórz menu telegramu", | ||
"zh-cn": "轻松创建电报菜单" | ||
}, | ||
"authors": ["MiRo1310 <michael.roling@gmx.de>"], | ||
"keywords": ["iobroker", "telegram", "menu"], | ||
"license": "MIT", | ||
"platform": "Javascript/Node.js", | ||
"main": "main.js", | ||
"icon": "telegram-menu.png", | ||
"enabled": true, | ||
"messagebox": true, | ||
"extIcon": "https://raw.githubusercontent.com/MiRo1310/ioBroker.telegram-menu/main/admin/telegram-menu.png", | ||
"readme": "https://github.com/MiRo1310/ioBroker.telegram-menu/blob/main/README.md", | ||
"loglevel": "info", | ||
"mode": "daemon", | ||
"type": "messaging", | ||
"compact": true, | ||
"connectionType": "local", | ||
"dataSource": "poll", | ||
"adminUI": { | ||
"config": "materialize" | ||
}, | ||
"dependencies": [ | ||
{ | ||
"js-controller": ">=3.3.22" | ||
} | ||
], | ||
"globalDependencies": [ | ||
{ | ||
"admin": ">=5.0.0" | ||
} | ||
] | ||
}, | ||
"native": { | ||
"devices": null, | ||
"table_nav": null, | ||
"nav_entry": null, | ||
"users": null | ||
}, | ||
"objects": [], | ||
"instanceObjects": [ | ||
{ | ||
"_id": "info", | ||
"type": "channel", | ||
"common": { | ||
"name": "Information" | ||
}, | ||
"native": {} | ||
}, | ||
{ | ||
"_id": "info.connection", | ||
"type": "state", | ||
"common": { | ||
"role": "indicator.connected", | ||
"name": "Device or service connected", | ||
"type": "boolean", | ||
"read": true, | ||
"write": false, | ||
"def": false | ||
}, | ||
"native": {} | ||
}, | ||
{ | ||
"_id": "navigation", | ||
"type": "state", | ||
"common": { | ||
"role": "value", | ||
"name": "Navigation", | ||
"type": "json", | ||
"read": true, | ||
"write": false, | ||
"def": {} | ||
}, | ||
"native": {} | ||
} | ||
] | ||
"common": { | ||
"name": "telegram-menu", | ||
"version": "0.0.2", | ||
"news": { | ||
"0.0.2": { | ||
"en": "initial release", | ||
"de": "erstausstrahlung", | ||
"ru": "начальный выпуск", | ||
"pt": "lançamento inicial", | ||
"nl": "niet", | ||
"fr": "initial release", | ||
"it": "rilascio iniziale", | ||
"es": "liberación inicial", | ||
"pl": "pierwsze wydanie", | ||
"uk": "початковий реліз", | ||
"zh-cn": "初步释放" | ||
}, | ||
"0.0.1": { | ||
"en": "initial release", | ||
"de": "Erstveröffentlichung", | ||
"ru": "Начальная версия", | ||
"pt": "lançamento inicial", | ||
"nl": "Eerste uitgave", | ||
"fr": "Première version", | ||
"it": "Versione iniziale", | ||
"es": "Versión inicial", | ||
"pl": "Pierwsze wydanie", | ||
"zh-cn": "首次出版", | ||
"uk": "початковий випуск" | ||
} | ||
}, | ||
"title": "Telegram Menu erzeugen", | ||
"titleLang": { | ||
"en": "Telegram Menu", | ||
"de": "Telegramm-Menü", | ||
"ru": "Меню телеграммы", | ||
"pt": "Menu Telegram", | ||
"nl": "Telegram-menu", | ||
"fr": "Menu Télégramme", | ||
"it": "Menù telegramma", | ||
"es": "Menú de telegramas", | ||
"pl": "menu telegramu", | ||
"zh-cn": "电报菜单", | ||
"uk": "Меню Telegram" | ||
}, | ||
"desc": { | ||
"en": "Easily create Telegram Menus", | ||
"de": "Erstellen Sie ganz einfach Telegrammmenüs", | ||
"ru": "Легко создавать меню Telegram", | ||
"pt": "Crie facilmente menus de telegrama", | ||
"nl": "Maak eenvoudig Telegram-menu's", | ||
"fr": "Créez facilement des menus de télégramme", | ||
"it": "Crea facilmente menu di Telegram", | ||
"es": "Crea fácilmente menús de Telegram", | ||
"pl": "Z łatwością twórz menu telegramu", | ||
"zh-cn": "轻松创建电报菜单", | ||
"uk": "Легко створюйте меню Telegram" | ||
}, | ||
"authors": [ | ||
"MiRo1310 <michael.roling@gmx.de>" | ||
], | ||
"keywords": [ | ||
"telegram", | ||
"menu" | ||
], | ||
"license": "MIT", | ||
"platform": "Javascript/Node.js", | ||
"main": "main.js", | ||
"icon": "telegram-menu.png", | ||
"enabled": true, | ||
"messagebox": true, | ||
"extIcon": "https://raw.githubusercontent.com/MiRo1310/ioBroker.telegram-menu/main/admin/telegram-menu.png", | ||
"readme": "https://github.com/MiRo1310/ioBroker.telegram-menu/blob/main/README.md", | ||
"loglevel": "info", | ||
"mode": "daemon", | ||
"type": "messaging", | ||
"compact": true, | ||
"connectionType": "local", | ||
"dataSource": "poll", | ||
"adminUI": { | ||
"config": "materialize" | ||
}, | ||
"dependencies": [ | ||
{ | ||
"js-controller": ">=3.3.22" | ||
} | ||
], | ||
"globalDependencies": [ | ||
{ | ||
"admin": ">=5.0.0" | ||
} | ||
] | ||
}, | ||
"native": { | ||
"nav": {}, | ||
"instance": "", | ||
"data": {}, | ||
"checkbox": [], | ||
"usersForGlobal": "", | ||
"users": [], | ||
"startsides": [] | ||
}, | ||
"objects": [], | ||
"instanceObjects": [ | ||
{ | ||
"_id": "info", | ||
"type": "channel", | ||
"common": { | ||
"name": "Information" | ||
}, | ||
"native": {} | ||
}, | ||
{ | ||
"_id": "info.connection", | ||
"type": "state", | ||
"common": { | ||
"role": "indicator.connected", | ||
"name": "Device or service connected", | ||
"type": "boolean", | ||
"read": true, | ||
"write": false, | ||
"def": false | ||
}, | ||
"native": {} | ||
}, | ||
{ | ||
"_id": "navigation", | ||
"type": "state", | ||
"common": { | ||
"role": "value", | ||
"name": "Navigation", | ||
"type": "json", | ||
"read": true, | ||
"write": false, | ||
"def": {} | ||
}, | ||
"native": {} | ||
} | ||
] | ||
} |
282
main.js
@@ -10,3 +10,11 @@ "use strict"; | ||
const utils = require("@iobroker/adapter-core"); | ||
const sendToTelegram = require("./lib/js/telegram").sendToTelegram; | ||
const editArrayButtons = require("./lib/js/action").editArrayButtons; | ||
const generateNewObjectStructure = require("./lib/js/action").generateNewObjectStructure; | ||
const generateActions = require("./lib/js/action").generateActions; | ||
// const lichtAn = require("./lib/js/action").lichtAn; | ||
// const wertUebermitteln = require("./lib/js/action").wertUebermitteln; | ||
const telegramID = "telegram.0.communicate.request"; | ||
// Load your modules here, e.g.: | ||
@@ -25,3 +33,3 @@ // const fs = require("fs"); | ||
this.on("ready", this.onReady.bind(this)); | ||
this.on("stateChange", this.onStateChange.bind(this)); | ||
// this.on("stateChange", this.onStateChange.bind(this)); | ||
// this.on("objectChange", this.onObjectChange.bind(this)); | ||
@@ -35,14 +43,200 @@ this.on("message", this.onMessage.bind(this)); | ||
*/ | ||
async onReady() { | ||
// Initialize your adapter here | ||
// Reset the connection indicator during startup | ||
this.setState("info.connection", false, true); | ||
const datapoint = `${this.config.instance}.info.connection`; | ||
const instanceTelegram = this.config.instance; | ||
this.log.debug("Datapoint " + JSON.stringify(datapoint)); | ||
let telegramAktiv, telegramState; | ||
// The adapters config (in the instance object everything under the attribute "native") is accessible via | ||
// this.config: | ||
// this.log.info("config option1: " + this.config.option1); | ||
// this.log.info("config option 22: " + this.config.option2); | ||
this.log.info("test"); | ||
this.getForeignObject(datapoint, async (err, obj) => { | ||
if (err || obj == null) { | ||
// Error | ||
this.log.error(JSON.stringify(err)); | ||
this.log.error(`The State ${datapoint} was not found!`); | ||
} else { | ||
// Datenpunkt wurde gefunden | ||
telegramState = await this.getForeignStateAsync(datapoint); | ||
this.log.debug("Datapoint " + JSON.stringify(datapoint)); | ||
telegramAktiv = telegramState?.val; | ||
if (!telegramAktiv) { | ||
this.log.info("Telegram was found, but is not runnig. Please start!"); | ||
} | ||
if (telegramAktiv) { | ||
this.log.info("Telegram was found"); | ||
this.setState("info.connection", true, true); | ||
const menu = { | ||
data: {}, | ||
}; | ||
const _this = this; | ||
const data = this.config.data; | ||
const nav = data["nav"]; | ||
const action = data["action"]; | ||
this.log.debug("Navigation " + JSON.stringify(nav)); | ||
this.log.debug("Action " + JSON.stringify(action)); | ||
try { | ||
for (const name in nav) { | ||
this.log.debug("Name " + JSON.stringify(name)); | ||
const value = await editArrayButtons(nav[name], this); | ||
// this.log.debug("Return " + JSON.stringify(value)); | ||
menu.data[name] = await generateNewObjectStructure(_this, value); | ||
menu.data[name] = generateActions(_this, action[name], menu.data[name]); | ||
} | ||
this.log.debug("Resume " + JSON.stringify(menu.data)); | ||
} catch (error) { | ||
this.log.error("Error: " + JSON.stringify(error)); | ||
} | ||
const checkbox = this.config.checkbox; | ||
this.log.debug("Checkbox " + JSON.stringify(checkbox)); | ||
const globalUserActiv = this.config.checkbox[0]["globalUserActiv"]; | ||
const one_time_keyboard = this.config.checkbox[2]["oneTiKey"]; | ||
const resize_keyboard = this.config.checkbox[1]["resKey"]; | ||
this.log.debug("Global User Activ: " + JSON.stringify(globalUserActiv)); | ||
const userList = this.config.users; | ||
const globalUserList = this.config.usersForGlobal.split(","); | ||
this.log.debug("Global User List: " + JSON.stringify(globalUserList)); | ||
const startsides = this.config.startsides; | ||
if (globalUserActiv) { | ||
this.log.debug("Global Users sendto "); | ||
globalUserList.forEach((user) => { | ||
const startside = [startsides["Global"]].toString(); | ||
if (startside && typeof startside == "string") | ||
this.log.debug("Text Global " + JSON.stringify(menu)); | ||
if (startside && typeof startside == "string") | ||
sendToTelegram( | ||
this, | ||
user, | ||
menu.data.Global[startside].text, | ||
menu.data.Global[startside].nav, | ||
instanceTelegram, | ||
resize_keyboard, | ||
one_time_keyboard, | ||
); | ||
}); | ||
} else { | ||
userList.forEach(function (user) { | ||
const startside = [startsides[user]].toString(); | ||
if (user != "Global") | ||
sendToTelegram( | ||
_this, | ||
user, | ||
menu.data[user][startside].text, | ||
menu.data[user][startside].nav, | ||
instanceTelegram, | ||
resize_keyboard, | ||
one_time_keyboard, | ||
); | ||
}); | ||
} | ||
this.on("stateChange", async (id, state) => { | ||
if (state && typeof state.val === "string" && state.val != "" && id == telegramID) { | ||
const value = state.val; | ||
const user = value.slice(1, value.indexOf("]")); | ||
const toDo = value.slice(value.indexOf("]") + 1, value.length); | ||
this.log.debug("Value: " + JSON.stringify(value)); | ||
this.log.debug("User: " + JSON.stringify(user)); | ||
this.log.debug("Todo: " + JSON.stringify(toDo)); | ||
let nav; | ||
let userToSend = null; | ||
if (globalUserActiv) { | ||
nav = menu.data["Global"]; | ||
if (globalUserList.indexOf(user) != -1) userToSend = user; | ||
} else { | ||
nav = menu.data[user]; | ||
userToSend = user; | ||
} | ||
this.log.debug("Nav " + JSON.stringify(nav)); | ||
this.log.debug("Menu " + JSON.stringify(menu.data)); | ||
if (nav[toDo]) { | ||
const part = nav[toDo]; | ||
this.log.debug("Part " + JSON.stringify(part)); | ||
// Navigation | ||
if (part.nav) { | ||
this.log.debug("User to send: " + JSON.stringify(userToSend)); | ||
this.log.debug("Todo " + JSON.stringify(toDo)); | ||
this.log.debug("Part.nav: " + JSON.stringify(part.nav)); | ||
if (userToSend) | ||
sendToTelegram( | ||
this, | ||
userToSend, | ||
part.text, | ||
part.nav, | ||
instanceTelegram, | ||
resize_keyboard, | ||
one_time_keyboard, | ||
); | ||
} | ||
// Schalten | ||
if (part.switch) { | ||
try { | ||
part.switch.forEach( | ||
(/** @type {{ id: string; value: boolean; toggle:boolean }} */ element) => { | ||
this.log.debug("Element to set " + JSON.stringify(element)); | ||
if (element.toggle) { | ||
if (element.toggle) this.log.debug("Toggle"); | ||
this.getForeignStateAsync(element.id) | ||
.then((val) => { | ||
this.log.debug("Value " + JSON.stringify(val)); | ||
if (val) this.setForeignStateAsync(element.id, !val.val); | ||
}) | ||
.catch((e) => { | ||
console.log(e); | ||
}); | ||
} else this.setForeignStateAsync(element.id, element.value); | ||
}, | ||
); | ||
} catch (error) { | ||
this.log.error("" + JSON.stringify(error)); | ||
} | ||
} | ||
if (part.getData) { | ||
try { | ||
let text = ""; | ||
let i = 0; | ||
part.getData.forEach((/** @type {{ id: string; text:string}} */ element) => { | ||
this.getForeignStateAsync(element.id).then((value) => { | ||
if (value && value.val && typeof value.val == "string") { | ||
this.log.debug("GetValue " + JSON.stringify(value.val)); | ||
this.log.debug("Element.text " + JSON.stringify(element.text)); | ||
if (element.text) { | ||
if (element.text.indexOf("&&") != -1) | ||
text += `${element.text.replace("&&", value.val)}`; | ||
else text += element.text + " " + value.val; | ||
} else text += `${value.val} `; | ||
i++; | ||
if (i === part.getData.length && userToSend) { | ||
sendToTelegram(this, userToSend, text); | ||
} | ||
} | ||
}); | ||
}); | ||
} catch (error) { | ||
this.log.error("Error: " + JSON.stringify(error)); | ||
} | ||
} | ||
} else { | ||
if (typeof userToSend == "string") | ||
sendToTelegram(this, userToSend, "Eintrag wurde nicht gefunden!"); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
// let users = this.config.users; | ||
// } | ||
// this.log.info(JSON.stringify(this.config.usersForGlobal)); | ||
// this.log.info(JSON.stringify(this.config.checkbox)); | ||
// this.log.info(JSON.stringify(this.config.users)); | ||
/* | ||
@@ -53,20 +247,22 @@ For every state in the system there has to be also an object of type state | ||
*/ | ||
await this.setObjectNotExistsAsync("testVariable", { | ||
type: "state", | ||
common: { | ||
name: "testVariable", | ||
type: "boolean", | ||
role: "indicator", | ||
read: true, | ||
write: true, | ||
}, | ||
native: {}, | ||
}); | ||
// await this.setObjectNotExistsAsync("testVariable", { | ||
// type: "state", | ||
// common: { | ||
// name: "testVariable", | ||
// type: "boolean", | ||
// role: "indicator", | ||
// read: true, | ||
// write: true, | ||
// }, | ||
// native: {}, | ||
// }); | ||
// 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. | ||
this.subscribeStates("testVariable"); | ||
// this.subscribeStates("testVariable"); | ||
// You can also add a subscription for multiple states. The following line watches all states starting with "lights." | ||
// this.subscribeStates("lights.*"); | ||
// 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: | ||
// this.subscribeStates("*"); | ||
this.subscribeForeignStatesAsync("telegram.0.info.connection"); | ||
this.subscribeForeignStatesAsync("telegram.0.communicate.request"); | ||
this.subscribeStates(telegramID); | ||
@@ -78,17 +274,17 @@ /* | ||
// the variable testVariable is set to true as command (ack=false) | ||
await this.setStateAsync("testVariable", true); | ||
// await this.setStateAsync("testVariable", true); | ||
// same thing, but the value is flagged "ack" | ||
// ack should be always set to true if the value is received from or acknowledged from the target system | ||
await this.setStateAsync("testVariable", { val: true, ack: true }); | ||
// 'await this.setStateAsync("testVariable", { val: true, ack: true }); | ||
// same thing, but the state is deleted after 30s (getState will return null afterwards) | ||
await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); | ||
// 'await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); | ||
// examples for the checkPassword/checkGroup functions | ||
let result = await this.checkPasswordAsync("admin", "iobroker"); | ||
this.log.info("check user admin pw iobroker: " + result); | ||
// let result = await this.checkPasswordAsync("admin", "iobroker"); | ||
// this.log.info("check user admin pw iobroker: " + result); | ||
result = await this.checkGroupAsync("admin", "admin"); | ||
this.log.info("check group user admin group admin: " + result); | ||
// result = await this.checkGroupAsync("admin", "admin"); | ||
// this.log.info("check group user admin group admin: " + result); | ||
} | ||
@@ -131,16 +327,16 @@ | ||
/** | ||
* Is called if a subscribed state changes | ||
* @param {string} id | ||
* @param {ioBroker.State | null | undefined} state | ||
*/ | ||
onStateChange(id, state) { | ||
if (state) { | ||
// The state was changed | ||
this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); | ||
} else { | ||
// The state was deleted | ||
this.log.info(`state ${id} deleted`); | ||
} | ||
} | ||
// /** | ||
// * Is called if a subscribed state changes | ||
// * @param {string} id | ||
// * @param {ioBroker.State | null | undefined} state | ||
// */ | ||
// onStateChange(id, state) { | ||
// if (state) { | ||
// // The state was changed | ||
// this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); | ||
// } else { | ||
// // The state was deleted | ||
// this.log.info(`state ${id} deleted`); | ||
// } | ||
// } | ||
@@ -147,0 +343,0 @@ // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. |
{ | ||
"name": "iobroker.telegram-menu", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Easily create Telegram Menus", | ||
@@ -38,3 +38,3 @@ "author": { | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^16.18.20", | ||
"@types/node": "^18.15.11", | ||
"@types/proxyquire": "^1.3.28", | ||
@@ -45,3 +45,3 @@ "@types/sinon": "^10.0.13", | ||
"chai-as-promised": "^7.1.1", | ||
"eslint": "^8.36.0", | ||
"eslint": "^8.38.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
@@ -52,5 +52,5 @@ "eslint-plugin-prettier": "^4.2.1", | ||
"proxyquire": "^2.1.3", | ||
"sinon": "^15.0.2", | ||
"sinon": "^15.0.3", | ||
"sinon-chai": "^3.7.0", | ||
"typescript": "~4.6.4" | ||
"typescript": "~5.0.4" | ||
}, | ||
@@ -57,0 +57,0 @@ "main": "main.js", |
![Logo](admin/telegram-menu.png) | ||
# ioBroker.telegram-menu | ||
@@ -17,79 +18,6 @@ | ||
## Developer manual | ||
This section is intended for the developer. It can be deleted later. | ||
## Discrition | ||
### DISCLAIMER | ||
## Changelog | ||
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. | ||
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. | ||
### Getting started | ||
You are almost done, only a few steps left: | ||
1. Create a new repository on GitHub with the name `ioBroker.telegram-menu` | ||
1. Push all files to the GitHub repo. The creator has already set up the local repository for you: | ||
```bash | ||
git push origin main | ||
``` | ||
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. | ||
1. Head over to [main.js](main.js) and start programming! | ||
### Best Practices | ||
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 | ||
check them out. If you're already experienced, you should also take a look at them - you might learn something new :) | ||
### Scripts in `package.json` | ||
Several npm scripts are predefined for your convenience. You can run them using `npm run <scriptname>` | ||
| Script name | Description | | ||
|-------------|-------------| | ||
| `test:js` | Executes the tests you defined in `*.test.js` files. | | ||
| `test:package` | Ensures your `package.json` and `io-package.json` are valid. | | ||
| `test:integration` | Tests the adapter startup with an actual instance of ioBroker. | | ||
| `test` | Performs a minimal test run on package files and your tests. | | ||
| `check` | Performs a type-check on your code (without compiling anything). | | ||
| `lint` | Runs `ESLint` to check your code for formatting errors and potential bugs. | | ||
| `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. | | ||
| `release` | Creates a new release, see [`@alcalzone/release-script`](https://github.com/AlCalzone/release-script#usage) for more details. | | ||
### Writing tests | ||
When done right, testing code is invaluable, because it gives you the | ||
confidence to change your code while knowing exactly if and when | ||
something breaks. A good read on the topic of test-driven development | ||
is https://hackernoon.com/introduction-to-test-driven-development-tdd-61a13bc92d92. | ||
Although writing tests before the code might seem strange at first, but it has very | ||
clear upsides. | ||
The template provides you with basic tests for the adapter startup and package files. | ||
It is recommended that you add your own tests into the mix. | ||
### Publishing the adapter | ||
Using GitHub Actions, you can enable automatic releases on npm whenever you push a new git tag that matches the form | ||
`v<major>.<minor>.<patch>`. We **strongly recommend** that you do. The necessary steps are described in `.github/workflows/test-and-release.yml`. | ||
Since you installed the release script, you can create a new | ||
release simply by calling: | ||
```bash | ||
npm run release | ||
``` | ||
Additional command line options for the release script are explained in the | ||
[release-script documentation](https://github.com/AlCalzone/release-script#command-line). | ||
To get your adapter released in ioBroker, please refer to the documentation | ||
of [ioBroker.repositories](https://github.com/ioBroker/ioBroker.repositories#requirements-for-adapter-to-get-added-to-the-latest-repository). | ||
### Test the adapter manually with dev-server | ||
Since you set up `dev-server`, you can use it to run, test and debug your adapter. | ||
You may start `dev-server` by calling from your dev directory: | ||
```bash | ||
dev-server watch | ||
``` | ||
The ioBroker.admin interface will then be available at http://localhost:8081/ | ||
Please refer to the [`dev-server` documentation](https://github.com/ioBroker/dev-server#command-line) for more details. | ||
## Changelog | ||
<!-- | ||
@@ -100,6 +28,8 @@ Placeholder for the next version (at the beginning of the line): | ||
### **WORK IN PROGRESS** | ||
* (MiRo1310) initial release | ||
### 0.0.2 (2023-04-16) | ||
- (MiRo1310) initial release | ||
## License | ||
MIT License | ||
@@ -125,2 +55,2 @@ | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
SOFTWARE. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
328175
26
1525
54
1