Skip to content

Commit e1be5fd

Browse files
committed
Refactored inbound to unify endpoints.
1 parent 0598d05 commit e1be5fd

20 files changed

+132
-564
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
"@nestjs/config": "^3.1.1",
2626
"@nestjs/core": "^10.0.0",
2727
"@nestjs/platform-express": "^10.0.0",
28-
"@samagra-x/uci-adapters-gupshup-whatsapp-adapter": "1.0.7",
29-
"@samagra-x/uci-adapters-telegram-bot": "1.0.2",
30-
"@samagra-x/uci-adapters-pwa": "1.0.2",
31-
"@samagra-x/xmessage": "^1.0.10",
28+
"@samagra-x/xmessage": "^1.0.11",
3229
"@samagra-x/uci-adapters-factory": "^1.0.4",
3330
"@supabase/supabase-js": "^2.38.5",
3431
"axios": "^1.6.2",

src/message/controllers/inbound/gupshup.whatsapp.controller.spec.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

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

Lines changed: 0 additions & 46 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Controller, Get, Post, Body, Logger, Param, NotFoundException } from '@nestjs/common';
2-
import { PwaBotService } from 'src/message/services/inbound/pwa.bot.service';
2+
import { InboundService } from 'src/message/services/inbound/inbound.bot.service';
33
import { WebClientProvider } from 'src/message/services/webclient/webclient.provider';
44

5-
@Controller('/inbound/pwa/bot')
6-
export class PwaBotController {
5+
@Controller('/inbound/bot')
6+
export class InboundBotController {
77
constructor(
8-
private readonly pwaBotService: PwaBotService,
8+
private readonly inboundBotService: InboundService,
99
private readonly webclientProvider: WebClientProvider,
1010
) {}
11-
private readonly logger = new Logger(PwaBotController.name);
11+
private readonly logger = new Logger(InboundBotController.name);
1212

1313
@Get('/health')
1414
async verifyEndpointIsActive(): Promise<string> {
@@ -20,14 +20,14 @@ export class PwaBotController {
2020
@Param('botId') botId: string,
2121
@Body() updateObject
2222
): Promise<any> {
23-
this.logger.log("Received whatsapp message from user.");
23+
this.logger.log("Received message on inbound.");
2424
const botFetchRequest = await this.webclientProvider.getUciApiWebClient().get(
2525
`/admin/bot/${botId}`
2626
);
2727
if (botFetchRequest.status != 200 || !botFetchRequest.data || !botFetchRequest.data.result) {
2828
this.logger.error(botFetchRequest);
2929
throw new NotFoundException('Bot Not Found!');
3030
}
31-
this.pwaBotService.handleIncomingMessage(botFetchRequest.data.result, updateObject);
31+
this.inboundBotService.handleIncomingMessage(botFetchRequest.data.result, updateObject);
3232
}
3333
}

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/message/controllers/outbound/outbound.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MessageState, XMessage } from '@samagra-x/xmessage';
33
import { CredentialService } from 'src/message/services/credentials/credentials.service';
44
import { OutboundService } from 'src/message/services/outbound/outbound.service';
55

6-
@Controller('/outbound/gupshup/whatsapp')
6+
@Controller('/outbound')
77
export class OutboundMessageController {
88
constructor(
99
private readonly outboundService: OutboundService,

src/message/controllers/test.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/message/enums/status.enum.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/message/message.module.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
import { Module } from '@nestjs/common';
2-
import { GupshupWhatsappInboundController } from './controllers/inbound/gupshup.whatsapp.controller';
3-
import { GupshupWhatsappInboundService } from './services/inbound/gupshup.whatsapp.service';
42
import { ConfigModule } from '@nestjs/config';
53
import { OutboundService } from './services/outbound/outbound.service';
64
import { CredentialService } from './services/credentials/credentials.service';
75
import { OutboundMessageController } from './controllers/outbound/outbound.controller';
86
import { UserModule } from 'src/user/user.module';
97
import { SupabaseService } from './services/supabase/supabase.service';
108
import { FeedbackService } from './services/feedback/feedback.service';
11-
import { TelegramBotController } from './controllers/inbound/telegram.bot.controller';
9+
import { InboundBotController } from './controllers/inbound/inbound.bot.controller';
1210
import { WebClientProvider } from './services/webclient/webclient.provider';
13-
import { TelegramBotService } from './services/inbound/telegram.bot.service';
14-
import { PwaBotController } from './controllers/inbound/pwa.bot.controller';
15-
import { PwaBotService } from './services/inbound/pwa.bot.service';
11+
import { InboundService } from './services/inbound/inbound.bot.service';
1612

1713
@Module({
1814
imports: [ConfigModule.forRoot(), UserModule],
1915
controllers: [
20-
GupshupWhatsappInboundController,
21-
TelegramBotController,
22-
PwaBotController,
16+
InboundBotController,
2317
OutboundMessageController
2418
],
2519
providers: [
26-
GupshupWhatsappInboundService,
27-
TelegramBotService,
20+
InboundService,
2821
OutboundService,
2922
CredentialService,
3023
SupabaseService,
3124
FeedbackService,
3225
WebClientProvider,
33-
PwaBotService,
3426
]
3527
})
3628
export class MessageModule {}

src/message/services/credentials/credentials.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class CredentialService {
3030
}
3131
}
3232

33-
private async getCredentialsFromVault(
33+
async getCredentialsFromVault(
3434
variableName: string,
3535
): Promise<any> {
3636
const response = await this.webClientProvider.getUciApiWebClient({

src/message/services/feedback/feedback.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ export class FeedbackService {
88

99
constructor(private readonly configService: ConfigService) {}
1010

11-
async givePositiveFeedback(messageId) {
11+
async givePositiveFeedback(messageId: string) {
1212
const orchestratorUrl = this.configService.get<string>('ORCHESTRATOR_API_ENDPOINT');
1313
const feedbackUrl = `${orchestratorUrl}/feedback/query/like/${messageId}`;
1414

1515
await axios.get(feedbackUrl);
1616
}
1717

18-
async giveNegativeFeedback(messageId) {
18+
async giveNegativeFeedback(messageId: string) {
1919
const orchestratorUrl = this.configService.get<string>('ORCHESTRATOR_API_ENDPOINT');
2020
const feedbackUrl = `${orchestratorUrl}/feedback/query/dislike/${messageId}`;
2121

2222
await axios.get(feedbackUrl)
2323
}
24+
25+
async giveNeutralFeedback(messageId: string) {
26+
console.warn("Neutral Feedback not implemented!");
27+
}
2428
}

0 commit comments

Comments
 (0)