async function main(params) {
  // The API key for SendGrid, put as a param in your Cloud-Function
  const sgApiKey = params.sgApiKey;

  // Init Sendgrind
  sgMail.setApiKey(sgApiKey);

  // Decode message to get information
  const data = jwtDecode(params.jws, {complete: true});

  // Extract kid from header
  const kid = data.header.kid;

  const keysArray = await obtainPublicKeys();

  // Verify the signature of the payload with the public keys
  await verifySignature(keysArray, kid ,params.jws);

  // Send the email with Your SendGrid account
  const message = data.payload.message;
  const msg = {
    to: message.to,
    from: message.from.address,
    subject: message.subject,
    html: message.body,
  };
  console.log(`Sending email to ${message.to}`);
  let sendgridResponse = await sgMail.send(msg);

  return {result : 'email_sent',sendgridResponse};
}
/**
 *
 * main() will be run when you invoke this action
 *
 * @param Cloud Functions actions accept a single parameter, which must be a JSON object.
 *
 * @return The output of this action, which must be a JSON object.
 *
 */
main() will be run when you invoke this action
@param Cloud Functions actions accept a single parameter, which must be a JSON object.

@return The output of this action, which must be a JSON object.
main () will be run when you invoke this action @param Cloud Functions actions accept a single parameter which must be a JSON object . @return The output of this action which must be a JSON object .
async function main(params) {
  const sgApiKey = params.sgApiKey;
  sgMail.setApiKey(sgApiKey);
  const data = jwtDecode(params.jws, {complete: true});
  const kid = data.header.kid;
  const keysArray = await obtainPublicKeys();
  await verifySignature(keysArray, kid ,params.jws);
  const message = data.payload.message;
  const msg = {
    to: message.to,
    from: message.from.address,
    subject: message.subject,
    html: message.body,
  };
  console.log(`Sending email to ${message.to}`);
  let sendgridResponse = await sgMail.send(msg);
  return {result : 'email_sent',sendgridResponse};
}
async function main ( params ) { const sgApiKey = params . sgApiKey ; sgMail . setApiKey ( sgApiKey ) ; const data = jwtDecode ( params . jws , { complete : true } ) ; const kid = data . header . kid ; const keysArray = await obtainPublicKeys ( ) ; await verifySignature ( keysArray , kid , params . jws ) ; const message = data . payload . message ; const msg = { to : message . to , from : message . from . address , subject : message . subject , html : message . body , } ; console . log ( ` ${ message . to } ` ) ; let sendgridResponse = await sgMail . send ( msg ) ; return { result : 'email_sent' , sendgridResponse } ; }
main() will be run when you invoke this action
 @param Cloud Functions actions accept a single parameter, which must be a JSON object.
main () will be run when you invoke this action @param Cloud Functions actions accept a single parameter which must be a JSON object .
// The API key for SendGrid, put as a param in your Cloud-Function // Init Sendgrind // Decode message to get information // Extract kid from header // Verify the signature of the payload with the public keys // Send the email with Your SendGrid account