Advertisement
headsortail

Azure Mobile Services Notification Hub Template Send

Oct 8th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function insert(item, user, request) {
  2.  
  3.     // Execute the request and send notifications.
  4.     request.execute({
  5.         success: function() {
  6.  
  7.             //respond back with success
  8.             request.respond(statusCodes.OK, item);
  9.                
  10.             //do async tasks
  11.             sendPushNotification(item);
  12.         }
  13.     });
  14. }
  15.  
  16. function sendPushNotification(move) {
  17.                    
  18.     // Create a template-based payload.
  19.     var payload = '{ "alert" : "' + move.playerName + ' just played. It\'s your turn!" }';                                              
  20.     var tag = 'user_id:' + move.otherPlayerId;
  21.    
  22.     //get the notification hub    
  23.     var azure = require('azure');
  24.     var hub = azure.createNotificationHubService('myhub', 'Endpoint=XXXXXXX');
  25.        
  26.     // Send the move notification to the other user on all platforms.
  27.     hub.send(tag, payload, function(error, outcome){
  28.         if (error) {
  29.             console.error("Error from notification hub on insert move:", error);    
  30.         }
  31.     });    
  32.        
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement