This commit is contained in:
natib21
2026-06-24 10:02:16 +00:00
parent 9c7300dcac
commit 0e351fa0b4
4 changed files with 77 additions and 11 deletions

View File

@@ -27,9 +27,29 @@ export class NotificationsService {
if (!strategy) {
throw new NotFoundException();
}
const sent = await strategy.send(recipient, message)
this.logger.log(`is sent - ${sent}`)
const sent = await strategy.send(recipient, message);
this.logger.log(`is sent - ${sent}`);
}
async notifyDriverVehicleAssignment(params: {
driverPhone: string;
driverName: string;
vehiclePlateNumber: string;
bookingReference: string;
pickupAddress?: string | null;
destinationYard?: string | null;
}): Promise<void> {
const { driverPhone, driverName, vehiclePlateNumber, bookingReference, pickupAddress, destinationYard } = params;
const message =
`Dear ${driverName}, you have been assigned to a first-mile pickup. ` +
`Booking: ${bookingReference}. Vehicle: ${vehiclePlateNumber}. ` +
(pickupAddress ? `Pickup: ${pickupAddress}. ` : '') +
(destinationYard ? `Destination: ${destinationYard}.` : '');
try {
await this.directSend('sms', driverPhone, message);
} catch (err) {
this.logger.error(`Failed to notify driver ${driverName} (${driverPhone}): ${String(err)}`);
}
}
}

View File

@@ -8,16 +8,19 @@ import { firstValueFrom } from 'rxjs';
export class SmsNotificationStrategy implements NotificationStrategy {
constructor(private readonly httpService: HttpService, private readonly configService: ConfigService) { }
async send(recipient: string, message: string) {
const url = this.configService.get("OZIKING_SMS_URL")
const url = this.configService.get("OZIKING_SMS_URL");
const body = {
to: recipient,
text: message
}
sourceId: this.configService.get("OZIKING_SOURCE_ID") ?? "EDR",
sourceName: this.configService.get("OZIKING_SOURCE_NAME") ?? "EDR Freight",
appKey: this.configService.get("OZIKING_APP_KEY") ?? "",
text: message,
callbackUrl: "",
};
const response = await firstValueFrom(
this.httpService.post(
url,
body,
),
this.httpService.post(url, body, {
headers: { accept: "*/*", "Content-Type": "application/json" },
}),
);
return response.status === 201;