feat: integrate WhatsApp notifications for booking registration and rescheduling
parent
8192396085
commit
ffc75ba174
|
@ -5,6 +5,7 @@ import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
||||||
import { CreateTransactionManager } from 'src/modules/transaction/transaction/domain/usecases/managers/create-transaction.manager';
|
import { CreateTransactionManager } from 'src/modules/transaction/transaction/domain/usecases/managers/create-transaction.manager';
|
||||||
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
||||||
import { mappingRevertTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
import { mappingRevertTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
||||||
|
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
export class CreateBookingManager extends CreateTransactionManager {
|
export class CreateBookingManager extends CreateTransactionManager {
|
||||||
|
@ -43,4 +44,20 @@ export class CreateBookingManager extends CreateTransactionManager {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
const whatsapp = new WhatsappService();
|
||||||
|
console.log(`/snap/v4/redirection/${this.data.payment_midtrans_token}`);
|
||||||
|
console.log(this.data.payment_midtrans_url);
|
||||||
|
await whatsapp.bookingRegister(
|
||||||
|
{
|
||||||
|
phone: this.data.customer_phone,
|
||||||
|
code: this.data.invoice_code,
|
||||||
|
name: this.data.customer_name,
|
||||||
|
time: this.data.booking_date,
|
||||||
|
id: this.data.id,
|
||||||
|
},
|
||||||
|
`snap/v4/redirection/${this.data.payment_midtrans_token}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,12 @@ export class RescheduleVerificationManager {
|
||||||
});
|
});
|
||||||
|
|
||||||
const whatsapp = new WhatsappService();
|
const whatsapp = new WhatsappService();
|
||||||
whatsapp.sendOtpNotification({
|
whatsapp.bookingReschedule({
|
||||||
phone: transaction.customer_phone,
|
phone: transaction.customer_phone,
|
||||||
code: otp.toString(),
|
code: otp.toString(),
|
||||||
|
name: transaction.customer_name,
|
||||||
|
time: new Date(request.reschedule_date).getTime(),
|
||||||
|
id: transaction.id,
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -199,6 +199,118 @@ export class WhatsappService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async bookingRegister(data: WhatsappBookingCreate, paymentUrl: string) {
|
||||||
|
const momentDate = moment(data.time);
|
||||||
|
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
messaging_product: 'whatsapp',
|
||||||
|
to: phoneNumberOnly(data.phone), // recipient's phone number
|
||||||
|
type: 'template',
|
||||||
|
template: {
|
||||||
|
name: 'booking_register',
|
||||||
|
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: 'booking_date',
|
||||||
|
text: fallbackValue,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
sub_type: 'url',
|
||||||
|
index: '0',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: paymentUrl, // replace with dynamic URL
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await this.sendMessage(payload);
|
||||||
|
if (response)
|
||||||
|
Logger.log(
|
||||||
|
`Notification register Booking for ${data.code} send to ${data.phone}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async bookingReschedule(data: WhatsappBookingCreate) {
|
||||||
|
const momentDate = moment(data.time);
|
||||||
|
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
messaging_product: 'whatsapp',
|
||||||
|
to: phoneNumberOnly(data.phone), // recipient's phone number
|
||||||
|
type: 'template',
|
||||||
|
template: {
|
||||||
|
name: 'booking_reschedule',
|
||||||
|
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: 'booking_code',
|
||||||
|
text: data.code, // replace with queue_code variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
parameter_name: 'booking_date',
|
||||||
|
text: fallbackValue,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
parameter_name: 'otp',
|
||||||
|
text: data.code,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
sub_type: 'copy_code',
|
||||||
|
index: '0',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
type: 'coupon_code',
|
||||||
|
coupon_code: data.code,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await this.sendMessage(payload);
|
||||||
|
if (response)
|
||||||
|
Logger.log(
|
||||||
|
`Notification reschedule Booking for ${data.code} send to ${data.phone}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async sendOtpNotification(data: { phone: string; code: string }) {
|
async sendOtpNotification(data: { phone: string; code: string }) {
|
||||||
// Compose the WhatsApp message payload for OTP using Facebook WhatsApp API
|
// Compose the WhatsApp message payload for OTP using Facebook WhatsApp API
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
Loading…
Reference in New Issue