restored env calls
This commit is contained in:
parent
883813a589
commit
5b83f21fc8
@ -21,7 +21,7 @@ export const sendEmailMessage = onRequest({
|
|||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, (request: Request, response: express.Response) => {
|
}, (request: Request, response: express.Response) => {
|
||||||
const mailgun = new Mailgun(formData);
|
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 toAddress = request.body.toAddress;
|
||||||
const subject = request.body.subject;
|
const subject = request.body.subject;
|
||||||
@ -31,8 +31,8 @@ export const sendEmailMessage = onRequest({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const textMessage = convert(message, options);
|
const textMessage = convert(message, options);
|
||||||
mailGunClient.messages.create(functions.config().MAILGUN_SERVER, {
|
mailGunClient.messages.create(process.env.MAILGUN_SERVER, {
|
||||||
from: functions.config().MAILGUN_FROM_ADDRESS,
|
from: process.env.MAILGUN_FROM_ADDRESS,
|
||||||
to: toAddress,
|
to: toAddress,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
text: textMessage,
|
text: textMessage,
|
||||||
@ -49,12 +49,12 @@ export const sendEmailMessage = onRequest({
|
|||||||
export const sendSMSMessage = onRequest({
|
export const sendSMSMessage = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, (request: Request, response: express.Response) => {
|
}, (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;
|
const { to, body } = request.body;
|
||||||
client.messages
|
client.messages
|
||||||
.create({
|
.create({
|
||||||
body: body,
|
body: body,
|
||||||
from: functions.config().TWILIO_PHONE_NUMBER,
|
from: process.env.TWILIO_PHONE_NUMBER,
|
||||||
to: to
|
to: to
|
||||||
})
|
})
|
||||||
.then((message: any) => {
|
.then((message: any) => {
|
||||||
@ -194,7 +194,7 @@ export const notifyTrainerUpdate = onRequest(
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const mailgun = new Mailgun(formData);
|
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 options = { wordwrap: 130 };
|
||||||
const textMessage = convert(emailContent, options);
|
const textMessage = convert(emailContent, options);
|
||||||
@ -209,11 +209,7 @@ export const notifyTrainerUpdate = onRequest(
|
|||||||
|
|
||||||
const userIds = memberships.docs.map((doc) => doc.data().userId);
|
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
|
const acceptedGyms = await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
@ -246,43 +242,14 @@ export const notifyTrainerUpdate = onRequest(
|
|||||||
const clientEmail = clientData.email;
|
const clientEmail = clientData.email;
|
||||||
|
|
||||||
if (fcmToken) {
|
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);
|
const message = generateTrainerUpdateMessage(trainerId,section,trainerName,fcmToken);
|
||||||
notificationPromises.push(admin.messaging().send(message));
|
notificationPromises.push(admin.messaging().send(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clientEmail) {
|
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);
|
const emailPromise = generateTrainerUpdateMail(mailGunClient,textMessage,emailContent,trainerName,clientEmail);
|
||||||
|
|
||||||
emailPromises.push(emailPromise);
|
emailPromises.push(emailPromise);
|
||||||
@ -309,30 +276,7 @@ export const notifyTrainerUpdate = onRequest(
|
|||||||
const gymEmail = gymData.email;
|
const gymEmail = gymData.email;
|
||||||
|
|
||||||
if (fcmToken) {
|
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);
|
const message = generateTrainerUpdateMessage(trainerId,section,trainerName,fcmToken);
|
||||||
|
|
||||||
@ -340,13 +284,7 @@ export const notifyTrainerUpdate = onRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gymEmail) {
|
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);
|
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> {
|
function generateTrainerUpdateMail(mailGunClient:any,textMessage:any,emailContent:string,trainerName: string, clientEmail: string) : Promise<any> {
|
||||||
return mailGunClient.messages.create(functions.config().mailgun.server, {
|
return mailGunClient.messages.create(process.env.MAILGUN_SERVER, {
|
||||||
from: functions.config().mailgun.from_address,
|
from: process.env.MAILGUN_FROM_ADDRESS,
|
||||||
to: clientEmail,
|
to: clientEmail,
|
||||||
subject: `Your trainer ${trainerName} has updated their profile`,
|
subject: `Your trainer ${trainerName} has updated their profile`,
|
||||||
text: textMessage,
|
text: textMessage,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user