Zumindest einen oneWay Sync mit todoist konnte ich bauen,
const axios = require('axios');
// Überwachen der Änderung des JSON-Arrays
on({id: 'alexa2.0.Lists.SHOPPING_LIST.json', change: 'any'}, function (obj) {
try {
const jsonArray = JSON.parse(obj.state.val);
if (jsonArray && jsonArray.length > 0) {
const currentTime = Date.now();
const timeLimit = 30 * 60 * 1000; // 30 Minuten in Millisekunden
// Überprüfen, ob das erste Element innerhalb der letzten 30 Minuten erstellt wurde
const createdDateTime = jsonArray[0].createdDateTime;
const completed=jsonArray[0].completed;
console.log(jsonArray[0]);
if (currentTime - createdDateTime < timeLimit && !completed ) {
const item = jsonArray[0].value;
const data = {
content: item,
project_id: '12345678'
};
axios.post('https://api.todoist.com/rest/v2/tasks', data, {
headers: {
'Content-Type': 'application/json',
'X-Request-Id': '598cee9a-cec2-44c0-9cc6-e3eae1608c53',
'Authorization': 'Bearer $token'
}
})
.then(response => {
console.log('Task created successfully:', response.data);
})
.catch(error => {
console.error('Error creating task:', error);
});
} else {
console.log('The item is older than 30 minutes, no task created.');
}
}
} catch (e) {
console.error('Error parsing JSON:', e);
}
});