<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.socialstack.dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2A02%3AC7C%3AC43F%3AC600%3A2505%3A4C62%3A1C31%3A494D</id>
	<title>SocialStack - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.socialstack.dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2A02%3AC7C%3AC43F%3AC600%3A2505%3A4C62%3A1C31%3A494D"/>
	<link rel="alternate" type="text/html" href="https://wiki.socialstack.dev/index.php?title=Special:Contributions/2A02:C7C:C43F:C600:2505:4C62:1C31:494D"/>
	<updated>2026-10-16T06:44:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.36.2</generator>
	<entry>
		<id>https://wiki.socialstack.dev/index.php?title=Push_Notifications&amp;diff=668</id>
		<title>Push Notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.socialstack.dev/index.php?title=Push_Notifications&amp;diff=668"/>
		<updated>2024-05-27T18:27:19Z</updated>

		<summary type="html">&lt;p&gt;2A02:C7C:C43F:C600:2505:4C62:1C31:494D: /* Add a UI handler for the messaging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Setting up firebase ==&lt;br /&gt;
=== Get the package details from your application ===&lt;br /&gt;
&lt;br /&gt;
Get the package name from the cordova config.xml&lt;br /&gt;
&lt;br /&gt;
for example &amp;lt;widget android-packageName=&amp;quot;com.thermomix.comapp&amp;quot; id=&amp;quot;com.thermomix.comapp&amp;quot; version=&amp;quot;1.0.0&amp;quot; xmlns=&amp;quot;http://www.w3.org/ns/widgets&amp;quot; xmlns:android=&amp;quot;http://schemas.android.com/apk/res/android&amp;quot; xmlns:cdv=&amp;quot;http://cordova.apache.org/ns/1.0&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So in this case &amp;quot;com.thermomix.comapp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Setup a new project in firebase ===&lt;br /&gt;
&lt;br /&gt;
https://firebase.google.com/docs/android/setup&lt;br /&gt;
&lt;br /&gt;
Create apps for ios, android and web as required&lt;br /&gt;
&lt;br /&gt;
=== Update your application ===&lt;br /&gt;
&lt;br /&gt;
Add the following plugin into the config.xml in the App folder&lt;br /&gt;
&lt;br /&gt;
&amp;lt;plugin name=&amp;quot;cordova-plugin-firebase-messaging&amp;quot; spec=&amp;quot;~4.3.1&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;variable name=&amp;quot;FIREBASE_MESSAGING_VERSION&amp;quot; value=&amp;quot;20.1.+&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;variable name=&amp;quot;ANDROIDX_CORE_VERSION&amp;quot; value=&amp;quot;1.0.+&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/plugin&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get the firebase config files ===&lt;br /&gt;
&lt;br /&gt;
See https://support.google.com/firebase/answer/7015592?hl=en#zippy=%2Cin-this-article for more info but basically&lt;br /&gt;
&lt;br /&gt;
Edit the config.xml in the App folder&lt;br /&gt;
&lt;br /&gt;
within platform name = andriod&lt;br /&gt;
&lt;br /&gt;
&amp;lt;resource-file src=&amp;quot;google-services.json&amp;quot; target=&amp;quot;app/google-services.json&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
within platform name = ios&lt;br /&gt;
&lt;br /&gt;
&amp;lt;resource-file src=&amp;quot;GoogleService-Info.plist&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download the 2 config files from the firebase application and copy then into the App folder containing the cordova config&lt;br /&gt;
&lt;br /&gt;
Get a copy of firebase-messaging-sw.js and copy it into the UI/public folder&lt;br /&gt;
&lt;br /&gt;
=== Pull in the required javascript files ===&lt;br /&gt;
&lt;br /&gt;
Update the htmlservice config to include &lt;br /&gt;
&lt;br /&gt;
  &amp;quot;EndHeadScripts&amp;quot;: [&lt;br /&gt;
      {&lt;br /&gt;
          &amp;quot;type&amp;quot; : &amp;quot;text/javascript&amp;quot;,&lt;br /&gt;
          &amp;quot;src&amp;quot; : &amp;quot;https://www.gstatic.com/firebasejs/7.14.0/firebase-app.js&amp;quot;&lt;br /&gt;
      },&lt;br /&gt;
      {&lt;br /&gt;
          &amp;quot;type&amp;quot; : &amp;quot;text/javascript&amp;quot;,&lt;br /&gt;
          &amp;quot;src&amp;quot;: &amp;quot;https://www.gstatic.com/firebasejs/7.14.0/firebase-messaging.js&amp;quot;&lt;br /&gt;
      }&lt;br /&gt;
      ],&lt;br /&gt;
&lt;br /&gt;
=== Add a UI handler for the messaging ===&lt;br /&gt;
&lt;br /&gt;
Install the push notifications UI module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
socialstack install UI/PushNotifications&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This module has the main job of registering for push notifications when the device is either in a native app or via the web. A device on the web will see the permission request for push notifications.&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll need to edit the PushNotifications.js file to include the correct firebase config from the web application. This config is primarily used when your site is running from the web.&lt;br /&gt;
&lt;br /&gt;
=== Add a settings page to your local wep app ===&lt;br /&gt;
&lt;br /&gt;
This will allow you to test the token refresh process in a webapp, and quickly confirm that all looks ok&lt;br /&gt;
&lt;br /&gt;
You need to add a page with the following component&lt;br /&gt;
&lt;br /&gt;
UI/PushSettings&lt;br /&gt;
{\n\t\&amp;quot;c\&amp;quot;: {\n\t\t\&amp;quot;t\&amp;quot;: \&amp;quot;UI/PushSettings\&amp;quot;,\n\t\t\&amp;quot;d\&amp;quot;: {},\n\t\t\&amp;quot;i\&amp;quot;: 2\n\t},\n\t\&amp;quot;i\&amp;quot;: 3\n}&lt;br /&gt;
&lt;br /&gt;
Once added, when you visit the page it should try and get a token from firebase and then send an update to the community via /api.ashx/v2/mwa/user/device/add.json&lt;br /&gt;
&lt;br /&gt;
This will add a device entry to the community and allow notifications to be passed back to the web app&lt;br /&gt;
&lt;br /&gt;
There are some console log entries to confirm it has been added&lt;br /&gt;
&lt;br /&gt;
=== First Test Time To Get The Client Key ===&lt;br /&gt;
&lt;br /&gt;
If all goes well, you should now be able to get a key in PushNotifications.js&lt;br /&gt;
&lt;br /&gt;
see section&lt;br /&gt;
&lt;br /&gt;
.then((currentToken)&lt;br /&gt;
&lt;br /&gt;
You should get some data looking like this, the key can then be used in your backend to send notifications to the web app&lt;br /&gt;
&lt;br /&gt;
notificationKey&lt;br /&gt;
&lt;br /&gt;
xxxxxxxxxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&lt;br /&gt;
&lt;br /&gt;
notificationKeyType&lt;br /&gt;
&lt;br /&gt;
web&lt;br /&gt;
&lt;br /&gt;
=== Backend Authentication ===&lt;br /&gt;
&lt;br /&gt;
Create a service account via https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts?supportedpurview=project&lt;br /&gt;
&lt;br /&gt;
Choose the application&lt;br /&gt;
&lt;br /&gt;
Click on the service account (will initial say no keys under key id)&lt;br /&gt;
&lt;br /&gt;
Click on keys&lt;br /&gt;
&lt;br /&gt;
Create a new key (export as json) and copy the contents into the mwa core config -&amp;gt; messaging&lt;br /&gt;
&lt;br /&gt;
The key should look something like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;type&amp;quot;: &amp;quot;service_account&amp;quot;,&lt;br /&gt;
  &amp;quot;project_id&amp;quot;: &amp;quot;com-theintelligence-app&amp;quot;,&lt;br /&gt;
  &amp;quot;private_key_id&amp;quot;: &amp;quot;31dc7cc70581a64dd2fdcb8df2d6179b018a9698&amp;quot;,&lt;br /&gt;
  &amp;quot;private_key&amp;quot;: &amp;quot;-----BEGIN PRIVATE KEY-----xxxxxxxxxxxxxxxxxxxx\n-----END PRIVATE KEY-----\n&amp;quot;,&lt;br /&gt;
  &amp;quot;client_email&amp;quot;: &amp;quot;firebase-adminsdk-jgnr7@com-theintelligence-app.iam.gserviceaccount.com&amp;quot;,&lt;br /&gt;
  &amp;quot;client_id&amp;quot;: &amp;quot;108818059171631247824&amp;quot;,&lt;br /&gt;
  &amp;quot;auth_uri&amp;quot;: &amp;quot;https://accounts.google.com/o/oauth2/auth&amp;quot;,&lt;br /&gt;
  &amp;quot;token_uri&amp;quot;: &amp;quot;https://oauth2.googleapis.com/token&amp;quot;,&lt;br /&gt;
  &amp;quot;auth_provider_x509_cert_url&amp;quot;: &amp;quot;https://www.googleapis.com/oauth2/v1/certs&amp;quot;,&lt;br /&gt;
  &amp;quot;client_x509_cert_url&amp;quot;: &amp;quot;https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-jgnr7%40com-theintelligence-app.iam.gserviceaccount.com&amp;quot;&lt;br /&gt;
?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backend Integration ===&lt;br /&gt;
&lt;br /&gt;
Start by installing the push notifications module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
socialstack install Api/PushNotifications&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This module creates the UserDevice type and also provides the PushNotificationService which can be used to send push notifications to target devices.&lt;br /&gt;
&lt;br /&gt;
Internally the PushNotificationService batches notifications together so can be used for large amounts of push notification traffic too.&lt;br /&gt;
&lt;br /&gt;
=== IOS APNS Key Setup ===&lt;br /&gt;
&lt;br /&gt;
To access iOS clients you will need to get a key from the Apple developer site and upload it into firebase:&lt;br /&gt;
&lt;br /&gt;
https://learn.buildfire.com/en/articles/5760994-how-to-set-up-your-apple-push-notification-key-for-your-ios-firebase-certificate#:~:text=How%20do%20I%20upload%20my%20APNs%20key%20to,Step%203.%20Click%20on%20Certificates%2C%20IDs%20%26%20Profiles&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
see the devops projects THE-APP-MCP AND THE-APP-MAP&lt;/div&gt;</summary>
		<author><name>2A02:C7C:C43F:C600:2505:4C62:1C31:494D</name></author>
	</entry>
	<entry>
		<id>https://wiki.socialstack.dev/index.php?title=Push_Notifications&amp;diff=667</id>
		<title>Push Notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.socialstack.dev/index.php?title=Push_Notifications&amp;diff=667"/>
		<updated>2024-05-27T18:16:42Z</updated>

		<summary type="html">&lt;p&gt;2A02:C7C:C43F:C600:2505:4C62:1C31:494D: /* Backend Integration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Setting up firebase ==&lt;br /&gt;
=== Get the package details from your application ===&lt;br /&gt;
&lt;br /&gt;
Get the package name from the cordova config.xml&lt;br /&gt;
&lt;br /&gt;
for example &amp;lt;widget android-packageName=&amp;quot;com.thermomix.comapp&amp;quot; id=&amp;quot;com.thermomix.comapp&amp;quot; version=&amp;quot;1.0.0&amp;quot; xmlns=&amp;quot;http://www.w3.org/ns/widgets&amp;quot; xmlns:android=&amp;quot;http://schemas.android.com/apk/res/android&amp;quot; xmlns:cdv=&amp;quot;http://cordova.apache.org/ns/1.0&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So in this case &amp;quot;com.thermomix.comapp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Setup a new project in firebase ===&lt;br /&gt;
&lt;br /&gt;
https://firebase.google.com/docs/android/setup&lt;br /&gt;
&lt;br /&gt;
Create apps for ios, android and web as required&lt;br /&gt;
&lt;br /&gt;
=== Update your application ===&lt;br /&gt;
&lt;br /&gt;
Add the following plugin into the config.xml in the App folder&lt;br /&gt;
&lt;br /&gt;
&amp;lt;plugin name=&amp;quot;cordova-plugin-firebase-messaging&amp;quot; spec=&amp;quot;~4.3.1&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;variable name=&amp;quot;FIREBASE_MESSAGING_VERSION&amp;quot; value=&amp;quot;20.1.+&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;variable name=&amp;quot;ANDROIDX_CORE_VERSION&amp;quot; value=&amp;quot;1.0.+&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/plugin&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get the firebase config files ===&lt;br /&gt;
&lt;br /&gt;
See https://support.google.com/firebase/answer/7015592?hl=en#zippy=%2Cin-this-article for more info but basically&lt;br /&gt;
&lt;br /&gt;
Edit the config.xml in the App folder&lt;br /&gt;
&lt;br /&gt;
within platform name = andriod&lt;br /&gt;
&lt;br /&gt;
&amp;lt;resource-file src=&amp;quot;google-services.json&amp;quot; target=&amp;quot;app/google-services.json&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
within platform name = ios&lt;br /&gt;
&lt;br /&gt;
&amp;lt;resource-file src=&amp;quot;GoogleService-Info.plist&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download the 2 config files from the firebase application and copy then into the App folder containing the cordova config&lt;br /&gt;
&lt;br /&gt;
Get a copy of firebase-messaging-sw.js and copy it into the UI/public folder&lt;br /&gt;
&lt;br /&gt;
=== Pull in the required javascript files ===&lt;br /&gt;
&lt;br /&gt;
Update the htmlservice config to include &lt;br /&gt;
&lt;br /&gt;
  &amp;quot;EndHeadScripts&amp;quot;: [&lt;br /&gt;
      {&lt;br /&gt;
          &amp;quot;type&amp;quot; : &amp;quot;text/javascript&amp;quot;,&lt;br /&gt;
          &amp;quot;src&amp;quot; : &amp;quot;https://www.gstatic.com/firebasejs/7.14.0/firebase-app.js&amp;quot;&lt;br /&gt;
      },&lt;br /&gt;
      {&lt;br /&gt;
          &amp;quot;type&amp;quot; : &amp;quot;text/javascript&amp;quot;,&lt;br /&gt;
          &amp;quot;src&amp;quot;: &amp;quot;https://www.gstatic.com/firebasejs/7.14.0/firebase-messaging.js&amp;quot;&lt;br /&gt;
      }&lt;br /&gt;
      ],&lt;br /&gt;
&lt;br /&gt;
=== Add a UI handler for the messaging ===&lt;br /&gt;
&lt;br /&gt;
Find an existing example in devops &lt;br /&gt;
&lt;br /&gt;
UI/PushNotifications&lt;br /&gt;
&lt;br /&gt;
Alter the PushRegister.js file to include the correct firebase config from the web application (see THE-COM-MAP for an example), this will be used to get a key in web mode and allow for quick testing of your backend&lt;br /&gt;
&lt;br /&gt;
=== Add a settings page to your local wep app ===&lt;br /&gt;
&lt;br /&gt;
This will allow you to test the token refresh process in a webapp, and quickly confirm that all looks ok&lt;br /&gt;
&lt;br /&gt;
You need to add a page with the following component&lt;br /&gt;
&lt;br /&gt;
UI/PushSettings&lt;br /&gt;
{\n\t\&amp;quot;c\&amp;quot;: {\n\t\t\&amp;quot;t\&amp;quot;: \&amp;quot;UI/PushSettings\&amp;quot;,\n\t\t\&amp;quot;d\&amp;quot;: {},\n\t\t\&amp;quot;i\&amp;quot;: 2\n\t},\n\t\&amp;quot;i\&amp;quot;: 3\n}&lt;br /&gt;
&lt;br /&gt;
Once added, when you visit the page it should try and get a token from firebase and then send an update to the community via /api.ashx/v2/mwa/user/device/add.json&lt;br /&gt;
&lt;br /&gt;
This will add a device entry to the community and allow notifications to be passed back to the web app&lt;br /&gt;
&lt;br /&gt;
There are some console log entries to confirm it has been added&lt;br /&gt;
&lt;br /&gt;
=== First Test Time To Get The Client Key ===&lt;br /&gt;
&lt;br /&gt;
If all goes well, you should now be able to get a key in PushNotifications.js&lt;br /&gt;
&lt;br /&gt;
see section&lt;br /&gt;
&lt;br /&gt;
.then((currentToken)&lt;br /&gt;
&lt;br /&gt;
You should get some data looking like this, the key can then be used in your backend to send notifications to the web app&lt;br /&gt;
&lt;br /&gt;
notificationKey&lt;br /&gt;
&lt;br /&gt;
xxxxxxxxxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&lt;br /&gt;
&lt;br /&gt;
notificationKeyType&lt;br /&gt;
&lt;br /&gt;
web&lt;br /&gt;
&lt;br /&gt;
=== Backend Authentication ===&lt;br /&gt;
&lt;br /&gt;
Create a service account via https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts?supportedpurview=project&lt;br /&gt;
&lt;br /&gt;
Choose the application&lt;br /&gt;
&lt;br /&gt;
Click on the service account (will initial say no keys under key id)&lt;br /&gt;
&lt;br /&gt;
Click on keys&lt;br /&gt;
&lt;br /&gt;
Create a new key (export as json) and copy the contents into the mwa core config -&amp;gt; messaging&lt;br /&gt;
&lt;br /&gt;
The key should look something like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;type&amp;quot;: &amp;quot;service_account&amp;quot;,&lt;br /&gt;
  &amp;quot;project_id&amp;quot;: &amp;quot;com-theintelligence-app&amp;quot;,&lt;br /&gt;
  &amp;quot;private_key_id&amp;quot;: &amp;quot;31dc7cc70581a64dd2fdcb8df2d6179b018a9698&amp;quot;,&lt;br /&gt;
  &amp;quot;private_key&amp;quot;: &amp;quot;-----BEGIN PRIVATE KEY-----xxxxxxxxxxxxxxxxxxxx\n-----END PRIVATE KEY-----\n&amp;quot;,&lt;br /&gt;
  &amp;quot;client_email&amp;quot;: &amp;quot;firebase-adminsdk-jgnr7@com-theintelligence-app.iam.gserviceaccount.com&amp;quot;,&lt;br /&gt;
  &amp;quot;client_id&amp;quot;: &amp;quot;108818059171631247824&amp;quot;,&lt;br /&gt;
  &amp;quot;auth_uri&amp;quot;: &amp;quot;https://accounts.google.com/o/oauth2/auth&amp;quot;,&lt;br /&gt;
  &amp;quot;token_uri&amp;quot;: &amp;quot;https://oauth2.googleapis.com/token&amp;quot;,&lt;br /&gt;
  &amp;quot;auth_provider_x509_cert_url&amp;quot;: &amp;quot;https://www.googleapis.com/oauth2/v1/certs&amp;quot;,&lt;br /&gt;
  &amp;quot;client_x509_cert_url&amp;quot;: &amp;quot;https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-jgnr7%40com-theintelligence-app.iam.gserviceaccount.com&amp;quot;&lt;br /&gt;
?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backend Integration ===&lt;br /&gt;
&lt;br /&gt;
Start by installing the push notifications module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
socialstack install Api/PushNotifications&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This module creates the UserDevice type and also provides the PushNotificationService which can be used to send push notifications to target devices.&lt;br /&gt;
&lt;br /&gt;
Internally the PushNotificationService batches notifications together so can be used for large amounts of push notification traffic too.&lt;br /&gt;
&lt;br /&gt;
=== IOS APNS Key Setup ===&lt;br /&gt;
&lt;br /&gt;
To access iOS clients you will need to get a key from the Apple developer site and upload it into firebase:&lt;br /&gt;
&lt;br /&gt;
https://learn.buildfire.com/en/articles/5760994-how-to-set-up-your-apple-push-notification-key-for-your-ios-firebase-certificate#:~:text=How%20do%20I%20upload%20my%20APNs%20key%20to,Step%203.%20Click%20on%20Certificates%2C%20IDs%20%26%20Profiles&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
see the devops projects THE-APP-MCP AND THE-APP-MAP&lt;/div&gt;</summary>
		<author><name>2A02:C7C:C43F:C600:2505:4C62:1C31:494D</name></author>
	</entry>
	<entry>
		<id>https://wiki.socialstack.dev/index.php?title=Push_Notifications&amp;diff=666</id>
		<title>Push Notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.socialstack.dev/index.php?title=Push_Notifications&amp;diff=666"/>
		<updated>2024-05-27T17:57:14Z</updated>

		<summary type="html">&lt;p&gt;2A02:C7C:C43F:C600:2505:4C62:1C31:494D: /* IOS APNS Key Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Setting up firebase ==&lt;br /&gt;
=== Get the package details from your application ===&lt;br /&gt;
&lt;br /&gt;
Get the package name from the cordova config.xml&lt;br /&gt;
&lt;br /&gt;
for example &amp;lt;widget android-packageName=&amp;quot;com.thermomix.comapp&amp;quot; id=&amp;quot;com.thermomix.comapp&amp;quot; version=&amp;quot;1.0.0&amp;quot; xmlns=&amp;quot;http://www.w3.org/ns/widgets&amp;quot; xmlns:android=&amp;quot;http://schemas.android.com/apk/res/android&amp;quot; xmlns:cdv=&amp;quot;http://cordova.apache.org/ns/1.0&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So in this case &amp;quot;com.thermomix.comapp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Setup a new project in firebase ===&lt;br /&gt;
&lt;br /&gt;
https://firebase.google.com/docs/android/setup&lt;br /&gt;
&lt;br /&gt;
Create apps for ios, android and web as required&lt;br /&gt;
&lt;br /&gt;
=== Update your application ===&lt;br /&gt;
&lt;br /&gt;
Add the following plugin into the config.xml in the App folder&lt;br /&gt;
&lt;br /&gt;
&amp;lt;plugin name=&amp;quot;cordova-plugin-firebase-messaging&amp;quot; spec=&amp;quot;~4.3.1&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;variable name=&amp;quot;FIREBASE_MESSAGING_VERSION&amp;quot; value=&amp;quot;20.1.+&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;variable name=&amp;quot;ANDROIDX_CORE_VERSION&amp;quot; value=&amp;quot;1.0.+&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/plugin&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get the firebase config files ===&lt;br /&gt;
&lt;br /&gt;
See https://support.google.com/firebase/answer/7015592?hl=en#zippy=%2Cin-this-article for more info but basically&lt;br /&gt;
&lt;br /&gt;
Edit the config.xml in the App folder&lt;br /&gt;
&lt;br /&gt;
within platform name = andriod&lt;br /&gt;
&lt;br /&gt;
&amp;lt;resource-file src=&amp;quot;google-services.json&amp;quot; target=&amp;quot;app/google-services.json&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
within platform name = ios&lt;br /&gt;
&lt;br /&gt;
&amp;lt;resource-file src=&amp;quot;GoogleService-Info.plist&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download the 2 config files from the firebase application and copy then into the App folder containing the cordova config&lt;br /&gt;
&lt;br /&gt;
Get a copy of firebase-messaging-sw.js and copy it into the UI/public folder&lt;br /&gt;
&lt;br /&gt;
=== Pull in the required javascript files ===&lt;br /&gt;
&lt;br /&gt;
Update the htmlservice config to include &lt;br /&gt;
&lt;br /&gt;
  &amp;quot;EndHeadScripts&amp;quot;: [&lt;br /&gt;
      {&lt;br /&gt;
          &amp;quot;type&amp;quot; : &amp;quot;text/javascript&amp;quot;,&lt;br /&gt;
          &amp;quot;src&amp;quot; : &amp;quot;https://www.gstatic.com/firebasejs/7.14.0/firebase-app.js&amp;quot;&lt;br /&gt;
      },&lt;br /&gt;
      {&lt;br /&gt;
          &amp;quot;type&amp;quot; : &amp;quot;text/javascript&amp;quot;,&lt;br /&gt;
          &amp;quot;src&amp;quot;: &amp;quot;https://www.gstatic.com/firebasejs/7.14.0/firebase-messaging.js&amp;quot;&lt;br /&gt;
      }&lt;br /&gt;
      ],&lt;br /&gt;
&lt;br /&gt;
=== Add a UI handler for the messaging ===&lt;br /&gt;
&lt;br /&gt;
Find an existing example in devops &lt;br /&gt;
&lt;br /&gt;
UI/PushNotifications&lt;br /&gt;
&lt;br /&gt;
Alter the PushRegister.js file to include the correct firebase config from the web application (see THE-COM-MAP for an example), this will be used to get a key in web mode and allow for quick testing of your backend&lt;br /&gt;
&lt;br /&gt;
=== Add a settings page to your local wep app ===&lt;br /&gt;
&lt;br /&gt;
This will allow you to test the token refresh process in a webapp, and quickly confirm that all looks ok&lt;br /&gt;
&lt;br /&gt;
You need to add a page with the following component&lt;br /&gt;
&lt;br /&gt;
UI/PushSettings&lt;br /&gt;
{\n\t\&amp;quot;c\&amp;quot;: {\n\t\t\&amp;quot;t\&amp;quot;: \&amp;quot;UI/PushSettings\&amp;quot;,\n\t\t\&amp;quot;d\&amp;quot;: {},\n\t\t\&amp;quot;i\&amp;quot;: 2\n\t},\n\t\&amp;quot;i\&amp;quot;: 3\n}&lt;br /&gt;
&lt;br /&gt;
Once added, when you visit the page it should try and get a token from firebase and then send an update to the community via /api.ashx/v2/mwa/user/device/add.json&lt;br /&gt;
&lt;br /&gt;
This will add a device entry to the community and allow notifications to be passed back to the web app&lt;br /&gt;
&lt;br /&gt;
There are some console log entries to confirm it has been added&lt;br /&gt;
&lt;br /&gt;
=== First Test Time To Get The Client Key ===&lt;br /&gt;
&lt;br /&gt;
If all goes well, you should now be able to get a key in PushNotifications.js&lt;br /&gt;
&lt;br /&gt;
see section&lt;br /&gt;
&lt;br /&gt;
.then((currentToken)&lt;br /&gt;
&lt;br /&gt;
You should get some data looking like this, the key can then be used in your backend to send notifications to the web app&lt;br /&gt;
&lt;br /&gt;
notificationKey&lt;br /&gt;
&lt;br /&gt;
xxxxxxxxxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&lt;br /&gt;
&lt;br /&gt;
notificationKeyType&lt;br /&gt;
&lt;br /&gt;
web&lt;br /&gt;
&lt;br /&gt;
=== Backend Authentication ===&lt;br /&gt;
&lt;br /&gt;
Create a service account via https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts?supportedpurview=project&lt;br /&gt;
&lt;br /&gt;
Choose the application&lt;br /&gt;
&lt;br /&gt;
Click on the service account (will initial say no keys under key id)&lt;br /&gt;
&lt;br /&gt;
Click on keys&lt;br /&gt;
&lt;br /&gt;
Create a new key (export as json) and copy the contents into the mwa core config -&amp;gt; messaging&lt;br /&gt;
&lt;br /&gt;
The key should look something like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;type&amp;quot;: &amp;quot;service_account&amp;quot;,&lt;br /&gt;
  &amp;quot;project_id&amp;quot;: &amp;quot;com-theintelligence-app&amp;quot;,&lt;br /&gt;
  &amp;quot;private_key_id&amp;quot;: &amp;quot;31dc7cc70581a64dd2fdcb8df2d6179b018a9698&amp;quot;,&lt;br /&gt;
  &amp;quot;private_key&amp;quot;: &amp;quot;-----BEGIN PRIVATE KEY-----xxxxxxxxxxxxxxxxxxxx\n-----END PRIVATE KEY-----\n&amp;quot;,&lt;br /&gt;
  &amp;quot;client_email&amp;quot;: &amp;quot;firebase-adminsdk-jgnr7@com-theintelligence-app.iam.gserviceaccount.com&amp;quot;,&lt;br /&gt;
  &amp;quot;client_id&amp;quot;: &amp;quot;108818059171631247824&amp;quot;,&lt;br /&gt;
  &amp;quot;auth_uri&amp;quot;: &amp;quot;https://accounts.google.com/o/oauth2/auth&amp;quot;,&lt;br /&gt;
  &amp;quot;token_uri&amp;quot;: &amp;quot;https://oauth2.googleapis.com/token&amp;quot;,&lt;br /&gt;
  &amp;quot;auth_provider_x509_cert_url&amp;quot;: &amp;quot;https://www.googleapis.com/oauth2/v1/certs&amp;quot;,&lt;br /&gt;
  &amp;quot;client_x509_cert_url&amp;quot;: &amp;quot;https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-jgnr7%40com-theintelligence-app.iam.gserviceaccount.com&amp;quot;&lt;br /&gt;
?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backend Integration ===&lt;br /&gt;
&lt;br /&gt;
Using the client key you should be able to create a simple c# app using the firebase nuget package to send a test message&lt;br /&gt;
&lt;br /&gt;
https://github.com/Firebase/firebase-admin-dotnet&lt;br /&gt;
&lt;br /&gt;
or see the repo &lt;br /&gt;
&lt;br /&gt;
https://4-roads.visualstudio.com/INT-TEL-APP&lt;br /&gt;
&lt;br /&gt;
The webapp communicates via a rest api &lt;br /&gt;
&lt;br /&gt;
https://{hostname}/api.ashx/v2/mwa/user/device/add &lt;br /&gt;
&lt;br /&gt;
All requests are logged to the community event log if you look for category &amp;quot;MWA Notifications&amp;quot;, so you should be able to see them coming in from the app &lt;br /&gt;
&lt;br /&gt;
By default the community mwa extension will forward any community notifications to the app via firebase if the user has a valid key, which are stored in extended attributes of the user account&lt;br /&gt;
&lt;br /&gt;
=== IOS APNS Key Setup ===&lt;br /&gt;
&lt;br /&gt;
To access iOS clients you will need to get a key from the Apple developer site and upload it into firebase:&lt;br /&gt;
&lt;br /&gt;
https://learn.buildfire.com/en/articles/5760994-how-to-set-up-your-apple-push-notification-key-for-your-ios-firebase-certificate#:~:text=How%20do%20I%20upload%20my%20APNs%20key%20to,Step%203.%20Click%20on%20Certificates%2C%20IDs%20%26%20Profiles&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
see the devops projects THE-APP-MCP AND THE-APP-MAP&lt;/div&gt;</summary>
		<author><name>2A02:C7C:C43F:C600:2505:4C62:1C31:494D</name></author>
	</entry>
</feed>