uniqush / uniqush-push

Uniqush is a free and open source software system which provides a unified push service for server side notification to apps on mobile devices.
http://uniqush.org
Apache License 2.0
1.53k stars 201 forks source link

Title in push notification #195

Closed geniuscd closed 6 years ago

geniuscd commented 6 years ago

The following describes how to push a message to a subscriber.

Parameter Description
service Service Name.
subscriber Subscriber ID. Could be more than one subscriber. Comma separated. Asterisk (*) could be used as a wildcard to match any string
msg Optional. Message Body
ttl Optional. Time to live. How long (in seconds) the message should be kept on push service provider’s server if the device is offline
badge Optional. Badge
img Optional. Image
sound Optional. Sound
loc-key Optional. loc-key for APNS
loc-args Optional. loc-args for APNS. It is a comma-separated string.
action-loc-key Option. action-loc-key for APNS.
Reserved Parameter Any parameter whose name starts with “uniqush.” is reserved by Uniqush. Users should avoid using those parameter names.
User Defined Parameter Optional. Any other parameter is accepted which will be sent to mobile devices

Can we add a title? I know that push notification payload can also have a title, but it isn't listed here. am I missing something?

TysonAndre commented 6 years ago

It seems to exist for GCM(Android) and for Apple watch.

For APNS, the alert would have to be changed from a string to a dictionary

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html https://developers.google.com/cloud-messaging/http-server-ref

geniuscd commented 6 years ago

alright, so you mean we have to edit the core plugin code and have another updated version (PR request?), or we can have a simple workaround? #192 ?

TysonAndre commented 6 years ago

https://github.com/uniqush/uniqush-push/blob/master/srv/apns/push_service_test.go#L301-L313

A PR for srv/apns/payload.go (and probably GCM) would work.

Manually passing in JSON with the desired title, etc. for uniqush.payload.apns would also work as a workaround.

geniuscd commented 6 years ago

ok great. I never wrote any go script before, I don't know how to compile it either :p I will try to contribute as much as I can. but please can you give us a curl example of the uniqush.payload.apns? coz I tried to write myself, and it didn't work, or at least I didn't knew how to write it.

TysonAndre commented 6 years ago

Example of how to send a push with uniqush.payload.apns. Note that you may need to url encode if the url is built manually.

curl http://127.0.0.1:9898 -d service=myservicename -d subscriber=1234 -d uniqush.payload.apns='{"aps":{"alert":{"body":"message body","title":"message title"}}}'

With this example, on an iphone, the title "message title" shows up in bold, below the app name and above the message body.

The previewpush endpoint may also help you. If you provide any additional parameters, it will show you the JSON generated from those parameters

curl http://127.0.0.1:9898/previewpush -d pushservicetype=apns -d pushtype=message -d msg='message body'                             
{"code":"UNIQUSH_SUCCESS","payload":{"aps":{"alert":{"body":"message body"}},"pushtype":"message"}}

curl http://127.0.0.1:9898/previewpush -d pushservicetype=apns -d pushtype=message -d msg='message body' -d img=myimg 
{"code":"UNIQUSH_SUCCESS","payload":{"aps":{"alert":{"body":"message body","launch-image":"myimg"}},"pushtype":"message"}}

curl http://127.0.0.1:9898/previewpush -d pushservicetype=apns -d pushtype=message -d uniqush.payload.apns='{"aps":{"alert":{"body":"message body","title":"message title"}}}'
{"code":"UNIQUSH_SUCCESS","payload":{"aps":{"alert":{"body":"message body","title":"message title"}}}}
geniuscd commented 6 years ago

ok so the uniqush.payload.apns approach will not work according to this line of code in order to support the title we should add only two lines of code after this line case "title": alert["title"]= v according to apple documentation

TysonAndre commented 6 years ago

Things that I should do later: