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: send signup event to Loops #531

Merged
merged 2 commits into from
Jul 17, 2024
Merged
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
4 changes: 4 additions & 0 deletions packages/server/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,8 @@ module.exports = {
endpoint: process.env.S3_ENDPOINT,
bucket: process.env.S3_BUCKET || 'bigcapital-documents',
},

loops: {
apiKey: process.env.LOOPS_API_KEY,
},
};
4 changes: 4 additions & 0 deletions packages/server/src/loaders/eventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import { UnlinkBankRuleOnDeleteBankRule } from '@/services/Banking/Rules/events/
import { DecrementUncategorizedTransactionOnMatching } from '@/services/Banking/Matching/events/DecrementUncategorizedTransactionsOnMatch';
import { DecrementUncategorizedTransactionOnExclude } from '@/services/Banking/Exclude/events/DecrementUncategorizedTransactionOnExclude';
import { DecrementUncategorizedTransactionOnCategorize } from '@/services/Cashflow/subscribers/DecrementUncategorizedTransactionOnCategorize';
import { LoopsEventsSubscriber } from '@/services/Loops/LoopsEventsSubscriber';

export default () => {
return new EventPublisher();
Expand Down Expand Up @@ -274,5 +275,8 @@ export const susbcribers = () => {

// Plaid
RecognizeSyncedBankTranasctions,

// Loops
LoopsEventsSubscriber
];
};
51 changes: 51 additions & 0 deletions packages/server/src/services/Loops/LoopsEventsSubscriber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import axios from 'axios';
import config from '@/config';
import { IAuthSignUpVerifiedEventPayload } from '@/interfaces';
import events from '@/subscribers/events';
import { SystemUser } from '@/system/models';

export class LoopsEventsSubscriber {
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.auth.signUpConfirmed,
this.triggerEventOnSignupVerified.bind(this)
);
}

/**
* Once the user verified sends the event to the Loops.
* @param {IAuthSignUpVerifiedEventPayload} param0
*/
public async triggerEventOnSignupVerified({
email,
userId,
}: IAuthSignUpVerifiedEventPayload) {
// Can't continue since the Loops the api key is not configured.
if (!config.loops.apiKey) {
return;
}
const user = await SystemUser.query().findById(userId);

const options = {
method: 'POST',
url: 'https://app.loops.so/api/v1/events/send',
headers: {
Authorization: `Bearer ${config.loops.apiKey}`,
'Content-Type': 'application/json',
},
data: {
email,
userId,
firstName: user.firstName,
lastName: user.lastName,
eventName: 'USER_VERIFIED',
eventProperties: {},
mailingLists: {},
},
};
await axios(options);
}
}
7 changes: 7 additions & 0 deletions packages/server/src/subscribers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export default {
baseCurrencyUpdated: 'onOrganizationBaseCurrencyUpdated',
},

/**
* User subscription events.
*/
subscription: {
onSubscribed: 'onOrganizationSubscribed',
},

/**
* Tenants managment service.
*/
Expand Down
Loading