functions/tip-service.js
/**
 * Authorizes the function to send notifications.
 * @return {Promise}
 */
Authorizes the function to send notifications.
@return {Promise}
Authorizes the function to send notifications . @return { Promise }
function authorize() {
  console.log('authorizing ..');
  const { google } = require('googleapis');
  const serviceAccount = require('./service-account.json');
  const jwtClient = new google.auth.JWT(
    serviceAccount.client_email, null, serviceAccount.private_key,
    ['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
    null
  );
  return new Promise((resolve, reject) => {
    jwtClient.authorize((err, tokens) => {
      if (err) {
        console.log('authorization error: ' + err);
        return reject(new Error(`Auth error: ${err}`));
      }
      console.log('authorization success');
      resolve(tokens);
    });
  });
}
function authorize ( ) { console . log ( 'authorizing ..' ) ; const { google } = require ( 'googleapis' ) ; const serviceAccount = require ( './service-account.json' ) ; const jwtClient = new google . auth . JWT ( serviceAccount . client_email , null , serviceAccount . private_key , [ 'https://www.googleapis.com/auth/actions.fulfillment.conversation' ] , null ) ; return new Promise ( ( resolve , reject ) => { jwtClient . authorize ( ( err , tokens ) => { if ( err ) { console . log ( 'authorization error: ' + err ) ; return reject ( new Error ( ` ${ err } ` ) ) ; } console . log ( 'authorization success' ) ; resolve ( tokens ) ; } ) ; } ) ; }
Authorizes the function to send notifications.
Authorizes the function to send notifications .