The following JSON is passed to Node-RED from a traccar server:
{"event":{"id":683,"attributes":{},"deviceId":1,"type":"deviceUnknown","serverTime":"2021-01-26T03:31:58.515+0000","positionId":0,"geofenceId":0,"maintenanceId":0},"device":{"id":1,"attributes":{},"groupId":0,"name":"Lorens Phone","uniqueId":"XXXXXX","status":"unknown","lastUpdate":"2021-01-26T03:21:58.505+0000","positionId":91959,"geofenceIds":[1,2],"phone":"","model":"","contact":"","category":null,"disabled":false},"users":[{"id":2,"attributes":{"speedUnit":"mph","distanceUnit":"mi","timezone":"America/Chicago","notificationTokens":"tokenstuffhere"},"name":"Loren","login":"","email":"myemail","phone":"","readonly":false,"administrator":false,"map":"custom","latitude":36.339871,"longitude":-86.557218,"zoom":18,"twelveHourFormat":false,"coordinateFormat":"","disabled":false,"expirationTime":null,"deviceLimit":-1,"userLimit":0,"deviceReadonly":false,"token":null,"limitCommands":false,"poiLayer":"","password":null}]}
I would like to send the information via telegram to my phone for debugging. I'm getting an error:
TypeError: Cannot read property 'type' of undefined
Here is the function that is causing the error:
var incomming = msg.payload;
if(incomming.event["type"] && incomming["geofence"]){
if(incomming.event.type === "geofenceEnter" || "geofenceExit"){
var name = incomming.device.name
var fence = incomming.geofence.name
if(incomming.event.type === "geofenceEnter"){
var direction = "Entered"
msg.payload ={
chatId:'XXXXXX',
type: 'message',
content: name + " " + direction + " " + fence
}
}
else if(incomming.event.type === "geofenceExit"){
var direction = "exited"
msg.payload ={
chatId:'XXXXXX',
type: 'message',
content: name + " " + direction + " " + fence
}
}
else if(incomming.event.type === "deviceOnline"){
msg.payload ={
chatId:'XXXXXX',
type: 'message',
content: name + " " + incomming.event.type
}
}else{
msg.payload ={
chatId:'XXXXXX',
type: 'message',
content: incomming
}
}
}
else{
msg.payload ={
chatId:'XXXXXX',
type: 'message',
content: incomming
}
}
}
else{
msg.payload ={
chatId:'XXXXXX',
type: 'message',
content: incomming
}
}
return msg;
What am I doing wrong?