bump: email service
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -26,8 +26,7 @@ const axios = require('axios');
|
||||
const { OAuth2Client } = require('google-auth-library');
|
||||
const { emailTemplates } = require('../data/email_body.data');
|
||||
|
||||
const GMAIL_SEND_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send';
|
||||
const GMAIL_PROFILE_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/profile';
|
||||
const GMAIL_SEND_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send';
|
||||
|
||||
// Lazily initialised so the module can be required before env is loaded.
|
||||
let _oauth2Client;
|
||||
@@ -85,10 +84,9 @@ const sendEmail = async ({ to, type, data = {} }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Confirms the refresh token is valid and the Gmail API is reachable.
|
||||
const ping = async () => {
|
||||
const accessToken = await getAccessToken();
|
||||
await axios.get(GMAIL_PROFILE_URL, { headers: { Authorization: `Bearer ${accessToken}` } });
|
||||
};
|
||||
// Confirms the refresh token is valid and Gmail's OAuth endpoint is reachable.
|
||||
// Deliberately doesn't call a Gmail read endpoint (e.g. users.getProfile) — the
|
||||
// refresh token is scoped to gmail.send only, which doesn't grant read access.
|
||||
const ping = () => getAccessToken();
|
||||
|
||||
module.exports = { sendEmail, ping };
|
||||
|
||||
Reference in New Issue
Block a user