Skip to content

Commit ab2582f

Browse files
authored
Merge pull request #32 from samagra-comms/main
Prod Deployment
2 parents 50c6654 + 47360c0 commit ab2582f

21 files changed

+1334
-1044
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ lerna-debug.log*
3535
!.vscode/settings.json
3636
!.vscode/tasks.json
3737
!.vscode/launch.json
38-
!.vscode/extensions.json
38+
!.vscode/extensions.json
39+
.prettierrc

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
"test:e2e": "jest --config ./test/jest-e2e.json"
2121
},
2222
"dependencies": {
23+
"@nestjs/axios": "^3.0.1",
2324
"@nestjs/common": "^10.0.0",
2425
"@nestjs/config": "^3.1.1",
2526
"@nestjs/core": "^10.0.0",
2627
"@nestjs/platform-express": "^10.0.0",
27-
"@samagra-x/gupshup-whatsapp-adapter": "^1.0.0",
28+
"@samagra-x/gupshup-whatsapp-adapter": "1.0.2",
2829
"@samagra-x/xmessage": "^1.0.1",
2930
"@supabase/supabase-js": "^2.38.5",
3031
"axios": "^1.6.2",

src/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppController } from './app.controller';
33
import { AppService } from './app.service';
44
import { MessageModule } from './message/message.module';
55
import { ConfigModule } from '@nestjs/config';
6+
import { UserModule } from './user/user.module';
67

78
@Module({
89
imports: [

src/main.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
3-
// import axios from 'axios';
4-
// import {XMessage, MessageState, MessageType} from "xmessage";
5-
// import {} from "userservice";
6-
// import {configService} from "botservice";
7-
// import {GSWhatsAppMessage, convertXMessageToMsg} from "gupshup-whatsapp-adapter";
8-
// import { measureMemory } from 'vm';
93

104
async function bootstrap() {
115
const app = await NestFactory.create(AppModule);

src/message/controllers/inbound.message.controller.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Controller, Get, Post, Body, Logger } from '@nestjs/common';
2+
import { GSWhatsAppMessage } from '@samagra-x/gupshup-whatsapp-adapter';
3+
import { ConfigService } from '@nestjs/config';
4+
import { GupshupWhatsappInboundService } from '../../services/inbound/gupshup.whatsapp.service';
5+
6+
@Controller('/inbound/gupshup/whatsapp')
7+
export class GupshupWhatsappInboundController {
8+
constructor(
9+
private configService: ConfigService,
10+
private readonly inboundService: GupshupWhatsappInboundService
11+
) {}
12+
private readonly logger = new Logger(GupshupWhatsappInboundController.name);
13+
14+
@Get('/health')
15+
async verifyEndpointIsActive(): Promise<string> {
16+
return 'Endpoint Active!';
17+
}
18+
19+
@Post()
20+
async handleIncomingMessageData(@Body() requestData: GSWhatsAppMessage): Promise<any> {
21+
if ("mobile" in requestData){
22+
this.logger.log(requestData)
23+
await this.inboundService.handleIncomingGsWhatsappMessage(requestData);
24+
}
25+
}
26+
}

src/message/controllers/orchestrator.message.controller.ts

Whitespace-only changes.
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { Body, Controller, Post } from '@nestjs/common';
2-
import { XMessage } from '@samagra-x/xmessage';
1+
import { Body, Controller, Logger, Post } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
3+
import { MessageState, XMessage } from '@samagra-x/xmessage';
34
import { OutboundService } from 'src/message/services/outbound/outbound.service';
45

56
@Controller('/outbound/gupshup/whatsapp')
67
export class OutboundMessageController {
7-
constructor(private readonly outboundService: OutboundService) {}
8+
constructor(private readonly outboundService: OutboundService, private readonly configService: ConfigService,) {}
9+
private readonly logger = new Logger(OutboundMessageController.name);
810

911
@Post()
1012
async handleIncomingXMessage(@Body() orchestratorRequest: XMessage): Promise<any> {
11-
await this.outboundService.handleOrchestratorRequest(orchestratorRequest)
13+
this.logger.log('Orchestrator Request', orchestratorRequest);
14+
const botMobileNumber = this.configService.get<string>('BOT_MOBILE_NUMBER')
15+
const credentials = await this.outboundService.getAdapterCredentials(botMobileNumber);
16+
orchestratorRequest.messageState = MessageState.REPLIED;
17+
await this.outboundService.handleOrchestratorResponse(orchestratorRequest, credentials);
1218
}
13-
1419
}

src/message/dto/xmessage.dto.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import { IsUUID, IsString, IsOptional, IsArray, IsEnum, IsNumber } from 'class-validator';
22
import { MessageState } from '@samagra-x/xmessage';
33

4-
export enum MessageStatus {
5-
DEFAULT = 'DEFAULT',
6-
DELIVERED = 'DELIVERED',
7-
RECEIVED = 'RECEIVED',
8-
SENT = 'SENT',
9-
PROCESSED = 'PROCESSED',
10-
}
11-
124
export class XMessageDbDto {
135
@IsOptional()
146
@IsUUID()
@@ -29,7 +21,7 @@ export class XMessageDbDto {
2921
provider?: string;
3022

3123
@IsNumber()
32-
timestamp: string;
24+
timestamp: number;
3325

3426
@IsOptional()
3527
@IsString()
@@ -88,7 +80,7 @@ export class XMessageDbDto {
8880
@IsString()
8981
remarks?: string;
9082

91-
// @IsOptional()
92-
// @IsEnum(MessageStatus)
93-
// status?: MessageStatus;
83+
@IsOptional()
84+
@IsEnum(MessageState)
85+
status?: MessageState;
9486
}

src/message/message.module.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { Module } from '@nestjs/common';
2-
import { MessageController } from './controllers/inbound.message.controller';
3-
import { InboundService } from './services/inbound/inbound.service';
2+
import { GupshupWhatsappInboundController } from './controllers/inbound/gupshup.whatsapp.controller';
3+
import { GupshupWhatsappInboundService } from './services/inbound/gupshup.whatsapp.service';
44
import { ConfigModule } from '@nestjs/config';
55
import { OutboundService } from './services/outbound/outbound.service';
6+
import { CredentialService } from './services/credentials/credentials.service';
7+
import { OutboundMessageController } from './controllers/outbound/outbound.controller';
8+
import { UserModule } from 'src/user/user.module';
9+
import { SupabaseService } from './services/supabase.service';
10+
import { FeedbackService } from './services/feedback/feedback.service';
611

712
@Module({
8-
imports: [ConfigModule.forRoot()],
9-
controllers: [MessageController],
10-
providers: [
11-
InboundService,
12-
OutboundService
13-
],
13+
imports: [ConfigModule.forRoot(), UserModule],
14+
controllers: [GupshupWhatsappInboundController, OutboundMessageController],
15+
providers: [GupshupWhatsappInboundService, OutboundService, CredentialService, SupabaseService, FeedbackService]
1416
})
15-
export class MessageModule {}
17+
export class MessageModule {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Injectable, Logger } from '@nestjs/common';
2+
import axios from 'axios';
3+
4+
@Injectable()
5+
export class CredentialService {
6+
private readonly logger = new Logger(CredentialService.name);
7+
async getCredentialsFromVault(
8+
baseUrl: string,
9+
secretPath: string,
10+
headers: Record<string, string>
11+
) {
12+
const webClient = axios.create({
13+
baseURL: baseUrl,
14+
headers: headers
15+
});
16+
17+
const response = await webClient.get(`${secretPath}`);
18+
return response.data
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Injectable, Logger } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
3+
import axios from 'axios';
4+
5+
@Injectable()
6+
export class FeedbackService {
7+
private readonly logger = new Logger(FeedbackService.name);
8+
9+
constructor(private readonly configService: ConfigService) {}
10+
11+
async givePositiveFeedback(messageId) {
12+
const orchestratorUrl = this.configService.get<string>('ORCHESTRATOR_API_ENDPOINT');
13+
const feedbackUrl = `${orchestratorUrl}/feedback/query/like/${messageId}`;
14+
15+
await axios.get(feedbackUrl);
16+
}
17+
18+
async giveNegativeFeedback(messageId) {
19+
const orchestratorUrl = this.configService.get<string>('ORCHESTRATOR_API_ENDPOINT');
20+
const feedbackUrl = `${orchestratorUrl}/feedback/query/dislike/${messageId}`;
21+
22+
await axios.get(feedbackUrl)
23+
}
24+
}

0 commit comments

Comments
 (0)