feat: implement booking expired notification in WhatsApp service

pull/142/head
shancheas 2025-06-19 14:40:17 +07:00
parent afad02ba52
commit a5da557dd9
2 changed files with 67 additions and 0 deletions

View File

@ -77,6 +77,22 @@ export class MidtransCallbackHandler
await whatsappService.bookingCreated(payload);
}
if (
transaction.status === STATUS.EXPIRED &&
transaction.type === TransactionType.ONLINE
) {
const whatsappService = new WhatsappService();
const formattedDate = moment(transaction.booking_date);
const payload = {
id: transaction.id,
phone: transaction.customer_phone,
code: transaction.invoice_code,
name: transaction.customer_name,
time: formattedDate.valueOf(),
};
await whatsappService.bookingExpired(payload);
}
this.eventBus.publish(
new TransactionChangeStatusEvent({
id: data_id,

View File

@ -198,6 +198,57 @@ export class WhatsappService {
);
}
async bookingExpired(data: WhatsappBookingCreate) {
const momentDate = moment(data.time);
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
// const dayOfWeek = momentDate.day();
// const dayOfMonth = momentDate.date();
// const year = momentDate.year();
// const month = momentDate.month() + 1;
// const hour = momentDate.hour();
// const minute = momentDate.minute();
const payload = {
messaging_product: 'whatsapp',
to: phoneNumberOnly(data.phone), // recipient's phone number
type: 'template',
template: {
name: 'booking_expired',
language: {
code: 'id', // language code
},
components: [
{
type: 'body',
parameters: [
{
type: 'text',
parameter_name: 'customer',
text: data.name, // replace with name variable
},
{
type: 'text',
parameter_name: 'code',
text: data.code, // replace with queue_code variable
},
{
type: 'text',
parameter_name: 'booking_date',
text: fallbackValue,
},
],
},
],
},
};
const response = await this.sendMessage(payload);
if (response)
Logger.log(
`Notification register Booking for ${data.code} send to ${data.phone}`,
);
}
async rescheduleCreated(data: WhatsappBookingCreate) {
const imageUrl = `${BOOKING_QR_URL}${data.id}`;