Nomie Plugins allows people who are familiar with HTML and Javascript to create entirely new methods of tracking and monitoring data within Nomie6-oss.
Nomie Plugins use iframes to load and communicate with “plugins”. So this really just means, a plugin is a hosted HTML page, that has some extra javascript to request data to and from Nomie. We do this by using postMessage and window.onMessage to securely pass data between Nomie and your Plugin.
Repo https://github.com/open-nomie/plugins
Nomie6-oss on GitHub Pages: https://open-nomie.github.io
This library abstracts the responsibility of posting messages and listening for messages into simple async calls. This document outlines the specific functions of nomie-plugin.js
.
<script src="https://cdn.jsdelivr.net/gh/open-nomie/plugins/bin/v1/nomie-plugin.js">
Once you’ve included nomie-plugin.js
you’ll have access to the NomiePlugin
class within the documents window.
const plugin = new NomiePlugin({
name: "Weather",
emoji: "⛈",
description: "Get todays weather for your current location",
uses: ["createNote", "onLaunch", "getLocation"],
version: "1.0",
addToCaptureMenu: true,
addToMoreMenu: true,
addToWidgets: false,
});
Describe your plugin using the following properties:
- name: The name of your plugin
- emoji: The Emoji that best describes your plugin
- description: a description of your plugin - this field does support Markdown formatting.
- uses: 🚨 An array of specific features that are blocked by default, and require access to be granted by the User.
- version: The current version of the plugin. If you need to add uses functions, you need to bump your version
- addToCaptureMenu:
(true | false)
Include a menu item in the Capture Menu that opens the Plugin - addToMoreMenu:
(true | false)
Include a menu item in Nomie’s More tab that opens the Plugin - addToWidgets:
(true | false)
Add this plugin as a selectable Dashboard Widget
Methods marked with uses:[]
are blocked by default. You must specifically define these function names in the uses array - this helps ensure users are fully aware of the data this plugin can access.
Create a new journal entry in Nomie.
uses: [’createNote’]
is required for this method
plugin.createNote("This is a Note");
// Or with options
plugin.createNote({
note: "This is a Note",
end: new Date('2010-10-11'),
lat: 40.00,
lng: -83.00,
location: 'Pizza House',
score: 3
});
Fires off each time the user launches Nomie
uses: [’onLaunch’]
is required for this method
plugin.onLaunch(()=>{
console.log("☔️☔️ weather plugin - onLaunch");
this.loadWeather();
});
uses: [’onNote’]
is required for this method
Fires off when the user save a new journal entry within Nomie - that is not SILENCED. Silenced saves are ones that do not trigger a onNote call. This includes entries created from the API, entires created by plugins, or entries that have been edited.
plugin.onNote((note)=>{
console.log("Note text", note.note)
console.log("Note Date", note.end)
console.log("Note Score", note.score)
console.log("Note Elements (raw trackable data)", note.elements)
})
uses: [’getLocation’]
is required for this method
Get the users current location
const location = await plugin.getLocation();
if(location) {
console.log(`User is located at ${location.lat},${location.lng}`)
}
Open the URL of a template within Nomie.
plugin.openTemplateURL('https://6.nomie.app/templates/adhd-template.json');
uses: [’getTrackableUsage’]
is required for this method
Get trackable usage stats for a given period of time.
- tag: string representing the trackable - for example
#mood, @mom, +vacation
- endDate: the last Date of data you’d like - as a javascript date
- daysBack: the number of days you’d like data for - max is 90
const call = await plugin.getTrackableUsage({ tag:'#alcohol', daysBack: 30 });
const usage = call.usage;
console.log("Trackable Values", usage.values); // array of values by day
console.log("Trackable Values", usage.dates); // array of dates
uses: [’searchNotes’]
is required for this method
Search through all data notes stored in Nomie for a given term, and time frame.
- term: undefined or a string
- endDate: last day of data to retrieve
- daysBack: number of Days to include in the search
const notes = await plugin.searchNotes('#mood', new Date(), 30);
if(notes) {
notes.forEach(entry=>{
console.log(`This note: ${entry.note}`);
console.log(entry);
})
}
Select multiple Trackables
uses: [’selectTrackables’]
is required for this method
- type: undefined | tracker | context | person - the type of trackables to show the user
- multiple: true | false - if the user can select multiple trackables or not
- returns: Promise<Array>
const mutipleTrackables = await plugin.selectTrackables(null, true);
const justOneTrackable = await plugin.selectTrackables(null);
const justAPersonTrackable = await plugin.selectTrackables('person');
Selects a single Trackable
uses: [’selectTrackables’]
is required for this method
- type: undefined | tracker | context | person - the type of trackables to show the user
- returns: Promise
const justAPersonTrackable = await plugin.selectTrackable('person');
Convert a tag into the full trackable object, if the user has it configured.
const trackable = await plugin.getTrackable('#mood');
console.log(`${trackable.emoji} ${trackable.tag} is a ${trackable.type} type`);
// If it's a tracker
console.log(trackable.tracker)
// if its a context
console.log(trackable.ctx)
// if its a person
console.log(trackable.person)
Need a specific value for a trackable? Using getTrackableInput, the user will be prompted to provide an input for the specified trackable. If it’s a person or context, the value will be return immediately, if its a tracker, then the tracker specific input will be displayed.
const sleep = await plugin.getTrackableInput('#sleep');
Each time Nomie launches, it will register the plugin
plugin.onRegistered(async () => {
await plugin.storage.init();
if (!plugin.storage.getItem('apikey')) {
const res = await plugin.prompt('OpenWeatherMap API Key',
`OpenWeatherMap API Required. Get your [FREE API key here](https://home.openweathermap.org/api_keys)`)
if (res && res.value) {
plugin.storage.setItem('apikey', res.value);
}
}
})
Open up Nomie’s full size Note editor for a given note.
plugin.openNoteEditor("Just as a string");
// or
plugin.openNoteEditor({ note: 'this is a note', lat: 34, lng: -81, score: 2 })
Request a value from the User. This will bring up Nomie’s prompt alert box with an input field where the user can input a response.
let res = await plugin.prompt('API Key Needed', 'You can get your API Key at [this link](http://somelink)');
if(res.value) {
console.log(`They provided ${res.value}`)
}
Ask the user to confirm an action - for example: Save this Item?
let res = await plugin.confirm('Save this item?', 'You can delete it later');
if(res.value) {
console.log("They confirmed it");
} else {
console.log("They DID NOT CONFIRM it");
}
Alert the user that something happened. It’s a better experience than just the browsers default alert()
plugin.alert('This item was deleted', 'It is gone forever.');
Open any URL in a modal within Nomie.
plugin.openURL('https://nomie.app')
When a plugin is registered it will be passed a set of user preferences for localization, theme and location settings. You can access these preferences from the plugin.prefs
object
console.log(`The week starts on ${plugin.prefs.weekStarts}`);
plugin.prefs.**theme**
: "light" - user themeplugin.prefs.**use24Hour**
: true or false - does the user prefer 24 hour timesplugin.prefs.**useLocation**
: true or false - can we access the users locationplugin.prefs.**useMetric**
: true or false - does the user prefer metricplugin.prefs.**weekStarts**
: sunday or monday - first day of the weekplugin.prefs.**language**
: the users selected language (en-us);
The Nomie Plugin supports reading and writing to a users Nomie storage engine - within an enclosed folder in the storage/plugins/{pluginId}
The storage class needs to be initialized which is async, this will pull the latest data and store it in memory.
await plugin.storage.init()
Storage getItem works just like localStorage, except it can return full javascript objects, so you do not need to JSON.parse.
let key = plugin.storage.getItem('weather-api-key');
if(key) console.log(`We have a key! ${key}`);
Storage setItem works just like localStorage, except you can save entire javascript objects, and you do not need to serialize it to a string.
plugin.storage.setItem('weather-api-key', 12345678);
In some cases you would like to enable multiple different widgets for the same plugin. You can enable this as per below instructions.
In order to enable multiple widgets you need to register the different widgets in the Nomie Storage Engine for your plugin like the below example:
let Widgets = [{"widgetid":"1", "name":"Widget1","emoji":"🥴","config":{"wctext":"This is Widget 1"}},{"widgetid":"2", "name":"Widget2”, "emoji":"👌","config":{"wctext":"This is Widget 2"}}];
plugin.storage.setItem('widgets',Widgets);
In above example we register 2 widgets. The fields widgetid, name and emoji are mandatory and will be used by Nomie to list the widgets as available widgets for this plugin. Any other fields (in above example the config object) can be added in support of your plugin.
When adding widgets to the Nomie dashboard, users will get the list of configured widgets. Nomie will use the widgetid as parameter in the url when the widget is loaded in the dashboard.
So in above example, when the user added the second widget to the dashboard, the url which will be used for this widget is: www.plugindomain.com/?widgetindex=2
You can use the following code to get the the value for the widgetindex parameter. Once you have the widgetindex value, you can use this in your plugin to direct the code to that specific widget.
let WidgetIndex;
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has("widgetindex")){
WidgetIndex = urlParams.get("widgetindex");
}
Please refer to the ☁️Nomie WordCloud or 💬Nomie Quote Plugins in below available plugin list for examples how this can be implemented.
You can install the plugins by copying and pasting the URL provided below in to Nomie’s Plugin manager (More Tab → Plugins)
- Go to the More Tab
- Select Plugins
- Click the + or Add Custom Plugin
- Provide the url for the plugin
- Tap Install Plugin
By default browsers do not let insecure iframes to be called from a secure frame.
in order to test your local plugin within https://open-nomie.github.io you will need to tell your browser to allow insecure content for Nomie’s domain. Follow these instructions to make that change https://experienceleague.adobe.com/docs/target/using/experiences/vec/troubleshoot-composer/mixed-content.html?lang=en
Copyright 2023 All Rights Reserved.