-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send signup event to Loops (#531)
* feat: send signup event to Loops * feat: fix
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/server/src/services/Loops/LoopsEventsSubscriber.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters