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

WIP: Crisp mailchimp messaging service #673

Open
wants to merge 5 commits into
base: develop
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
4 changes: 2 additions & 2 deletions docs/key-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ User authentication is handled by [Firebase Auth](https://firebase.google.com/do

Crisp is the messaging platform used to message the Chayn team in relation to bloom course content or other queries and support. For public users, this 1-1 chat feature is available on _live_ courses only. For partner users, This 1-1 chat feature is available to users with a `PartnerAccess` that has 1-1 chat enabled.

Users who have access to 1-1 chat also have a profile on Crisp that reflects data from our database regarding their partners, access and course progress. See [crisp-api.ts](src/api/crisp/crisp-api.ts)
Users who have access to 1-1 chat also have a profile on Crisp that reflects data from our database regarding their partners, access and course progress. See [crisp.service.ts](src/crisp/crisp.service.ts)

### Reporting

Google Data Studio is an online tool for converting data into customizable informative reports and dashboards.

The reports are generated by writing custom sql queries that return actionable data to Data Studio. Filters are applied in Data Studio allowing
data to be segregated into different time periods based on the data createdAt date
data to be segregated into different time periods based on the data createdAt date
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"axios": "^1.7.7",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"crisp-api": "^9.2.0",
"date-fns": "^3.6.0",
"dotenv": "^16.4.5",
"firebase": "^10.10.0",
Expand Down
127 changes: 0 additions & 127 deletions src/api/crisp/crisp-api.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/api/mailchimp/mailchimp-api.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export enum MAILCHIMP_MERGE_FIELD_TYPES {
ZIP = 'zip',
}

export enum MAILCHIMP_CUSTOM_EVENTS {
CRISP_MESSAGE_RECEIVED = 'CRISP_MESSAGE_RECEIVED',
}

export interface ListMemberCustomFields {
NAME?: string;
SIGNUPD?: string;
Expand Down
11 changes: 11 additions & 0 deletions src/api/mailchimp/mailchimp-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Logger } from '../../logger/logger';
import {
ListMember,
ListMemberPartial,
MAILCHIMP_CUSTOM_EVENTS,
MAILCHIMP_MERGE_FIELD_TYPES,
UpdateListMemberRequest,
} from './mailchimp-api.interfaces';
Expand Down Expand Up @@ -128,3 +129,13 @@ export const deleteCypressMailchimpProfiles = async () => {
throw new Error(`Delete cypress mailchimp profiles API call failed: ${error}`);
}
};

export const sendMailchimpUserEvent = async (email: string, event: MAILCHIMP_CUSTOM_EVENTS) => {
try {
await mailchimp.lists.createListMemberEvent(mailchimpAudienceId, getEmailMD5Hash(email), {
name: event,
});
} catch (error) {
throw new Error(`Send mailchimp user event failed: ${error}`);
}
};
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AuthModule } from './auth/auth.module';
import { CoursePartnerModule } from './course-partner/course-partner.module';
import { CourseUserModule } from './course-user/course-user.module';
import { CourseModule } from './course/course.module';
import { CrispModule } from './crisp/crisp.module';
import { EventLoggerModule } from './event-logger/event-logger.module';
import { FeatureModule } from './feature/feature.module';
import { HealthModule } from './health/health.module';
Expand Down Expand Up @@ -43,6 +44,7 @@ import { WebhooksModule } from './webhooks/webhooks.module';
PartnerFeatureModule,
EventLoggerModule,
HealthModule,
CrispModule,
],
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { EMAIL_REMINDERS_FREQUENCY } from '../../utils/constants';
import { EMAIL_REMINDERS_FREQUENCY } from 'src/utils/constants';

export enum EVENT_NAME {
CHAT_MESSAGE_SENT = 'CHAT_MESSAGE_SENT',
CHAT_MESSAGE_RECEIVED = 'CHAT_MESSAGE_RECEIVED',
LOGGED_IN = 'LOGGED_IN',
LOGGED_OUT = 'LOGGED_OUT',
}

export interface ICreateEventLog {
date: Date | string;
event: EVENT_NAME;
userId: string;
}

export interface CrispProfileCustomFields {
signed_up_at?: string;
Expand Down
12 changes: 12 additions & 0 deletions src/crisp/crisp.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EventLogEntity } from 'src/entities/event-log.entity';
import { UserEntity } from 'src/entities/user.entity';
import { EventLoggerService } from 'src/event-logger/event-logger.service';
import { CrispService } from './crisp.service';

@Module({
imports: [TypeOrmModule.forFeature([EventLogEntity, UserEntity])],
providers: [CrispService, EventLoggerService],
})
export class CrispModule {}
1 change: 1 addition & 0 deletions src/crisp/crisp.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
describe('CrispService', () => {});
Loading
Loading