restored env calls

This commit is contained in:
josephgladwingeorge 2025-03-27 11:59:54 +05:30
parent 883813a589
commit 5b83f21fc8

View File

@ -21,7 +21,7 @@ export const sendEmailMessage = onRequest({
region: '#{SERVICES_RGN}#'
}, (request: Request, response: express.Response) => {
const mailgun = new Mailgun(formData);
const mailGunClient = mailgun.client({ username: 'api', key: functions.config().MAILGUN_API_KEY });
const mailGunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
const toAddress = request.body.toAddress;
const subject = request.body.subject;
@ -31,8 +31,8 @@ export const sendEmailMessage = onRequest({
};
const textMessage = convert(message, options);
mailGunClient.messages.create(functions.config().MAILGUN_SERVER, {
from: functions.config().MAILGUN_FROM_ADDRESS,
mailGunClient.messages.create(process.env.MAILGUN_SERVER, {
from: process.env.MAILGUN_FROM_ADDRESS,
to: toAddress,
subject: subject,
text: textMessage,
@ -49,12 +49,12 @@ export const sendEmailMessage = onRequest({
export const sendSMSMessage = onRequest({
region: '#{SERVICES_RGN}#'
}, (request: Request, response: express.Response) => {
const client = twilio(functions.config().TWILIO_ACCOUNT_SID, functions.config().TWILIO_AUTH_TOKEN);
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
const { to, body } = request.body;
client.messages
.create({
body: body,
from: functions.config().TWILIO_PHONE_NUMBER,
from: process.env.TWILIO_PHONE_NUMBER,
to: to
})
.then((message: any) => {
@ -194,7 +194,7 @@ export const notifyTrainerUpdate = onRequest(
`;
const mailgun = new Mailgun(formData);
const mailGunClient = mailgun.client({ username: 'api', key: functions.config().mailgun.api_key});
const mailGunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY});
const options = { wordwrap: 130 };
const textMessage = convert(emailContent, options);
@ -209,11 +209,7 @@ export const notifyTrainerUpdate = onRequest(
const userIds = memberships.docs.map((doc) => doc.data().userId);
// if (clients.empty) {
// logger.info(`No clients found for trainer: ${trainerId}`);
// response.json({ success: true, message: 'No clients to notify' });
// return;
// }
const acceptedGyms = await admin
.firestore()
@ -246,43 +242,14 @@ export const notifyTrainerUpdate = onRequest(
const clientEmail = clientData.email;
if (fcmToken) {
// const message : Message ={
// notification: {
// title: 'Trainer Profile Update',
// body: `${trainerName} has updated their ${section}`,
// },
// data: {
// type: 'trainer_profile_update',
// trainerId: trainerId,
// section: section,
// trainerName: trainerName,
// },
// android: {
// priority: 'high',
// notification: {
// channelId: 'trainer_updates_channel',
// priority: 'high',
// defaultSound: true,
// defaultVibrateTimings: true,
// icon: '@mipmap/ic_launcher',
// clickAction: 'FLUTTER_NOTIFICATION_CLICK',
// },
// },
// token: fcmToken,
// };
const message = generateTrainerUpdateMessage(trainerId,section,trainerName,fcmToken);
notificationPromises.push(admin.messaging().send(message));
}
if (clientEmail) {
// const emailPromise = mailGunClient.messages.create(functions.config().mailgun.server, {
// from: functions.config().mailgun.from_address,
// to: clientEmail,
// subject: `Your trainer ${trainerName} has updated their profile`,
// text: textMessage,
// html: emailContent
// });
const emailPromise = generateTrainerUpdateMail(mailGunClient,textMessage,emailContent,trainerName,clientEmail);
emailPromises.push(emailPromise);
@ -309,30 +276,7 @@ export const notifyTrainerUpdate = onRequest(
const gymEmail = gymData.email;
if (fcmToken) {
// const message :Message={
// notification: {
// title: 'Trainer Profile Update',
// body: `${trainerName} has updated their ${section}`,
// },
// data: {
// type: 'trainer_profile_update',
// trainerId: trainerId,
// section: section,
// trainerName: trainerName,
// },
// android: {
// priority: 'high',
// notification: {
// channelId: 'trainer_updates_channel',
// priority: 'high',
// defaultSound: true,
// defaultVibrateTimings: true,
// icon: '@mipmap/ic_launcher',
// clickAction: 'FLUTTER_NOTIFICATION_CLICK',
// },
// },
// token: fcmToken,
// };
const message = generateTrainerUpdateMessage(trainerId,section,trainerName,fcmToken);
@ -340,13 +284,7 @@ export const notifyTrainerUpdate = onRequest(
}
if (gymEmail) {
// const emailPromise = mailGunClient.messages.create(functions.config().mailgun.server, {
// from: functions.config().mailgun.from_address,
// to: gymEmail,
// subject: `Your trainer ${trainerName} has updated their profile`,
// text: textMessage,
// html: emailContent
// });
const emailPromise = generateTrainerUpdateMail(mailGunClient,textMessage,emailContent,trainerName,gymEmail);
@ -491,8 +429,8 @@ function generateTrainerUpdateMessage(trainerId: string, section: string, traine
}
function generateTrainerUpdateMail(mailGunClient:any,textMessage:any,emailContent:string,trainerName: string, clientEmail: string) : Promise<any> {
return mailGunClient.messages.create(functions.config().mailgun.server, {
from: functions.config().mailgun.from_address,
return mailGunClient.messages.create(process.env.MAILGUN_SERVER, {
from: process.env.MAILGUN_FROM_ADDRESS,
to: clientEmail,
subject: `Your trainer ${trainerName} has updated their profile`,
text: textMessage,