I need to push notification to user , when new task is assigned to the user, I am planning to use "ChomePushNotification" , but i could not understand how to use it in php to invoke notification..
https://storage-cdn.realtime.co/chrome-push/index.html
Can anyone give me the overview how to use this in PHP , to invoke notification if a record inserted in a table "Task" with agent_id =123, i need to send notification to user "123".. "NEW TASK ASSIGNE.."
The first step is to use javascript to give the user the option to subscribe to the push notifications...
if ('serviceWorker' in navigator) {
console.log('Service Worker is supported');
navigator.serviceWorker.register('sw.js').then(function(reg) {
console.log(':^)', reg);
reg.pushManager.subscribe({
userVisibleOnly: true
}).then(function(sub) {
console.log('endpoint:', sub.endpoint);
});
}).catch(function(error) {
console.log(':^(', error);
});
}
The next step is to use cURL to send the request to Google using the following cURL command, either from the command line or by extrapolating it into a PHP cURL command...
curl --header "Authorization: key=AIzaSyAc2e8MeZHA5NfhPANea01wnyeQD7uVY0c" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration\_ids\":[\"APA91bE9DAy6\_p9bZ9I58rixOv-ya6PsNMi9Nh5VfV4lpXGw1wS6kxrkQbowwBu17ryjGO0ExDlp-S-mCiwKc5HmVNbyVfylhgwITXBYsmSszpK0LpCxr9Cc3RgxqZD7614SqDokwsc3vIEXkaT8OPIM-mnGMRYG1-hsarEU4coJWNjdFP16gWs\"]}"
Please note the cURL example is take directly from the Google Developers page at https://developers.google.com/web/fundamentals/getting-started/push-notifications/step-07?hl=en and uses their sample hashes and keys.
For further information you can review the details of how to send push notifications by checking out the Google documentation at https://developers.google.com/web/fundamentals/getting-started/push-notifications/?hl=en
Related
I get message conversations via Facebook graph API which looks like:
https://graph.facebook.com/' + id + '/messages?fields=message
and I want to mark as read the message but I can't find how to in documents.
please, can someone point me to some examples?
You only have read access to the Inbox via the API. So this is not currently possible.
You can set typing indicators or send read receipts using the API, to let users know you are processing their request.
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"<PSID>"
},
"sender_action":"typing_on"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
Check below.
sender action = mark_seen..
I am using it and its working fine..
https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions/
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"<PSID>"
},
"sender_action":"mark_seen"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=
<PAGE_ACCESS_TOKEN>"
I'm Using Ionic Framework V1.
I've already get push notifications through Postman using
and I've already save all devicetokens in my DB, but i'm stuck at getting any push for specific devices in php functions.
curl -X POST -H "Authorization: Bearer API_TOKEN" -H "Content-Type: application/json" -d '{
"tokens": ["DEV_DEVICE_TOKEN"],
"profile": "PROFILE_NAME",
"notification": {
"message": "This is my demo push!"
}
Example:
public function confirmAction($request){
$action = $this->find($request->idtblAction);
$action->idtblStatus=1;
if($action->save()){
//I need to send notification in this part
return Response::json(array('success'=>'true'));
}else{
return Response::json(array('success'=>'false'));
}
}
Ionic io uses Bearer key and profileapp
Any idea?
I've already solve this without using php. I did it through my internal ionic app code.
Thank you to everybody!
I am using PerfectSwift for a RESTful API to bridge our TeamCity build server and HipChat; however I am stuck at a point whereby I am unable to post to the HipChat backend using Perfect's cURL wrapper.
The command I am trying to mimic is:
curl -d '{"color":"green","message":"My first notification (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>
I currently have the following code in my Perfect program:
let curl = CURL(url: "https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>")
curl.setOption(CURLOPT_POST, int: 1)
curl.setOption(CURLOPT_POSTFIELDS, s: "{\"color\":\"green\",\"message\":\"My first notification (yey)\",\"notify\":false,\"message_format\":\"text\"}")
curl.setOption(CURLOPT_HTTPHEADER, s: "[Content-Type:application/json]")
curl.perform { (code, header, body) in
}
However, the message never gets to HipChat, or, if it does, it's not in a readable format.
When I paste the first command into terminal, everything works as expected.
From my understanding, this uses a similar system to PHP, and I am therefore including the PHP tag as I feel PHP developers may be able to offer advice if I am using the wrong CURLOPTs etc...
Thanks in advance.
How can I read response from a remote server using Nagios Notification? I'm new to this Nagios Notification System.
The only data from the server side is, they are pushing data in this format:
/usr/bin/curl --url http://mywebpage.com/TicKeTREder.php? --data-urlencode "eventType=Nagios Notification" --data-urlencode "message=$NOTIFICATIONTYPE$#$LONGDATETIME$#$SERVICEDESC$#$HOSTALIAS$#$SERVICESTATE$#$SERVICEOUTPUT$#$CONTACTEMAIL$#$NOTIFICATIONISESCALATED$"
I've tried searching. But no results found.
What I need is read those tickets from Nagios notification system with my TicKeTREder.php page.
Is there any plugin to read these data using php.
Issue solved since the problem was not with the program side.
You get the message with
$message = $_REQUEST['message'];
You can split the information parts with:
$infoArray = explode('#', $message);
Then $infoArray[0] holds the notification type and so on.
you will get data from nagios as a string where all the server /service details are seprated with hash(#). You can split these details by :
$Array = explode('#', $message);
I followed this Laravel token API tutorial: http://rjv.im/post/95988160186/api-token-authentication-with-laravel-and-sentry-part. I have written the following cURL request to communicate with my API:
curl -H "X-Auth-Token:tokenhere" http://localhost:8000/account
The request works properly, and accurately returns the expected data. When I translate this to Python I receive urllib2.HTTPError: HTTP Error 401: Unauthorized
import urllib2
req = urllib2.Request('http://localhost:8000/account')
req.add_header("X-Auth-Token", "tokenhere")
resp = urllib2.urlopen(req)
content = resp.read()
print content
If I pass user credentials using basic auth instead of an X-Auth-Token, the request works as expected:
import urllib2
def basic_authorization(user, password):
s = user + ":" + password
return "Basic " + s.encode("base64").rstrip()
req = urllib2.Request("http://localhost:8000/account", headers = { "Authorization": basic_authorization("usernameHere", "passwordHere"), })
f = urllib2.urlopen(req)
print f.read()
Any assistance would be much appreciated.
There is something you missed in the tutorial. In the tokens table there is a column:
$table->string('client');
It is important from which client you are sending your request. I am using https://github.com/hisorange/browser-detect to detect from which client I got the request.
But for now I will just try to see User Agent. In my laravel code I just logged every request to see what's happening with the following code:
Route::filter('auth.token', function($route, $request)
{
....
Log::info($request);
....
}
Now, Let's see:
When I use curl from command line:
curl -u user#example.com:password -X GET http://localhost:8000/account
My User Agent is
User-Agent: curl/7.32.0
I sent the same from python using your code above, User Agent is:
User-Agent: Python-urllib/2.7
Ah! That must be it. You have to authenticate your user at least once using Basic Auth, it will give you a token and that token is valid for only that client. In the first part http://rjv.im/post/78940780589/api-token-authentication-with-laravel-and-sentry-part of tutorial there was no such condition. In the comments I received someone posted a query on how to support multiple clients, so this example was made to solve that problem.
Apart from that, may I suggest this library: https://github.com/chrisbjr/api-guard It supports Rate Limiting, easy to integrate with Sentry. It's a bit different from my tutorial. Using my solution you can hit any endpoint using Basic Auth or Token. Using above library, only token is permitted, so there is dedicated route to generate token. Let me know how it goes.