Skip to content

Commit

Permalink
feat: send signup event to Loops (#531)
Browse files Browse the repository at this point in the history
* feat: send signup event to Loops

* feat: fix
  • Loading branch information
abouolia authored Jul 17, 2024
1 parent 107a6f7 commit 6b6b73b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
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

0 comments on commit 6b6b73b

Please sign in to comment.