Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Otp email bridge #32982

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/meteor/app/apps/server/bridges/bridges.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppApisBridge } from './api';
import { AppCloudBridge } from './cloud';
import { AppCommandsBridge } from './commands';
import { AppDetailChangesBridge } from './details';
import { AppEmailBridge } from './email';
import { AppEnvironmentalVariableBridge } from './environmental';
import { AppHttpBridge } from './http';
import { AppInternalBridge } from './internal';
Expand Down Expand Up @@ -42,6 +43,7 @@ export class RealAppBridges extends AppBridges {
this._internalBridge = new AppInternalBridge(orch);
this._setsBridge = new AppSettingBridge(orch);
this._userBridge = new AppUserBridge(orch);
this._emailBridge = new AppEmailBridge(orch);
this._livechatBridge = new AppLivechatBridge(orch);
this._uploadBridge = new AppUploadBridge(orch);
this._uiInteractionBridge = new UiInteractionBridge(orch);
Expand Down Expand Up @@ -119,6 +121,10 @@ export class RealAppBridges extends AppBridges {
return this._uploadBridge;
}

getEmailBridge() {
return this._emailBridge;
}

getUiInteractionBridge() {
return this._uiInteractionBridge;
}
Expand Down
16 changes: 16 additions & 0 deletions apps/meteor/app/apps/server/bridges/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { IAppServerOrchestrator } from '@rocket.chat/apps';
import { EmailBridge } from '@rocket.chat/apps-engine/server/bridges/EmailBridge';
import type { IEmail } from '@rocket.chat/apps-engine/server/definitions/email';

import * as Mailer from '../../../mailer/server/api';

export class AppEmailBridge extends EmailBridge {
constructor(private readonly orch: IAppServerOrchestrator) {
super();
}

protected async sendEmail(email: IEmail, appId: string): Promise<void> {
this.orch.debugLog(`The app: ${appId} is requesting an OTP code to be sent to: ${email}`);
await Mailer.send(email);
}
}
18 changes: 18 additions & 0 deletions apps/meteor/app/livechat/server/lib/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ type UpdateContactParams = {
channels?: ILivechatContactChannel[];
};

type ContactOTPCodeInfo = {
code: string;
expiresAt: Date;
attempts: number;
};

export const Contacts = {
async registerContact({
token,
Expand Down Expand Up @@ -278,3 +284,15 @@ export async function validateContactManager(user: Pick<IUser, 'roles'> | null)
throw new Error('error-contact-manager-not-found');
}
}

export async function addEmailCodeByContactEmail(email: string, channel: string, code: string, expiresAt: Date): Promise<any> {
throw new Error('addEmailCodeByContactEmail: implement');
}

export async function findContactCodeFromChannelAndEmail(email: string, channel: string): Promise<ContactOTPCodeInfo> {
throw new Error('findContactCodeFromChannelAndEmail: implement');
}

export async function incrementInvalidEmailCodeAttemptByVerifyingMethod(email: string, channel: string): Promise<any> {
throw new Error('incrementInvalidEmailCodeAttemptByVerifyingMethod: implement');
}
Loading