diff --git a/pushnotifications/README.md b/pushnotifications/README.md index c0f105a9..d8728da5 100644 --- a/pushnotifications/README.md +++ b/pushnotifications/README.md @@ -17,6 +17,8 @@ for iOS too. On Ubuntu, the UBPorts push services are used. ## More +### Setup + During setup, the token, the push service system and a client id needs to be provided. The token is normally obtained by the operating system. The push service should be selected from FB-GCM, FB-APNs or UBPorts. The client id must a unique per client and as persistent as possible. @@ -29,3 +31,28 @@ when setting up a push notification thing. Normally, push tokens expire after a the user clears app data, when the operating system decides to cycle tokens etc). In this case, the client app should reconfigure its own push notification thing, updating the token with the new one. The client ID parameter schould be used to find the appropriate thing to reconfigure. + + +### Extra data +When sending a push notification, additional data can be passed which will delivered to the client (e.g. nymea:app). + +nymea:app currently supports the following extra data: + +* open=view: Open a particular view in the app. This can be a main view or a thing id. +* execute=action&thingId=&actionParams= + +Examples: + +Open the Dashboard view: + + open=dashboard + +Open a particular thing by its ID: + + open=5634307c-8569-4365-a78a-45e7e97966cb + +Turn on a light: + + execute=power&thingId=5634307c-8569-4365-a78a-45e7e97966cb&actionParams="{\"power\":true}" + + diff --git a/pushnotifications/integrationpluginpushnotifications.cpp b/pushnotifications/integrationpluginpushnotifications.cpp index 74b7e7e6..1138e9e2 100644 --- a/pushnotifications/integrationpluginpushnotifications.cpp +++ b/pushnotifications/integrationpluginpushnotifications.cpp @@ -119,14 +119,23 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info) QString token = thing->paramValue(pushNotificationsThingTokenParamTypeId).toString(); QString pushService = thing->paramValue(pushNotificationsThingServiceParamTypeId).toString(); - QString title = action.param(pushNotificationsNotifyActionTitleParamTypeId).value().toString(); QString body = action.param(pushNotificationsNotifyActionBodyParamTypeId).value().toString(); + QString data = action.paramValue(pushNotificationsNotifyActionDataParamTypeId).toString(); if (pushService != "None" && token.isEmpty()) { return info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Push notifications need to be reconfigured.")); } + QVariantMap nymeaData; + // FIXME: This is quite ugly but there isn't an API that allows to retrieve the server UUID yet + NymeaSettings settings(NymeaSettings::SettingsRoleGlobal); + settings.beginGroup("nymead"); + QUuid serverUuid = settings.value("uuid").toUuid(); + settings.endGroup(); + nymeaData.insert("serverUuid", serverUuid); + nymeaData.insert("data", data); + QNetworkRequest request; QVariantMap payload; @@ -147,6 +156,8 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info) QVariantMap notification; notification.insert("title", title); notification.insert("body", body); + notification.insert("nymeaData", nymeaData); + if (pushService == "FB-GCM") { @@ -189,6 +200,7 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info) notification.insert("card", card); notification.insert("vibrate", true); notification.insert("sound", true); + notification.insert("nymeaData", nymeaData); QVariantMap data; data.insert("notification", notification); diff --git a/pushnotifications/integrationpluginpushnotifications.h b/pushnotifications/integrationpluginpushnotifications.h index 76285663..73312627 100644 --- a/pushnotifications/integrationpluginpushnotifications.h +++ b/pushnotifications/integrationpluginpushnotifications.h @@ -33,6 +33,8 @@ #include "integrations/integrationplugin.h" +#include "extern-plugininfo.h" + class IntegrationPluginPushNotifications: public IntegrationPlugin { Q_OBJECT diff --git a/pushnotifications/integrationpluginpushnotifications.json b/pushnotifications/integrationpluginpushnotifications.json index 382b613b..f0c77770 100644 --- a/pushnotifications/integrationpluginpushnotifications.json +++ b/pushnotifications/integrationpluginpushnotifications.json @@ -26,7 +26,7 @@ { "id": "12ec06b2-44e7-486a-9169-31c684b91c8f", "name": "token", - "displayName": "access token", + "displayName": "Access token", "type": "QString" }, { @@ -40,12 +40,12 @@ { "id": "ed9a0196-6c24-4e05-9cbc-c6834de38005", "name": "notify", - "displayName": "notify", + "displayName": "Send notification", "paramTypes": [ { "id": "3b5e195c-9f96-4f2f-a654-f17ed77c02ee", "name": "title", - "displayName": "title", + "displayName": "Title", "type": "QString", "inputType": "TextLine", "defaultValue": "" @@ -53,10 +53,17 @@ { "id": "074c4c7c-037f-45ac-ab2f-f7aea3f84bde", "name": "body", - "displayName": "body", + "displayName": "Body", "type": "QString", "inputType": "TextArea", "defaultValue": "" + }, + { + "id": "ca36a33f-a7f2-4f59-8767-3522ecaaf8fb", + "name": "data", + "displayName": "Data", + "type": "QString", + "defaultValue": "" } ] } diff --git a/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-de.ts b/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-de.ts index 405fd946..68dd61b0 100644 --- a/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-de.ts +++ b/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-de.ts @@ -1,72 +1,91 @@ - + IntegrationPluginPushNotifications - + The token must not be empty. Error setting up thing - + Das Token darf nicht leer sein. - + The push service must not be empty. Error setting up thing - + Der Push-Benachrichtigungsdienst darf nicht leer sein. - + + + Firebase server API key not installed. + Error setting up thing + Das API-Token für den Firebase Server ist nicht installiert. + + + Push notifications need to be reconfigured. - + Push Notifications müssen erneut eingerichtet werden. pushNotifications - - + + Access token + The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f}) + Zugrangs-Token + + + + Body + The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde}) + Benachrichtigungstext + + + + Client ID + The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {d76da367-64e3-4b7d-aa84-c96b3acfb65e}) + Client ID + + + + Data + The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {ca36a33f-a7f2-4f59-8767-3522ecaaf8fb}) + Daten + + + + Push Notifications The name of the ThingClass ({f0dd4c03-0aca-42cc-8f34-9902457b05de}) ---------- The name of the plugin pushNotifications ({fdcea3b3-8d79-4fbb-8101-1ab45d71cedb}) - + Push-Benachrichtigungen - + Push service The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {3cb8e30e-2ec5-4b4b-8c8c-03eaf7876839}) - + Push-Benachrichtigungsdiesnt - - access token - The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f}) - - - - - body - The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde}) - - - - - notify + + Send notification The name of the ActionType ({ed9a0196-6c24-4e05-9cbc-c6834de38005}) of ThingClass pushNotifications - + Benachrichtigung senden - + + Title + The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee}) + Titel + + + nymea GmbH The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) - - - - - title - The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee}) - + nymea GmbH diff --git a/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-en_US.ts b/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-en_US.ts index 405fd946..c0a367b8 100644 --- a/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-en_US.ts +++ b/pushnotifications/translations/fdcea3b3-8d79-4fbb-8101-1ab45d71cedb-en_US.ts @@ -4,19 +4,26 @@ IntegrationPluginPushNotifications - + The token must not be empty. Error setting up thing - + The push service must not be empty. Error setting up thing - + + + Firebase server API key not installed. + Error setting up thing + + + + Push notifications need to be reconfigured. @@ -24,8 +31,32 @@ pushNotifications - - + + Access token + The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f}) + + + + + Body + The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde}) + + + + + Client ID + The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {d76da367-64e3-4b7d-aa84-c96b3acfb65e}) + + + + + Data + The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {ca36a33f-a7f2-4f59-8767-3522ecaaf8fb}) + + + + + Push Notifications The name of the ThingClass ({f0dd4c03-0aca-42cc-8f34-9902457b05de}) ---------- @@ -33,40 +64,28 @@ The name of the plugin pushNotifications ({fdcea3b3-8d79-4fbb-8101-1ab45d71cedb} - + Push service The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {3cb8e30e-2ec5-4b4b-8c8c-03eaf7876839}) - - access token - The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f}) - - - - - body - The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde}) - - - - - notify + + Send notification The name of the ActionType ({ed9a0196-6c24-4e05-9cbc-c6834de38005}) of ThingClass pushNotifications - + + Title + The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee}) + + + + nymea GmbH The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) - - - title - The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee}) - -