bw-essentials-core 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

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.

Potentially problematic release.


This version of bw-essentials-core might be problematic. Click here for more details.

@@ -0,0 +1,77 @@
1
+ """
2
+ Module to make API calls to Notification Service
3
+ """
4
+ import logging
5
+
6
+ from bw_essentials.constants.services import Services
7
+ from bw_essentials.services.api_client import ApiClient
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ class NotificationService(ApiClient):
13
+ """
14
+ Handles notifications through various channels.
15
+ """
16
+ PLATFORM = "PLATFORM"
17
+ NOTIFICATION_API_KEY = 'NOTIFICATION_API_KEY'
18
+ NOTIFICATION_SENDER_NUMBER = "NOTIFICATION_SENDER_NUMBER"
19
+
20
+ def __init__(self):
21
+ """
22
+ Initializes the Notification object.
23
+
24
+ Args:
25
+ - user: The user associated with the notification.
26
+ """
27
+ super().__init__("notification")
28
+ self.name = Services.NOTIFICATION.value
29
+ self.base_url = self.get_base_url(self.name)
30
+ self.urls = {
31
+ "whatsapp": "whatsapp"
32
+ }
33
+
34
+ def _whatsapp(self, title, template, platform, params, to, user_id):
35
+ """
36
+ Sends a WhatsApp notification.
37
+
38
+ Args:
39
+ - user_id (str): The ID of the user receiving the notification.
40
+ - number (str): The phone number for the recipient.
41
+ - title (str): Title of the notification.
42
+ - template (str): Template for the WhatsApp message.
43
+ - platform (str): The platform used for sending
44
+ (WhatsApp, in this case).
45
+ - params: Parameters for the notification message.
46
+
47
+ Returns:
48
+ None
49
+ """
50
+ logger.info(f"In - whatsapp {user_id =}, {to =}, "
51
+ f"{title =}, {template =}, {platform =}, {params =}")
52
+ payload = {
53
+ "from": self._get_env_var(NotificationService.NOTIFICATION_SENDER_NUMBER),
54
+ "to": to,
55
+ "userId": user_id,
56
+ "platform": platform,
57
+ "title": title,
58
+ "template": template,
59
+ "params": params
60
+ }
61
+ logger.info(f"whatsapp {payload =}")
62
+ headers = {
63
+ 'api-key': self._get_env_var(NotificationService.NOTIFICATION_API_KEY)
64
+ }
65
+ self.set_headers(headers)
66
+ resp_data = self._post(url=self.base_url, endpoint=self.urls.get('whatsapp'), data=payload)
67
+ logger.info(f"Whatsapp response {resp_data =}")
68
+
69
+ def send_whatsapp(self, template, title, params, to, user_id):
70
+ logger.info(f"In - send_whatsapp_notification {user_id =} {title = } {params = } {to = }")
71
+
72
+ self._whatsapp(title=title,
73
+ template=template,
74
+ platform=self._get_env_var(NotificationService.PLATFORM),
75
+ params=params,
76
+ to=to,
77
+ user_id=user_id)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bw-essentials-core
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Reusable utilities for S3, email, Data Loch, Microsoft Teams Notifications and more.
5
5
  Author: InvestorAI
6
6
  Author-email: support+tech@investorai.in
@@ -16,11 +16,12 @@ bw_essentials/services/broker.py,sha256=As-VT1MxkCD9p-13dQJDwf0_aEJVA6H0wNqL-EYH
16
16
  bw_essentials/services/market_pricer.py,sha256=Qc9lxzAjhefAvjyEKsBPDu60bF6_61cnSpZNfjGMyDg,11755
17
17
  bw_essentials/services/master_data.py,sha256=2o_r2gdhIKBeTFgn5IIY-becgCEpYBymO4BKmixdV1g,11987
18
18
  bw_essentials/services/model_portfolio_reporting.py,sha256=iOtm4gyfU8P7C0R1gp6gUJI4ZRxJD5K2GLOalI_gToM,3249
19
+ bw_essentials/services/notification.py,sha256=OQD-rB7FaqcoyjRgFyl2pgeXWIgtYcUhRs_4uT1Em9A,2634
19
20
  bw_essentials/services/trade_placement.py,sha256=PrzeU2XXC9HF1IQ1dMDM_ZHxmC491sOl-JbA6GWPwII,20772
20
21
  bw_essentials/services/user_app.py,sha256=_Y2NgDq6kEoco7ZRJ3-MMYJ-K2HGStJoFoeGOH_HotQ,11107
21
22
  bw_essentials/services/user_portfolio.py,sha256=_5M6yPfQt4MXedINBawEoPkb_o7IGzxPeHkvZkoQm8k,16191
22
23
  bw_essentials/services/user_portfolio_reporting.py,sha256=QaZzcw912Uos5ZafEaxLXDmCyetTFiVX3at3cTAv6MA,6003
23
- bw_essentials_core-0.1.0.dist-info/METADATA,sha256=jara8u2pGS_rtKqecDPjm1TkRMhy8GdZwFlmC7YYz5s,7501
24
- bw_essentials_core-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
- bw_essentials_core-0.1.0.dist-info/top_level.txt,sha256=gDc5T_y5snwKGXDQUusEus-FEt0RFwG644Yn_58wQOQ,14
26
- bw_essentials_core-0.1.0.dist-info/RECORD,,
24
+ bw_essentials_core-0.1.1.dist-info/METADATA,sha256=c5-YYlMERt3ZzOLmu4hp78zV1t5bNCawWyWh6BIGY7o,7501
25
+ bw_essentials_core-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ bw_essentials_core-0.1.1.dist-info/top_level.txt,sha256=gDc5T_y5snwKGXDQUusEus-FEt0RFwG644Yn_58wQOQ,14
27
+ bw_essentials_core-0.1.1.dist-info/RECORD,,