Phone actions can be triggered from outside the phone via email

This commit is contained in:
J Francisco Rader committed 2021-03-30 02:08:53 -03:00
1 parent 901d7e95d3
commit 0a5a49b3d5
8 files changed
+67 -32

No files matched your search

+16 -11
View File
@@ -43,27 +43,32 @@ export async function fetchMessageActions(
}> {
const queryPhoneActions = `
SELECT
npwd_emails_phone_actions.label as action_phone_label,
npwd_emails_phone_actions.close_phone as action_phone_close_phone,
npwd_emails_phone_actions.delete_email as action_phone_delete_email,
npwd_emails_phone_actions.href as action_phone_href
npwd_emails_phone_actions.label,
npwd_emails_phone_actions.close_phone,
npwd_emails_phone_actions.delete_email,
npwd_emails_phone_actions.href
FROM npwd_emails_phone_actions
WHERE message_id = ?;
WHERE message_id = ?
`;
const queryExternalActions = `
SELECT
npwd_emails_external_actions.label as action_ext_label,
npwd_emails_external_actions.close_phone as action_ext_close_phone,
npwd_emails_external_actions.delete_email as action_ext_delete_email,
npwd_emails_external_actions.event_name as action_ext_event_name,
npwd_emails_external_actions.event_arg as action_ext_event_arg,
npwd_emails_external_actions.label,
npwd_emails_external_actions.close_phone,
npwd_emails_external_actions.delete_email,
npwd_emails_external_actions.event_name,
npwd_emails_external_actions.event_arg
FROM npwd_emails_external_actions
WHERE message_id = ?;
WHERE message_id = ?
`;
const [phoneActions] = await pool.query(queryPhoneActions, [id]);
const [externalActions] = await pool.query(queryExternalActions, [id]);
console.log({
phoneActions: phoneActions as UnformattedEmailPhoneAction[],
externalActions: externalActions as UnformattedEmailExternalAction[],
});
return {
phoneActions: phoneActions as UnformattedEmailPhoneAction[],
externalActions: externalActions as UnformattedEmailExternalAction[],
+1 -1
View File
@@ -106,7 +106,7 @@ onNet(EmailEvents.FETCH_MESSAGE_ACTIONS, async ({ messageId }: { messageId: numb
const actions = await fetchMessageActions(messageId);
const phoneActions = mapUnformattedEmailPhoneActions(actions.phoneActions);
const externalActions = mapUnformattedEmailExternalActions(actions.externalActions);
emitNet(EmailEvents.FETCH_MESSAGE_ACTIONS_SUCCESS, { phoneActions, externalActions });
emitNet(EmailEvents.FETCH_MESSAGE_ACTIONS_SUCCESS, _source, { phoneActions, externalActions });
} catch (e) {
emailLogger.error(`Failed to fetch email message actions, ${e.message}`, {
source: _source,
+5 -1
View File
@@ -135,7 +135,10 @@ export async function generatePhoneNumber(identifier: string): Promise<string> {
return phoneNumber;
}
export async function generateEmail(identifier: string): Promise<string> {
export async function generateEmail(
identifier: string,
cb?: (email: string) => void,
): Promise<string> {
const getQuery = `SELECT phone_email FROM users WHERE identifier = ?`;
const [results] = await pool.query(getQuery, [identifier]);
const result = <any[]>results;
@@ -153,6 +156,7 @@ export async function generateEmail(identifier: string): Promise<string> {
const newEmail = `${userProfileNames[0]}@${emailProvider}`.trim().toLowerCase();
const query = 'UPDATE users SET phone_email = ? WHERE identifier = ?';
await pool.query(query, [newEmail, identifier]);
cb?.(newEmail);
mainLogger.debug(`Inserting email into Database: ${newEmail}`);
return newEmail;
}
+20 -2
View File
@@ -2,6 +2,8 @@ import { mainLogger } from '../sv_logger';
import { pool } from '../db';
import { generateEmail, generatePhoneNumber } from '../functions';
import { PhoneEvents } from '../../../typings/phone';
import { sendEmail } from './../email/sv_email';
import config from '../../utils/config';
export const playerLogger = mainLogger.child({
module: 'player',
@@ -17,7 +19,7 @@ export async function handlePlayerAdd(pSource: number) {
// Parse specifically for license identifier as its
// guranteed
let playerIdentifer;
let playerIdentifer: string = null;
for (const identifier of playerIdentifiers) {
if (identifier.includes('license:')) {
playerIdentifer = identifier.split(':')[1];
@@ -37,7 +39,23 @@ export async function handlePlayerAdd(pSource: number) {
// Get player info to populate class instance
const { firstname, lastname, phone_number } = await getPlayerInfo(playerIdentifer);
const email = await generateEmail(playerIdentifer);
const email = await generateEmail(playerIdentifer, (email) => {
sendEmail(
'npwd',
`no-reply@${config.email.provider || 'project-error.dev'}`,
[
{
email,
identifier: playerIdentifer,
},
],
'--translate-APPS_EMAIL_WELCOME',
'New Phone Who Dis',
null,
[{ href: '/settings', label: 'Go to Settings', deleteEmail: false, closePhone: false }],
[],
);
});
const newPlayer = new Player({
identifier: playerIdentifer,