Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile.asterisk-worker
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Install dependencies only when needed
FROM node:20-alpine3.19 AS deps
WORKDIR /usr/src/app
COPY ./dist/apps/asterisk-worker/package.json .npmrc ./
COPY ./dist/apps/asterisk-worker/package.json ./
RUN npm install -g pnpm@8.14.1 && pnpm install

FROM node:20-alpine3.19 AS builder
Expand Down
16 changes: 16 additions & 0 deletions apps/asterisk-worker/src/workers/ivr.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class IVRService implements OnModuleInit, OnModuleDestroy {
private isConnected = false;
private isShuttingDown = false;
private reconnectTimer: NodeJS.Timeout | null = null;
private broadcastAddressPrefix: string | null;

constructor(
private readonly batchManager: BatchManager,
Expand All @@ -40,13 +41,28 @@ export class IVRService implements OnModuleInit, OnModuleDestroy {
audioPath: process.env.ASTERISK_AUDIO_PATH,
callerId: process.env.ASTERISK_CALLER_ID,
};
this.broadcastAddressPrefix = process.env.BROADCAST_ADDRESS_PREFIX || null;
this.logger.log('IVRService initialized', this.config);
}

callEndpoint = (broadcastAddress: string) => {
// Strip +977 prefix if present
if (broadcastAddress.startsWith('+977')) {
this.logger.log(`Stripping '+977' prefix from broadcast address: ${broadcastAddress}`);
broadcastAddress = broadcastAddress.slice(4);
}
if (broadcastAddress.startsWith('977')) {
this.logger.log(`Stripping '977' prefix from broadcast address: ${broadcastAddress}`);
broadcastAddress = broadcastAddress.slice(3);
}

// Apply broadcast address prefix if configured
if (this.broadcastAddressPrefix) {
this.logger.log(`Applying broadcast address prefix: ${this.broadcastAddressPrefix} to ${broadcastAddress}`);
broadcastAddress = `${this.broadcastAddressPrefix}${broadcastAddress}`;
}

this.logger.log(`Constructed call endpoint for broadcast address: ${broadcastAddress}`);
return `${this.config.trunk}/${broadcastAddress}`;
};

Expand Down
Loading