Airnotifier for custom Moodle App

Airnotifier for custom Moodle App

by Egor Strelnikov -
Number of replies: 36

Hello. I have problem with airnotifier. I've created airnotifier server and link it to moodle site

moodle settings

I've created Firebase Cloud Messaging account from where i get project id and json key and insert in airnotifield setting

FCM

Also i've created certificate file .pem and privatekey for APN and added it to settings. Then launched apn server.

But even my broadcast doesnt work. When im trying to send message in moodle site from one user to other, airnotifier creates few tokens and logs show that notification sent (at least created). But it's strange message length there and push notification doesnt income on any devices.

tokens

logs

So push notifications dont work. Help how to fix it. What should i do?

Average of ratings: -
In reply to Egor Strelnikov

Re: Airnotifier for custom Moodle App

by Ardian Deari -
Exactly the same problem, any help here?
Additionally, in the android customized app... the notifications (silent notifications without vibration) come when the app is not loaded... if the app is loaded then it crashes working... I have no idea where the problem stands...
In reply to Egor Strelnikov

Re: Airnotifier for custom Moodle App

by Anil Sonune -

hi, 

i am facing exact problem. I installed  airnotifier3 . log shows exact same. no push messages working. 

Please help 

Attachment moodle_forum.JPG
In reply to Anil Sonune

Re: Airnotifier for custom Moodle App

by Ardian Deari -
I believe we are facing some issues inside the app, if you try to send cloud message from firebase console it works! I have no idea what is happening... someone could help us here please!
In reply to Ardian Deari

Re: Airnotifier for custom Moodle App

by Anil Sonune -
Yes, when message sent from firebase console it works
In reply to Anil Sonune

Re: Airnotifier for custom Moodle App

by Yogesh Patel -
Hello Anil
How are you?

Have you got any solution for this?
In reply to Ardian Deari

Trả lời: Re: Airnotifier for custom Moodle App

by Nguyễn Tủn Channel -
How to send cloud message from firebase console . Can you guide me ?


Is it this?

I just send notification by firebase console  but the app crashed like this: 


In reply to Anil Sonune

Re: Airnotifier for custom Moodle App

by Johnny Sørensen -

Anil or Ardian could you please tell how you at least got your Airnotifier to show tokens and logs? My Airnotifier panel is completely empty no matter how much I try generating push notifications - no logs, no tokens, nothing... and of course no push notifications.

 

Here are the steps I took:

0) Build an .apk file with everything left at default - NOTHING changed in the code files or config files at all. I used:

        1) npm run ionic:build -- --prod

        2) cordova build android --release

3) Signed the .apk file using jarsigner.exe

4) installed the .apk on my phone. After this this step the app works perfectly - except for push notifications smile

5) Created a standard 5$/month node at DigitalOcean where the Airnotifier server will run. Ubuntu 18.04.3 (LTS) x64 was chosen as the base image

6) SSH into it using putty and ran the following commands:

7) git clone -b 2.x git://github.com/airnotifier/airnotifier.git airnotifier

8) cd airnotifier git checkout 2.x

9) sudo mkdir -p /var/airnotifier/pemdir

10) rename config.py-sample to config.py

11) Change first line in config.py to: https = False

12) Add this line in config.py: pemdir = "/var/airnotifier/pemdir"

Install missing dependencies:

        13) sudo apt-get update

        14) sudo apt-get install python3-pip build-essential git

        15) sudo apt-get install -y mongodb

        16) pip3 install pymongo

        17) pip3 install tornado

        18) pip3 install oauth2client

Install the Airnotifier server

        19) python3 install.py

Run it

        20) python3 app.py

21) Accessed the server through the browser and logged into the admin panel

22) Click "Create"

23) Enter some chosen application name

24) Enter Firebase Project ID and the JSON key contents from my console.firebase.google.com admin panel

25) Went to Site administration > Messaging > Mobile in my moodle site and entered:

        26) Airnotifier URL: http://[my DigitalOcean server public IP]

        27) Airnotifier port: 8801

        29) Mobile app name: left unchanged

        30) Airnotifier app name: the application name I choose previously

        31) Airnotifier access key: generated this in the airnotifier admin panel under "Access keys". Just ticked off all permisions listed.

32) Logged into my moodle site and message the user who is logged into the app that I build. This would normally generate a push notification, but nothing happens. No Airnotifier logs either…

I also tried with version v3.0.0-alpha.2, but it made no difference.

 

BTW. did you add your app to Firebase under "my apps"? I think this is might be required, but correct me if I am wrong.

1) Go to the bottom of page https://console.firebase.google.com/u/0/project/[your project id]/settings) and click the android option

2) Follow the wizard: enter your app details, download the generated google-services.json file and replace it with the one in your project root and then finally update your build.gradle files

Average of ratings: Useful (1)
In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Ardian Deari -
As far as I can see you problem stands here:
cd ~
git clone -b master git://github.com/airnotifier/airnotifier.git airnotifier
cd airnotifier
pipenv install --deploy

master branch...try this one. (ubuntu 18) follow the directions here https://github.com/airnotifier/airnotifier/wiki/Installation-3.x
btw I have tried everything but the problem is we end up in notifications with no sound
when we receive notifications the app crashes if it's open,,,

All the best,
Average of ratings: Useful (1)
In reply to Ardian Deari

Re: Airnotifier for custom Moodle App

by Johnny Sørensen -
Thank you. I'll post here if I get it working
In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Ardian Deari -
Hi Johnny, did it work and did you receive notifications on your app? If yes, please share it with us...
In reply to Ardian Deari

Re: Airnotifier for custom Moodle App

by Johnny Sørensen -

Thank you for your help Ardian. I hope we can crack this nut together, since the Moodle team seem awfully quiet when it comes to Airnotifier related questions (which wouldn't be that big of a problem, if only the documentation wasn't so awful).

I've progressed to the point, where I got the master branch of Airnotifier up and running. I am also now able to send push notifications (with sound) from the firebase "Cloud Messaging" panel in https://console.firebase.google.com/. Nice!

But my Airnotifier is still completely blank with no logs or tokens at all. No sign of activity... Just how did you manage to get tokens and logs registered? Again, I will list all the exact steps I took, and I hope you can point out what you did differently 😊

Installing Airnotiifier

Starting from a completely fresh DigitalOcean ubuntu 18.04.3 (LTS) x64 server. The mobile app was compiled with all files (including config.json) left at default (untouched), except for the changes in step 19.

Install required packages

  1. sudo apt-get update
  2. sudo apt-get install python3-pip build-essential git
  3. sudo apt-get install -y mongodb
  4. pip3 install pipenv --user

Download airnotifier master branch

  1. git clone -b master git://github.com/airnotifier/airnotifier.git airnotifier
  2. cd airnotifier
  3. mv config.py-sample config.py

Setup virtual environment

  1. python3 -m pipenv install --deploy

Install and run Airnotifier inside the virtual environment

  1. python3 -m pipenv run ./install.py
  2. sudo python3 -m pipenv run ./app.py

Note: I did not install any certificates, and I used HTTP (not HTTPS) when referring to the Airnotifier server address.

Setting up Airnotifier

  1. Access the Airnotifier server in the browser
  2. Log in with
    1. Username: admin@airnotifier
    2. Password: admin@airnotifier
  3. Created an app and gave it a random name as ID. I gave it: najmapp. I left "OrgId" to the default value of 0.
  4. Clicked "Save"
  5. Enter the FCM Project ID and JSON key:
    1. Logged into my firebase account and create a new project
    2. Got the Project ID from firebase.google.com/u/0/project/[PROJECT ID]/settings/general
    3. Got the JSON key file from "Project settings" => "Service accounts" => "Generate the private key". Copy-pasted the whole file content into the textfield.
  6. I left the fields for APNs and WNS empty

Integrating Airnotifier with my Moodle site

  1. Went to “Site administration” => “Messaging” => “Mobile” in my moodle site and entered:
    1. Airnotifier URL: http://[my server public IP]
    2. Airnotifier port: 8801
    3. Mobile app name: left uchanged
    4. Airnotifier app name: the application name I choose previously
    5. Airnotifier access key: generated this in the Airnotifier admin panel under "Access keys" (just ticked off all permissions listed)

Integrating my mobile app with FCM

  1. Added the app to the Firebase control panel (android app).
  2. Followed the wizard:
    1. Android package name: com.moodle.moodlemobile
    2. SHA-1: generated this using keytool.exe and my .keystore file
    3. Downloaded the generated google-services.json file and inserted it into my project root.
    4. Updated the following files with the shown lines of code:
      1. platforms\android\build.gradle
      2. platforms\android\app\build.gradle.
    5. However, I had to go to platforms\android\cordova-support-google-services\moodlemobile-build.gradle and comment out the following line to prevent an error during compilation:
      1. apply plugin: com.google.gms.googleservices.GoogleServicesPlugin.
    6. I had to leave out inserting the analytics code line, as this caused an error during compilation.
    7. Recompiled the apk
  3. The final step, where you had to install and run the compiled apk and wait for it to connect to the firebase server, never worked, so I just skipped that step.

 

  1. Logged into my moodle site and messaged the user who is logged into the app. No push notification, no Airnotifier log or tokens created. Nothing.

Here is a picture of my Airnotifier and moodle site settings:



In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Ardian Deari -
Now install your apk to your android,
try to login with a test-user and send a message from moodle web to your test user (you are logged-in to your moodle mobile), you should be able to see logs and tokens....
The problem stands for sound and vibration... I have no idea what could it be but sooner or later we will find out the problem...
In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Ahmed Samy -
have you been able to get it to work ?
In reply to Ahmed Samy

Re: Airnotifier for custom Moodle App

by Ardian Deari -
On android version it works only on silent mode... I cannot activate sound/vibration.... otherwise, it works perfectly well... soon we will find out it...
In reply to Ardian Deari

Re: Airnotifier for custom Moodle App

by Ahmed Samy -
Did you clone the master branch of AirNotifier as mentioned in their docs (installation 3.x) ? because Moodle docs say that their own fork of AirNotifier should be used ...

I am currently stuck at making Moodle send tokens to my installed AirNotifier server ... I tested the API manually and it works fine but still for some reason Moodle doesn't send the tokens to the server. Can you help with that ?
In reply to Ardian Deari

Re: Airnotifier for custom Moodle App

by Timothy Dillan -
Hi everyone. I'm also trying to send push notifications using Airnotifier, but it doesn't work. 

What I've done so far:


VPS/SERVER SIDE:
Installed Python:
sudo apt-get install python3-pip build-essential git
pip3 install pipenv --user

Installed and started MongoDB:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
sudo systemctl unmask mongod
sudo service mongod start

Downloaded and ran Airnotifier:
cd ~
git clone -b master git://github.com/airnotifier/airnotifier.git airnotifier
cd airnotifier
pipenv install --deploy
mv config.py-sample config.py
sudo python3 -m pipenv run ./app.py

Created an App:
orgID = 0
Name of app = CHClassroom
Entered FCM Project ID and Json Key, APN and WNS empty.

Moodle Integration:
Airnotifier URL: https://[my_airnotifier_ip_addr]
Airnotifier Port: 8801
Mobile app name: com.ch.moodlemobile
Airnotifier app name: CHClassroom
Airnotifier Access Key: generated an access key with all permissions given, and pasted it into the airnotifier access key field in Moodle.

APP SIDE:
Building the App:
Changed the App name
Changed the App id
Changed the siteurl
Build using -> ionic cordova build android
Run using -> npm run dev:android
App successfully executed and I'm able to log in

Testing Airnotifier:
Went to broadcast, and entered a message
Clicked sent
No notifications, no logs, no tokens.

Any help is appreciated.

In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Johnny Sørensen -
Just an update: I managed to get it to work (with the exact above steps), as soon as I:
* Created a fresh empty moodle install on another server host (cloudways.com). Here I only changed the settings that allowed notifications using the official Airnotifier server on the official moodle app. When this worked, then I just changed the airnotifier settings to my custom server's values (see the post above, with the only difference being "Mobile app name" now not being the default name). Then it worked. This means that the problem was probably with the server (maybe a firewall?) or my moodle settings.
* Recompiled the apk with now the app id changed from the default value of com.moodle.moodlemobile. But I don't know if this made a difference.
In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Ahmed Samy -
Which AirNotifier repo did you clone ?
In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by JJ-Com Tech Ltd -

I have setup airnotifier and it sends notifications as expected. The only problem I have now is that I am starting it with:

sudo python3 -m pipenv run ./app.py

as you suggested in an earlier post. 

The steps I used to setup airnotifier

Please, how do I start airnotifier to run permanently and restart after system boot and after crash?

In reply to JJ-Com Tech Ltd

Re: Airnotifier for custom Moodle App

by Zayar Min -

I have the same issue as you. How can I solve it?

In reply to Zayar Min

Re: Airnotifier for custom Moodle App

by Olalekan Adeniyi -
use the below to run the server in the background

python3 -m pipenv run ./app.py &
In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Phạm Lê Minh -
Hi,
can I see your file: platforms\android\app\build.gradle
I want to know where to put this code:
  • // Import the Firebase BoM
  • implementation platform('com.google.firebase:firebase-bom:26.6.0')

  • // Add the dependency for the Firebase SDK for Google Analytics
  • // When using the BoM, don't specify versions in Firebase dependencies
  • implementation 'com.google.firebase:firebase-analytics'

  • // Add the dependencies for any other desired Firebase products
  • // https://firebase.google.com/docs/android/setup#available-libraries

because I find two code segment:

1. Start at line 355:
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')

if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

// SUB-PROJECT DEPENDENCIES START
implementation(project(path: ":CordovaLib"))
implementation "com.android.support:support-v4:27.1.0"
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.10.0"
implementation "com.android.support:support-v4:27.+"
implementation "com.android.support:support-v4:26.+"
implementation "com.android.support:support-v4:28.+"
implementation "com.android.support:appcompat-v7:28.+"
implementation "com.android.support:support-v13:27.+"
implementation "me.leolin:ShortcutBadger:1.1.17@aar"
implementation "com.google.firebase:firebase-messaging:17.5.+"
// SUB-PROJECT DEPENDENCIES END
}

2. start at line: 54

dependencies {
apply from: '../CordovaLib/cordova.gradle'

classpath 'com.android.tools.build:gradle:4.0.0'

if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

if(cdvHelpers.getConfigPreference('GradlePluginGoogleServicesEnabled', 'false').toBoolean()) {
String defaultGradlePluginGoogleServicesVersion = '4.2.0'

/**
* Fetches the user's defined Google Services Plugin Version from config.xml.
* If the version is not set or invalid, it will default to the ${defaultGradlePluginGoogleServicesVersion}
*/
String gradlePluginGoogleServicesVersion = cdvHelpers.getConfigPreference('GradlePluginGoogleServicesVersion', defaultGradlePluginGoogleServicesVersion)
if(!cdvHelpers.isVersionValid(gradlePluginGoogleServicesVersion)) {
println("The defined Google Services plugin version (${gradlePluginGoogleServicesVersion}) does not appear to be a valid version. Falling back to version: ${defaultGradlePluginGoogleServicesVersion}.")
gradlePluginGoogleServicesVersion = defaultGradlePluginGoogleServicesVersion
}

// Create the Google Services classpath and set it.
String gradlePluginGoogleServicesClassPath = "com.google.gms:google-services:${gradlePluginGoogleServicesVersion}"
println "Adding classpath: ${gradlePluginGoogleServicesClassPath}"
classpath gradlePluginGoogleServicesClassPath
}

implementation platform('com.google.firebase:firebase-bom:26.6.0')
implementation 'com.google.firebase:firebase-analytics'
}

And I dont know which one to modify as firebase suggest
In reply to Phạm Lê Minh

Re: Airnotifier for custom Moodle App

by Phạm Lê Minh -
Sorry I already know where to put firebase script, it should be put at this code segment:
1. Start at line 355:
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')

if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

// SUB-PROJECT DEPENDENCIES START
implementation(project(path: ":CordovaLib"))
implementation "com.android.support:support-v4:27.1.0"
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.10.0"
implementation "com.android.support:support-v4:27.+"
implementation "com.android.support:support-v4:26.+"
implementation "com.android.support:support-v4:28.+"
implementation "com.android.support:appcompat-v7:28.+"
implementation "com.android.support:support-v13:27.+"
implementation "me.leolin:ShortcutBadger:1.1.17@aar"
implementation "com.google.firebase:firebase-messaging:17.5.+"
// SUB-PROJECT DEPENDENCIES END
}
In reply to Johnny Sørensen

Re: Airnotifier for custom Moodle App

by Lê Bá Hùng -
I don't know what's wrong with your case but in my case:
On the Airnotification server terminal I get this error: ModuleNotFoundError: No module named 'netaddr'
So the simple solution is to install that Module: pip install netaddr
Done! Hopes this helps.
In reply to Egor Strelnikov

Re: Airnotifier for custom Moodle App

by Phạm Lê Minh -
Has anyone here successfully set up push notification on ios app, How to setup?
In reply to Egor Strelnikov

Re: Airnotifier for custom Moodle App

by Phạm Lê Minh -
Hi, anyone have a problem of Clicking a notification does not go to the right page in Android and crash on IOS. What version of airnotifier should I use?
In reply to Phạm Lê Minh

Re: Airnotifier for custom Moodle App

by Yogesh Patel -
Hello Pham

Are you using custom mobile App or moodle mobile app?
In reply to Egor Strelnikov

Re: Airnotifier for custom Moodle App

by Lê Bá Hùng -
Can you show me how to connect Moodle to airnotifier? I've created an Airnotifer server successfully and can access it use the web but when I configure it in moodle, this error happens:
"This site is not able to connect to the notifications server"
image.png

In reply to Lê Bá Hùng

Re: Airnotifier for custom Moodle App

by Lê Bá Hùng -
A little update. I created a testing sever with Moodle 3.11 and it worked, however, with Moodle 4.0, I cannot connect to Airnotifier. Maybe something has changed. I will continue to look and keep this post updated if people are interested
In reply to Lê Bá Hùng

Re: Airnotifier for custom Moodle App

by Lê Bá Hùng -
Fixed: It turns out Moodle block every port except port 443 and 80 and Airnotifier runs on port 8801 so you cannot connect to Airnotifier. I simple fix is allow port 8801 in Moodle
Site admin > Security > HTTP Security
then add port 8801 to cURL allowed ports list
Done!
In reply to Egor Strelnikov

Trả lời: Airnotifier for custom Moodle App

by Nguyễn Tủn Channel -
Has anyone had this error like me?
{
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "UNREGISTERED"
      }
    ]
  }
}

Attachment tokene.PNG
In reply to Nguyễn Tủn Channel

Re: Trả lời: Airnotifier for custom Moodle App

by Ardian Deari -
The issue with AirNotifier is that you need to provide the correct payload. You can refer to the following link for more information on the payload format:

https://moodledev.io/general/app/development/custom-push-notifications#payload-format
Average of ratings: Useful (1)
In reply to Ardian Deari

Trả lời: Re: Trả lời: Airnotifier for custom Moodle App

by Nguyễn Tủn Channel -
Thanks for your answer.
I just send it with Postman and the correct syntax based on the below link.
This is my Moodle web. I clicked on the "Send test push notification to my devices" button


And This is my airnotifier server 



Can you give me some advice?