functions/tip-service.js
/**
 * Authorizes and sends a notification to the user.
 * @return {Promise}
 */
Authorizes and sends a notification to the user.
@return {Promise}
Authorizes and sends a notification to the user . @return { Promise }
function authorizeAndSendNotification() {
  const intent = 'tell.latest.tip';
  let authTokens;
  console.log('about to authorize ..');
  return authorize().then((tokens) => {
    console.log('received authTokens ');
    authTokens = tokens;
    return getUsersRegisteredForNotification(intent);
  })
    .then((notificationTargets) => {
      console.log('received notification targets', notificationTargets);
      const sendPromises = [];
      let notification = {
        userNotification: {
          title: 'AoG tips latest tip',
        },
        target: {},
      };
      notificationTargets.forEach((notificationTarget) => {
        notification.target = notificationTarget;
        sendPromises.push(sendNotification(notification, authTokens));
      });
      return Promise.all(sendPromises);
    })
    .catch((error) => {
      console.log('Error sending notification to users ', error);
    });
}
function authorizeAndSendNotification ( ) { const intent = 'tell.latest.tip' ; let authTokens ; console . log ( 'about to authorize ..' ) ; return authorize ( ) . then ( ( tokens ) => { console . log ( 'received authTokens ' ) ; authTokens = tokens ; return getUsersRegisteredForNotification ( intent ) ; } ) . then ( ( notificationTargets ) => { console . log ( 'received notification targets' , notificationTargets ) ; const sendPromises = [ ] ; let notification = { userNotification : { title : 'AoG tips latest tip' , } , target : { } , } ; notificationTargets . forEach ( ( notificationTarget ) => { notification . target = notificationTarget ; sendPromises . push ( sendNotification ( notification , authTokens ) ) ; } ) ; return Promise . all ( sendPromises ) ; } ) . catch ( ( error ) => { console . log ( 'Error sending notification to users ' , error ) ; } ) ; }
Authorizes and sends a notification to the user.
Authorizes and sends a notification to the user .