PushNotifications: Allow adding custom data to push notifications

master
Michael Zanetti 2021-09-15 14:38:47 +02:00
parent b4aeeefa48
commit 7d966c6293
6 changed files with 153 additions and 67 deletions

View File

@ -17,6 +17,8 @@ for iOS too. On Ubuntu, the UBPorts push services are used.
## More ## More
### Setup
During setup, the token, the push service system and a client id needs to be provided. The token is normally 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 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. 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 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 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. 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=<thingId>&actionParams=<params json>
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}"

View File

@ -119,14 +119,23 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
QString token = thing->paramValue(pushNotificationsThingTokenParamTypeId).toString(); QString token = thing->paramValue(pushNotificationsThingTokenParamTypeId).toString();
QString pushService = thing->paramValue(pushNotificationsThingServiceParamTypeId).toString(); QString pushService = thing->paramValue(pushNotificationsThingServiceParamTypeId).toString();
QString title = action.param(pushNotificationsNotifyActionTitleParamTypeId).value().toString(); QString title = action.param(pushNotificationsNotifyActionTitleParamTypeId).value().toString();
QString body = action.param(pushNotificationsNotifyActionBodyParamTypeId).value().toString(); QString body = action.param(pushNotificationsNotifyActionBodyParamTypeId).value().toString();
QString data = action.paramValue(pushNotificationsNotifyActionDataParamTypeId).toString();
if (pushService != "None" && token.isEmpty()) { if (pushService != "None" && token.isEmpty()) {
return info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Push notifications need to be reconfigured.")); 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; QNetworkRequest request;
QVariantMap payload; QVariantMap payload;
@ -147,6 +156,8 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
QVariantMap notification; QVariantMap notification;
notification.insert("title", title); notification.insert("title", title);
notification.insert("body", body); notification.insert("body", body);
notification.insert("nymeaData", nymeaData);
if (pushService == "FB-GCM") { if (pushService == "FB-GCM") {
@ -189,6 +200,7 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
notification.insert("card", card); notification.insert("card", card);
notification.insert("vibrate", true); notification.insert("vibrate", true);
notification.insert("sound", true); notification.insert("sound", true);
notification.insert("nymeaData", nymeaData);
QVariantMap data; QVariantMap data;
data.insert("notification", notification); data.insert("notification", notification);

View File

@ -33,6 +33,8 @@
#include "integrations/integrationplugin.h" #include "integrations/integrationplugin.h"
#include "extern-plugininfo.h"
class IntegrationPluginPushNotifications: public IntegrationPlugin class IntegrationPluginPushNotifications: public IntegrationPlugin
{ {
Q_OBJECT Q_OBJECT

View File

@ -26,7 +26,7 @@
{ {
"id": "12ec06b2-44e7-486a-9169-31c684b91c8f", "id": "12ec06b2-44e7-486a-9169-31c684b91c8f",
"name": "token", "name": "token",
"displayName": "access token", "displayName": "Access token",
"type": "QString" "type": "QString"
}, },
{ {
@ -40,12 +40,12 @@
{ {
"id": "ed9a0196-6c24-4e05-9cbc-c6834de38005", "id": "ed9a0196-6c24-4e05-9cbc-c6834de38005",
"name": "notify", "name": "notify",
"displayName": "notify", "displayName": "Send notification",
"paramTypes": [ "paramTypes": [
{ {
"id": "3b5e195c-9f96-4f2f-a654-f17ed77c02ee", "id": "3b5e195c-9f96-4f2f-a654-f17ed77c02ee",
"name": "title", "name": "title",
"displayName": "title", "displayName": "Title",
"type": "QString", "type": "QString",
"inputType": "TextLine", "inputType": "TextLine",
"defaultValue": "" "defaultValue": ""
@ -53,10 +53,17 @@
{ {
"id": "074c4c7c-037f-45ac-ab2f-f7aea3f84bde", "id": "074c4c7c-037f-45ac-ab2f-f7aea3f84bde",
"name": "body", "name": "body",
"displayName": "body", "displayName": "Body",
"type": "QString", "type": "QString",
"inputType": "TextArea", "inputType": "TextArea",
"defaultValue": "" "defaultValue": ""
},
{
"id": "ca36a33f-a7f2-4f59-8767-3522ecaaf8fb",
"name": "data",
"displayName": "Data",
"type": "QString",
"defaultValue": ""
} }
] ]
} }

View File

@ -1,72 +1,91 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <TS version="2.1" language="de">
<context> <context>
<name>IntegrationPluginPushNotifications</name> <name>IntegrationPluginPushNotifications</name>
<message> <message>
<location filename="../integrationpluginpushnotifications.cpp" line="71"/> <location filename="../integrationpluginpushnotifications.cpp" line="99"/>
<source>The token must not be empty.</source> <source>The token must not be empty.</source>
<extracomment>Error setting up thing</extracomment> <extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation> <translation>Das Token darf nicht leer sein.</translation>
</message> </message>
<message> <message>
<location filename="../integrationpluginpushnotifications.cpp" line="76"/> <location filename="../integrationpluginpushnotifications.cpp" line="93"/>
<source>The push service must not be empty.</source> <source>The push service must not be empty.</source>
<extracomment>Error setting up thing</extracomment> <extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation> <translation>Der Push-Benachrichtigungsdienst darf nicht leer sein.</translation>
</message> </message>
<message> <message>
<location filename="../integrationpluginpushnotifications.cpp" line="96"/> <location filename="../integrationpluginpushnotifications.cpp" line="106"/>
<location filename="../integrationpluginpushnotifications.cpp" line="146"/>
<source>Firebase server API key not installed.</source>
<extracomment>Error setting up thing</extracomment>
<translation>Das API-Token für den Firebase Server ist nicht installiert.</translation>
</message>
<message>
<location filename="../integrationpluginpushnotifications.cpp" line="127"/>
<source>Push notifications need to be reconfigured.</source> <source>Push notifications need to be reconfigured.</source>
<translation type="unfinished"></translation> <translation>Push Notifications müssen erneut eingerichtet werden.</translation>
</message> </message>
</context> </context>
<context> <context>
<name>pushNotifications</name> <name>pushNotifications</name>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="28"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="35"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="31"/> <source>Access token</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f})</extracomment>
<translation>Zugrangs-Token</translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="38"/>
<source>Body</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde})</extracomment>
<translation>Benachrichtigungstext</translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="41"/>
<source>Client ID</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {d76da367-64e3-4b7d-aa84-c96b3acfb65e})</extracomment>
<translation>Client ID</translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="44"/>
<source>Data</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {ca36a33f-a7f2-4f59-8767-3522ecaaf8fb})</extracomment>
<translation>Daten</translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="47"/>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="50"/>
<source>Push Notifications</source> <source>Push Notifications</source>
<extracomment>The name of the ThingClass ({f0dd4c03-0aca-42cc-8f34-9902457b05de}) <extracomment>The name of the ThingClass ({f0dd4c03-0aca-42cc-8f34-9902457b05de})
---------- ----------
The name of the plugin pushNotifications ({fdcea3b3-8d79-4fbb-8101-1ab45d71cedb})</extracomment> The name of the plugin pushNotifications ({fdcea3b3-8d79-4fbb-8101-1ab45d71cedb})</extracomment>
<translation type="unfinished"></translation> <translation>Push-Benachrichtigungen</translation>
</message> </message>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="34"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="53"/>
<source>Push service</source> <source>Push service</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {3cb8e30e-2ec5-4b4b-8c8c-03eaf7876839})</extracomment> <extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {3cb8e30e-2ec5-4b4b-8c8c-03eaf7876839})</extracomment>
<translation type="unfinished"></translation> <translation>Push-Benachrichtigungsdiesnt</translation>
</message> </message>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="37"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="56"/>
<source>access token</source> <source>Send notification</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="40"/>
<source>body</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="43"/>
<source>notify</source>
<extracomment>The name of the ActionType ({ed9a0196-6c24-4e05-9cbc-c6834de38005}) of ThingClass pushNotifications</extracomment> <extracomment>The name of the ActionType ({ed9a0196-6c24-4e05-9cbc-c6834de38005}) of ThingClass pushNotifications</extracomment>
<translation type="unfinished"></translation> <translation>Benachrichtigung senden</translation>
</message> </message>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="46"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="59"/>
<source>Title</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee})</extracomment>
<translation>Titel</translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="62"/>
<source>nymea GmbH</source> <source>nymea GmbH</source>
<extracomment>The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6})</extracomment> <extracomment>The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6})</extracomment>
<translation type="unfinished"></translation> <translation>nymea GmbH</translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="49"/>
<source>title</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee})</extracomment>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
</TS> </TS>

View File

@ -4,19 +4,26 @@
<context> <context>
<name>IntegrationPluginPushNotifications</name> <name>IntegrationPluginPushNotifications</name>
<message> <message>
<location filename="../integrationpluginpushnotifications.cpp" line="71"/> <location filename="../integrationpluginpushnotifications.cpp" line="99"/>
<source>The token must not be empty.</source> <source>The token must not be empty.</source>
<extracomment>Error setting up thing</extracomment> <extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../integrationpluginpushnotifications.cpp" line="76"/> <location filename="../integrationpluginpushnotifications.cpp" line="93"/>
<source>The push service must not be empty.</source> <source>The push service must not be empty.</source>
<extracomment>Error setting up thing</extracomment> <extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../integrationpluginpushnotifications.cpp" line="96"/> <location filename="../integrationpluginpushnotifications.cpp" line="106"/>
<location filename="../integrationpluginpushnotifications.cpp" line="146"/>
<source>Firebase server API key not installed.</source>
<extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginpushnotifications.cpp" line="127"/>
<source>Push notifications need to be reconfigured.</source> <source>Push notifications need to be reconfigured.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -24,8 +31,32 @@
<context> <context>
<name>pushNotifications</name> <name>pushNotifications</name>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="28"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="35"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="31"/> <source>Access token</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="38"/>
<source>Body</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="41"/>
<source>Client ID</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {d76da367-64e3-4b7d-aa84-c96b3acfb65e})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="44"/>
<source>Data</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {ca36a33f-a7f2-4f59-8767-3522ecaaf8fb})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="47"/>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="50"/>
<source>Push Notifications</source> <source>Push Notifications</source>
<extracomment>The name of the ThingClass ({f0dd4c03-0aca-42cc-8f34-9902457b05de}) <extracomment>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}
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="34"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="53"/>
<source>Push service</source> <source>Push service</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {3cb8e30e-2ec5-4b4b-8c8c-03eaf7876839})</extracomment> <extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {3cb8e30e-2ec5-4b4b-8c8c-03eaf7876839})</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="37"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="56"/>
<source>access token</source> <source>Send notification</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, Type: thing, ID: {12ec06b2-44e7-486a-9169-31c684b91c8f})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="40"/>
<source>body</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {074c4c7c-037f-45ac-ab2f-f7aea3f84bde})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="43"/>
<source>notify</source>
<extracomment>The name of the ActionType ({ed9a0196-6c24-4e05-9cbc-c6834de38005}) of ThingClass pushNotifications</extracomment> <extracomment>The name of the ActionType ({ed9a0196-6c24-4e05-9cbc-c6834de38005}) of ThingClass pushNotifications</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="46"/> <location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="59"/>
<source>Title</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build/nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="62"/>
<source>nymea GmbH</source> <source>nymea GmbH</source>
<extracomment>The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6})</extracomment> <extracomment>The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6})</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/pushnotifications/plugininfo.h" line="49"/>
<source>title</source>
<extracomment>The name of the ParamType (ThingClass: pushNotifications, ActionType: notify, ID: {3b5e195c-9f96-4f2f-a654-f17ed77c02ee})</extracomment>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>