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

Update email template as per further suggestions, add threadId in response #27

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
33 changes: 24 additions & 9 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import { BadRequestException, HttpException, Inject, Injectable, InternalServerErrorException, Logger, NotFoundException } from '@nestjs/common';
import { BadRequestException, HttpException, HttpStatus, Inject, Injectable, InternalServerErrorException, Logger, NotFoundException } from '@nestjs/common';
import { ClientProxy, RpcException } from '@nestjs/microservices';
import { map } from 'rxjs/operators';
import { IGetAllProofPresentations, IProofRequestSearchCriteria, IGetProofPresentationById, IProofPresentation, IProofRequestPayload, IRequestProof, ISendProofRequestPayload, IVerifyPresentation, IVerifiedProofData, IInvitation } from './interfaces/verification.interface';
Expand Down Expand Up @@ -454,8 +454,8 @@ export class VerificationService {
}

if (emailId) {
await this.sendEmailInBatches(payload, emailId, getAgentDetails, getOrganization);
return true;
const emailResponse = await this.sendEmailInBatches(payload, emailId, getAgentDetails, getOrganization);
return emailResponse;
} else {
const presentationProof: IInvitation = await this.generateOOBProofReq(payload);
const proofRequestInvitationUrl: string = presentationProof.invitationUrl;
Expand Down Expand Up @@ -498,13 +498,16 @@ export class VerificationService {


// Currently batch size is not used, as length of emails sent is restricted to '10'
async sendEmailInBatches(payload: IProofRequestPayload, emailIds: string[], getAgentDetails: org_agents, organizationDetails: organisation): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async sendEmailInBatches(payload: IProofRequestPayload, emailIds: string[], getAgentDetails: org_agents, organizationDetails: organisation): Promise<any> {
try {
const accumulatedErrors = [];
const accumulatedResponse = [];

for (const email of emailIds) {
try {
await this.sendOutOfBandProofRequest(payload, email, getAgentDetails, organizationDetails);
const response = await this.sendOutOfBandProofRequest(payload, email, getAgentDetails, organizationDetails);
accumulatedResponse.push({email, ...response});
await this.delay(500);
} catch (error) {
this.logger.error(`Error sending email to ${email}::::::`, error);
Expand All @@ -517,6 +520,8 @@ export class VerificationService {
throw new Error(ResponseMessages.verification.error.emailSend);
}

return accumulatedResponse;

} catch (error) {
this.logger.error('[sendEmailInBatches] - error in sending email in batches');
throw new Error(ResponseMessages.verification.error.batchEmailSend);
Expand All @@ -525,8 +530,9 @@ export class VerificationService {


// This function is specifically for OOB verification using email
async sendOutOfBandProofRequest(payload: IProofRequestPayload, email: string, getAgentDetails: org_agents, organizationDetails: organisation): Promise<boolean> {
const getProofPresentation = await this._sendOutOfBandProofRequest(payload);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async sendOutOfBandProofRequest(payload: IProofRequestPayload, email: string, getAgentDetails: org_agents, organizationDetails: organisation): Promise<any> {
const getProofPresentation = await this._sendOutOfBandProofRequest(payload);

if (!getProofPresentation) {
throw new Error(ResponseMessages.verification.error.proofPresentationNotFound);
Expand Down Expand Up @@ -564,7 +570,11 @@ export class VerificationService {
throw new Error(ResponseMessages.verification.error.emailSend);
}

return isEmailSent;
return {
isEmailSent,
outOfBandRecordId: getProofPresentation?.response?.outOfBandRecord?.id,
proofRecordThId: getProofPresentation?.response?.proofRecordThId
};
}


Expand Down Expand Up @@ -975,9 +985,14 @@ export class VerificationService {

verificationErrorHandling(error): void {
if (!error && !error?.status && !error?.status?.message && !error?.status?.message?.error) {

throw new RpcException(error.response ? error.response : error);
} else {
if (error?.message) {
throw new RpcException({
message: error?.message,
statusCode: HttpStatus.INTERNAL_SERVER_ERROR
});
}
throw new RpcException({
message: error?.status?.message?.error?.reason ? error?.status?.message?.error?.reason : error?.status?.message?.error,
statusCode: error?.status?.code
Expand Down
22 changes: 8 additions & 14 deletions apps/verification/templates/out-of-band-verification.template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class OutOfBandVerification {

public outOfBandVerification(email: string, orgName: string, deeplLinkURL: string): string {
public outOfBandVerification(email: string, orgName: string, deepLinkURL: string): string {
try {
return `<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -37,35 +37,29 @@ export class OutOfBandVerification {
Hello ${email},
</p>
<p>
<b>${orgName}</b> has requested verification of your digital credential. To share requested credential kindly follow below steps:
<b>${orgName}</b> has requested verification of your digital credential. To share the requested credentials, kindly follow the steps below:
<ul>
<li>Download the <b>${process.env.MOBILE_APP_NAME}</b> from
<a href="${process.env.PLAY_STORE_DOWNLOAD_LINK}" target="_blank">Android Play Store</a> or
<a href="${process.env.IOS_DOWNLOAD_LINK}" target="_blank">iOS App Store.</a> (Skip, if already downloaded)
</li>
<li>Complete the onboarding process in ${process.env.MOBILE_APP}.</li>
<li>Open the “Share Credential” link below in this email <i>(This will open the link in the ${process.env.MOBILE_APP} App)</i></li>
<li>Tap the <b>"Send Proof"</b> button in ${process.env.MOBILE_APP} to share you credential data.</li>
<li>Complete the onboarding process on ${process.env.MOBILE_APP}.</li>
<li>Click on “Share Credential” button below in this email <i>(This will redirect you to the ${process.env.MOBILE_APP} App)</i></li>
<li>Tap the <b>"Share"</b> button on ${process.env.MOBILE_APP} to share your credentials.</li>
</ul>
<div style="text-align: center; padding-bottom: 20px;">
<a clicktracking=off href="${deeplLinkURL}"
<a clicktracking=off href="${deepLinkURL}"
class="mobile-button"
style="padding: 10px 20px 10px 20px;color: #fff;background: #1F4EAD;border-radius: 5px;text-decoration: none;">
style="padding: 10px 20px 10px 20px;color: #fff;background: #124143;border-radius: 5px;text-decoration: none;">
Share Credential
</a>
<a clicktracking=off href="${process.env.MOBILE_APP_DOWNLOAD_URL}"
class="desktop-button"
style="padding: 10px 20px 10px 20px;color: #fff;background: #1F4EAD;border-radius: 5px;text-decoration: none;">
Download App
</a>
</div>

</p>
<p>
<b>Note:</b> If the above steps do not work for you, please open the <b>attached QR Code image</b> in this email on another device, and scan the QR code using the ${process.env.MOBILE_APP_NAME} on your mobile device.
<b>Note:</b> Alternatively, you will find a <b>QR Code image attached</b> to this email. You can open the QR code on another device and scan the QR code using the ${process.env.MOBILE_APP} App on your mobile device.
<u> The QR Code is single-use.</u>
</p>


<hr style="border-top:1px solid #e8e8e8" />
<footer style="padding-top: 20px;">
Expand Down