MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

MMM-NotificationTrigger transform payload



  • Hi there…
    first of all sorry for my english
    Can someone explain how I can transfer the payload “title” of the standard calendar module to the payload “massage” of the alert module? This is the configuration I’ve tested:

    {
      module: "MMM-NotificationTrigger",
      config: {
        triggers:[
          {
            trigger: "CALENDAR_EVENTS",
            fires: [
              {
                fire:"SHOW_ALERT",
                payload: (payload) => {
                  return {
                    type: "notification",
                    title: "test",
                    message: payload.title
                  }
                },
              },
            ],
          },
        ]
      }
    
    },  
    

    The result of this configuration is that I only see the title in the alert.

    Thanks.



  • can nobody help me?



  • @corius what is ‘title’? the incoming message is an array of calendar events…



  • by the title i mean the title of the individual calendar events. but ok then it doesn’t work that way. So again asked differently: is there a way to display upcoming calendar events via the alert module?



  • @corius said in MMM-NotificationTrigger transform payload:

    upcoming calendar events

    what does that mean? if I have 20 entries, u want 1 alert with 20 entries, or 20 alerts with 1 entry each?
    or just today, or?

    alert module is expecting a single line of text


  • Module Developer

    @corius you need to have a look at how the payload looks. If it’s an array, you should be able to catch the title of specific elements by using something like payload.entries[n].title


  • Module Developer

    @corius Considering you want to alert the next event happening in say 15 minutes, you could first check what event is in a range of the next 15 minutes, then take it’s title and alert that one. Can all be done inside the callback function you’ve shown above.

    Is that what you want?



  • @lavolp3 actually payload IS an array
    (from my system default cal)

    0: {title: "M L King Day", startDate: "1579500000000", endDate: "1579586400000", fullDayEvent: true, location: "United States", …}
    1: {title: "Valentine's Day", startDate: "1581660000000", endDate: "1581746400000", fullDayEvent: true, location: "United States", …}
    2: {title: "Presidents' Day", startDate: "1581919200000", endDate: "1582005600000", fullDayEvent: true, location: "United States", …}
    3: {title: "Good Friday", startDate: "1586494800000", endDate: "1586581200000", fullDayEvent: true, location: "United States", …}
    4: {title: "Easter Sunday", startDate: "1586667600000", endDate: "1586754000000", fullDayEvent: true, location: "United States", …}
    5: {title: "Mother's Day", startDate: "1589086800000", endDate: "1589173200000", fullDayEvent: true, location: "United States", …}
    6: {title: "Memorial Day", startDate: "1590382800000", endDate: "1590469200000", fullDayEvent: true, location: "United States", …}
    7: {title: "Father's Day", startDate: "1592715600000", endDate: "1592802000000", fullDayEvent: true, location: "United States", …}
    8: {title: "Independence Day Holiday", startDate: "1593752400000", endDate: "1593838800000", fullDayEvent: true, location: "United States", …}
    9: {title: "Independence Day", startDate: "1593838800000", endDate: "1593925200000", fullDayEvent: true, location: "United States", …}
    
    

    so the js would be

    payload[0].title 
    

    for the title (cal subject) of the 1st cal entry

    I found this by using the developers window (ctrl-shift-i), selecting the ‘Sources’ tab,
    expanding the modules entry, and then the calendar entry to get to calendar.js

    then knowing it is a notification,(notificationreceived) i searched (ctrl-f) for ‘sendnotification’
    I put a stop on that line, hit refesh(f5), and the web page starts over, and stops on that line, then use the mouse to hover over the eventlist variable name, and it expands to the data layout



  • @lavolp3 yes that is exacly wat i want. can you please post the code? Thank you


  • Module Developer

    {
      module: "MMM-NotificationTrigger",
      config: {
        triggers:[
          {
            trigger: "CALENDAR_EVENTS",
            fires: [
              {
                fire:"SHOW_ALERT",
                payload: (payload) => {
                  var testMessage = "";
                  payload.forEach(event => {
                    if (moment(event.startDate) > moment() && moment(event.startDate) < moment().add("15", minutes)) {
                     testMessage += event.title + ", "
                    }
                  });
                  return {
                          type: "notification",
                           title: "test",
                           message: testMessage
                  } 
                },
              },
            ],
          },
        ]
      }
    },
    

    This will most probably not work and needs to be de-bugged, but might be worth as a starting point. And I hope you get what I’m hinting at.


Log in to reply