Push Notifications

63 views
Skip to first unread message

mostwanted

unread,
Nov 16, 2020, 3:31:10 AM11/16/20
to web2py-users

Has anyone been able to implement push notifications on their web2py apps?

I need a working application with some examples on how to implement this for one of my applications.

I've been looking at the "web-push-book (https://web-push-book.gauntface.com/how-push-works/)" but I cant put it together in my head.

What I wanna achieve is relatively basic, I have an applivcation that offers information on services & products sold in my area, so what I want is to be able to send notifications everytime a new service or product is registered.

If anyone has any idea on how I can easily implement this please help me.

Regards;

Mostwanted

mostwanted

unread,
Nov 16, 2020, 3:44:51 AM11/16/20
to web2py-users
So far all I have been able achieve is asking the user for permission to send them notifications & if they accept all that happens is that everytime they open the app they get a greetings notification, achieving that was not complicated because it was straight forward, I placed the code in my main.js script & it runs everytime the service worker gets registered.

CODE:
Notification.requestPermission(result => {
  if (result === 'granted') {
    showNotification('Welcome to My App™', 'Everything Services™')
  }
});

function showNotification(title, message) {
  if ('Notification' in window) {
    navigator.serviceWorker.ready.then(registration => {
      registration.showNotification(title, {
        body: message,
        tag: 'my-app',
        icon:'/init/static/images/icon_192x192.png',
        badge:'/init/static/images/icon_128x128.png',
        vibrate: [200, 100, 200, 100, 200, 100]
      });
    });
  }
}


António Ramos

unread,
Nov 16, 2020, 6:06:10 PM11/16/20
to web...@googlegroups.com
Why reiventing the wheel ??? 

I use it with web2py and works like a charm


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/01da1065-f7d3-4394-9014-a424639bef03n%40googlegroups.com.

AGRogers

unread,
Nov 16, 2020, 9:49:25 PM11/16/20
to web...@googlegroups.com
Thanks for the tip Antonio. The free version could work well for me. I dont mind reinventing the wheel - I just dont like fixing it when it breaks :)

___________________________
www.TenOutOfTen.org



mostwanted

unread,
Nov 17, 2020, 12:53:20 AM11/17/20
to web2py-users
Thanks alot Ramos, think this will work, very little work needs to be done here, I'll try it out.

mostwanted

unread,
Nov 20, 2020, 2:40:58 AM11/20/20
to web2py-users
Hey Ramos, I was able to successfully register the app on pusher.com. towards step 4 its says i should copy this code:
CODE:
curl -H "Content-Type: application/json" \
     -H "Authorization: Bearer 9C9232906DFC6C8F8115926CC30D637945EB75F60467DA77977C399C4235E61C" \
     -X POST "https://733e2240-aca0-4a12-a5a9-c3b1422b9063.pushnotifications.pusher.com/publish_api/v1/instances/733e2240-aca0-4a12-a5a9-c3b1422b9063/publishes" \
     -d '{"interests":["hello"],"web":{"notification":{"title":"Hello","body":"Hello, world!"}}}'

to my console! Which console is this one? My desktop console? I'm hosted with pythonanywhere.com, can i use the Bash console in my dashboard?

António Ramos

unread,
Nov 20, 2020, 3:33:10 AM11/20/20
to web...@googlegroups.com
create a module inside web2py
API_Pusher.py

import pusher

def pusher_client():
    return pusher.Pusher(
                          app_id='yourid',
                          key='yourkey',
                          secret='yoursecret',
                          cluster='eu',
                          ssl=True
                        )


Then inside your controllers

from API_Pusher import pusher_client
...
pusher_client().trigger('fileit''plannerPesos',  {'message'"PlaySound('ok')"})

mostwanted

unread,
Nov 20, 2020, 11:45:25 AM11/20/20
to web2py-users
Gratitude

Christian Varas

unread,
Nov 20, 2020, 1:28:34 PM11/20/20
to web...@googlegroups.com
Hi! I need to implement this and receive the notifications in the phone android/iOS. For this do I need to make my own app? Or do you use an app who can subscribe to push notifications in pusher.com ?
This is off topic but any recommendation is appreciated 

Cheers.
Chris

António Ramos

unread,
Nov 20, 2020, 6:13:52 PM11/20/20
to web...@googlegroups.com
Yes you make an app in web2py that subscribes to one or many pusher notification channels. That channels are created by you in your html of your web2py app.
 your web2py server sends notifications to pusher.com using python code ,and your webpages subscribes the same notifications using javascript. you can go crazy and create rooms etc.
The docs from pusher are very informative.
Regards
António

Reply all
Reply to author
Forward
0 new messages