dhisana 0.0.1.dev239__py3-none-any.whl → 0.0.1.dev241__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.
dhisana/schemas/common.py CHANGED
@@ -378,6 +378,7 @@ class SendEmailContext(BaseModel):
378
378
  sender_email: str
379
379
  labels: Optional[List[str]]
380
380
  body_format: BodyFormat = BodyFormat.AUTO
381
+ headers: Optional[Dict[str, str]] = None
381
382
 
382
383
  class QueryEmailContext(BaseModel):
383
384
  start_time: str
@@ -145,6 +145,12 @@ async def send_email_using_google_oauth_async(
145
145
  message["from"] = f"{send_email_context.sender_name} <{send_email_context.sender_email}>"
146
146
  message["subject"] = send_email_context.subject
147
147
 
148
+ extra_headers = getattr(send_email_context, "headers", None) or {}
149
+ for header, value in extra_headers.items():
150
+ if not header or value is None:
151
+ continue
152
+ message[header] = str(value)
153
+
148
154
  raw_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
149
155
 
150
156
  payload: Dict[str, Any] = {"raw": raw_message}
@@ -179,6 +179,12 @@ async def send_email_using_service_account_async(
179
179
  message['from'] = f"{send_email_context.sender_name} <{send_email_context.sender_email}>"
180
180
  message['subject'] = send_email_context.subject
181
181
 
182
+ extra_headers = getattr(send_email_context, "headers", None) or {}
183
+ for header, value in extra_headers.items():
184
+ if not header or value is None:
185
+ continue
186
+ message[header] = str(value)
187
+
182
188
  # Base64-encode the message
183
189
  raw_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
184
190
 
@@ -531,6 +537,7 @@ class SendEmailContext(BaseModel):
531
537
  sender_email: str
532
538
  labels: Optional[List[str]]
533
539
  body_format: BodyFormat = BodyFormat.AUTO
540
+ headers: Optional[Dict[str, str]] = None
534
541
 
535
542
  @assistant_tool
536
543
  async def send_email_using_service_account_async(
@@ -126,6 +126,12 @@ async def send_email_using_mailgun_async(
126
126
  "html": html_body,
127
127
  }
128
128
 
129
+ extra_headers = getattr(send_email_context, "headers", None) or {}
130
+ for header, value in extra_headers.items():
131
+ if not header or value is None:
132
+ continue
133
+ data[f"h:{header}"] = str(value)
134
+
129
135
  async with aiohttp.ClientSession() as session:
130
136
  async with session.post(
131
137
  f"https://api.mailgun.net/v3/{domain}/messages",
@@ -0,0 +1,123 @@
1
+ import os
2
+ import aiohttp
3
+ import logging
4
+ from typing import List, Dict, Any, Optional
5
+ from dhisana.utils.assistant_tool_tag import assistant_tool
6
+
7
+ logging.basicConfig(level=logging.INFO)
8
+ logger = logging.getLogger(__name__)
9
+
10
+ base_url = 'https://api.mailreach.co/api/v1'
11
+
12
+
13
+ def get_mailreach_api_key(tool_config: Optional[List[Dict]] = None) -> str:
14
+ """
15
+ Retrieves the MailReach API key from the provided tool configuration or environment variables.
16
+
17
+ Args:
18
+ tool_config (list): A list of dictionaries containing the tool configuration.
19
+ Each dictionary should have a "name" key and a "configuration" key,
20
+ where "configuration" is a list of dictionaries containing "name" and "value" keys.
21
+
22
+ Returns:
23
+ str: The MailReach API key.
24
+
25
+ Raises:
26
+ ValueError: If the MailReach integration has not been configured.
27
+ """
28
+ api_key = None
29
+
30
+ if tool_config:
31
+ mailreach_config = next(
32
+ (item for item in tool_config if item.get("name") == "mailreach"), None
33
+ )
34
+ if mailreach_config:
35
+ config_map = {
36
+ item["name"]: item["value"]
37
+ for item in mailreach_config.get("configuration", [])
38
+ if item
39
+ }
40
+ api_key = config_map.get("apiKey")
41
+
42
+ api_key = api_key or os.getenv("MAILREACH_API_KEY")
43
+
44
+ if not api_key:
45
+ raise ValueError(
46
+ "MailReach integration is not configured. Please configure the connection to MailReach in Integrations."
47
+ )
48
+
49
+ return api_key
50
+
51
+
52
+ def get_mailreach_headers(tool_config: Optional[List[Dict]] = None) -> Dict[str, str]:
53
+ """
54
+ Get the headers required for MailReach API requests.
55
+
56
+ Args:
57
+ tool_config (list): Optional tool configuration containing API credentials.
58
+
59
+ Returns:
60
+ Dict[str, str]: Headers dictionary with x-api-key and Content-Type.
61
+ """
62
+ api_key = get_mailreach_api_key(tool_config)
63
+ headers = {
64
+ "x-api-key": api_key,
65
+ "Content-Type": "application/json"
66
+ }
67
+ return headers
68
+
69
+
70
+ async def _handle_mailreach_response(response: aiohttp.ClientResponse) -> Any:
71
+ """
72
+ Handle MailReach API responses consistently.
73
+
74
+ Args:
75
+ response: The aiohttp ClientResponse object.
76
+
77
+ Returns:
78
+ The JSON response data.
79
+
80
+ Raises:
81
+ aiohttp.ClientResponseError: For rate limits or other errors.
82
+ """
83
+ if response.status == 200:
84
+ return await response.json()
85
+ elif response.status == 429:
86
+ raise aiohttp.ClientResponseError(
87
+ request_info=response.request_info,
88
+ history=response.history,
89
+ status=response.status,
90
+ message="Rate limit exceeded",
91
+ headers=response.headers
92
+ )
93
+ else:
94
+ error_message = await response.text()
95
+ logger.error(f"MailReach API Error {response.status}: {error_message}")
96
+ response.raise_for_status()
97
+
98
+
99
+ @assistant_tool
100
+ async def ping_mailreach(
101
+ tool_config: Optional[List[Dict]] = None
102
+ ) -> Dict[str, Any]:
103
+ """
104
+ Ping the MailReach API to verify connectivity and authentication.
105
+
106
+ This is a simple endpoint to test if your API key is valid and the service is accessible.
107
+
108
+ Args:
109
+ tool_config (list): Optional tool configuration containing API credentials.
110
+
111
+ Returns:
112
+ Dict[str, Any]: Response from the ping endpoint, typically containing a success message.
113
+ """
114
+ url = f"{base_url}/ping"
115
+ headers = get_mailreach_headers(tool_config)
116
+
117
+ logger.info("Pinging MailReach API...")
118
+
119
+ async with aiohttp.ClientSession() as session:
120
+ async with session.get(url, headers=headers) as response:
121
+ result = await _handle_mailreach_response(response)
122
+ logger.info("MailReach ping successful")
123
+ return result
@@ -168,6 +168,14 @@ async def send_email_using_microsoft_graph_async(
168
168
  ],
169
169
  }
170
170
 
171
+ extra_headers = getattr(send_email_context, "headers", None) or {}
172
+ if extra_headers:
173
+ message_payload["internetMessageHeaders"] = [
174
+ {"name": header, "value": str(value)}
175
+ for header, value in extra_headers.items()
176
+ if header and value is not None
177
+ ]
178
+
171
179
  headers = {
172
180
  "Authorization": f"Bearer {token}",
173
181
  "Content-Type": "application/json",
@@ -59,6 +59,7 @@ async def send_email_with_sendgrid(
59
59
  message: str,
60
60
  tool_config: Optional[List[Dict]] = None,
61
61
  body_format: Optional[str] = None,
62
+ custom_headers: Optional[Dict[str, str]] = None,
62
63
  ):
63
64
  """
64
65
  Send an email using SendGrid's v3 Mail Send API.
@@ -69,6 +70,7 @@ async def send_email_with_sendgrid(
69
70
  - subject: Subject string.
70
71
  - message: HTML body content.
71
72
  - tool_config: Optional integration configuration list.
73
+ - custom_headers: Optional mapping of header names to values.
72
74
  """
73
75
  api_key = get_sendgrid_api_key(tool_config)
74
76
 
@@ -98,6 +100,13 @@ async def send_email_with_sendgrid(
98
100
  "content": content,
99
101
  }
100
102
 
103
+ if custom_headers:
104
+ payload["headers"] = {
105
+ header: str(value)
106
+ for header, value in custom_headers.items()
107
+ if header and value is not None
108
+ }
109
+
101
110
  headers = {
102
111
  "Authorization": f"Bearer {api_key}",
103
112
  "Content-Type": "application/json",
@@ -143,6 +152,7 @@ async def send_email_using_sendgrid_async(
143
152
  message=ctx.body or "",
144
153
  body_format=getattr(ctx, "body_format", None),
145
154
  tool_config=tool_config,
155
+ custom_headers=getattr(ctx, "headers", None),
146
156
  )
147
157
  # Normalise output to a string id-like value
148
158
  if isinstance(result, dict) and result.get("status") == 202:
@@ -174,6 +174,12 @@ async def send_email_via_smtp_async(
174
174
  generated_id = f"<{uuid.uuid4()}@{domain_part}>"
175
175
  msg["Message-ID"] = generated_id
176
176
 
177
+ extra_headers = getattr(ctx, "headers", None) or {}
178
+ for header, value in extra_headers.items():
179
+ if not header or value is None:
180
+ continue
181
+ msg[header] = str(value)
182
+
177
183
  smtp_kwargs = dict(
178
184
  hostname=smtp_server,
179
185
  port=smtp_port,
@@ -483,6 +483,31 @@ async def test_sendgrid(api_key: str) -> Dict[str, Any]:
483
483
  return {"success": False, "status_code": 0, "error_message": str(e)}
484
484
 
485
485
 
486
+ async def test_mailreach(api_key: str) -> Dict[str, Any]:
487
+ """
488
+ Basic MailReach connectivity check using the Ping endpoint.
489
+
490
+ Uses the /v1/ping endpoint to verify API key validity and service availability.
491
+ Reference: https://docs.mailreach.co/reference/getv1ping
492
+ """
493
+ url = "https://api.mailreach.co/api/v1/ping"
494
+ headers = {"x-api-key": api_key}
495
+ try:
496
+ async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10)) as session:
497
+ async with session.get(url, headers=headers) as response:
498
+ status = response.status
499
+ data = await safe_json(response)
500
+ if status != 200:
501
+ msg = None
502
+ if data and isinstance(data, dict):
503
+ msg = data.get("message") or data.get("error")
504
+ return {"success": False, "status_code": status, "error_message": msg or f"MailReach non-200: {status}"}
505
+ return {"success": True, "status_code": status, "error_message": None}
506
+ except Exception as e:
507
+ logger.error(f"MailReach test failed: {e}")
508
+ return {"success": False, "status_code": 0, "error_message": str(e)}
509
+
510
+
486
511
  async def test_samgov(api_key: str) -> Dict[str, Any]:
487
512
  """Test SAM.gov connectivity by fetching a single opportunity."""
488
513
 
@@ -1789,6 +1814,7 @@ async def test_connectivity(tool_config: List[Dict[str, Any]]) -> Dict[str, Dict
1789
1814
  "mcpServer": test_mcp_server,
1790
1815
  "slack": test_slack,
1791
1816
  "mailgun": test_mailgun,
1817
+ "mailreach": test_mailreach,
1792
1818
  "sendgrid": test_sendgrid,
1793
1819
  "samgov": test_samgov,
1794
1820
  "scraperapi": test_scraperapi,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dhisana
3
- Version: 0.0.1.dev239
3
+ Version: 0.0.1.dev241
4
4
  Summary: A Python SDK for Dhisana AI Platform
5
5
  Home-page: https://github.com/dhisana-ai/dhisana-python-sdk
6
6
  Author: Admin
@@ -5,7 +5,7 @@ dhisana/cli/datasets.py,sha256=OwzoCrVQqmh0pKpUAKAg_w9uGYncbWU7ZrAL_QukxAk,839
5
5
  dhisana/cli/models.py,sha256=IzUFZW_X32mL3fpM1_j4q8AF7v5nrxJcxBoqvG-TTgA,706
6
6
  dhisana/cli/predictions.py,sha256=VYgoLK1Ksv6MFImoYZqjQJkds7e5Hso65dHwbxTNNzE,646
7
7
  dhisana/schemas/__init__.py,sha256=jv2YF__bseklT3OWEzlqJ5qE24c4aWd5F4r0TTjOrWQ,65
8
- dhisana/schemas/common.py,sha256=rt1ho4nzVhTwTQ_1Kx5TI-xZSbnyDpYN0fQ8Fgf8z6k,9332
8
+ dhisana/schemas/common.py,sha256=WZJDobtNRJaqY51UhRL2axhft8AHHiD1kw794IaR-W8,9377
9
9
  dhisana/schemas/sales.py,sha256=XGPdTuHoNjvkq-xQtEh5Qfg5MQQoaJdDmu46aObBCV0,34219
10
10
  dhisana/ui/__init__.py,sha256=jv2YF__bseklT3OWEzlqJ5qE24c4aWd5F4r0TTjOrWQ,65
11
11
  dhisana/ui/components.py,sha256=4NXrAyl9tx2wWwoVYyABO-EOGnreGMvql1AkXWajIIo,14316
@@ -46,15 +46,16 @@ dhisana/utils/generate_linkedin_connect_message.py,sha256=WZThEun-DMuAOqlzMI--hG
46
46
  dhisana/utils/generate_linkedin_response_message.py,sha256=-jg-u5Ipf4-cn9q0yjEHsEBe1eJhYLCLrjZDtOXnCyQ,14464
47
47
  dhisana/utils/generate_structured_output_internal.py,sha256=DmZ5QzW-79Jo3JL5nDCZQ-Fjl8Nz7FHK6S0rZxXbKyg,20705
48
48
  dhisana/utils/google_custom_search.py,sha256=5rQ4uAF-hjFpd9ooJkd6CjRvSmhZHhqM0jfHItsbpzk,10071
49
- dhisana/utils/google_oauth_tools.py,sha256=RbZvmjnueb8At35_kJOfFwDR36PN3ofh3iVV8ugJMwM,28307
50
- dhisana/utils/google_workspace_tools.py,sha256=6z2PngTumEwtS9L9zXEpdtpAoD2sFYfpc7md6z7_p_o,48869
49
+ dhisana/utils/google_oauth_tools.py,sha256=ReG5lCpXL3_e_s0yn6ai4U7B4-feOWHJVtbv_c0g0rE,28525
50
+ dhisana/utils/google_workspace_tools.py,sha256=axHOrbSs5Yod0kREdu11T53GMjZn4pyuVjQCA51UntY,49132
51
51
  dhisana/utils/hubspot_clearbit.py,sha256=keNX1F_RnDl9AOPxYEOTMdukV_A9g8v9j1fZyT4tuP4,3440
52
52
  dhisana/utils/hubspot_crm_tools.py,sha256=lbXFCeq690_TDLjDG8Gm5E-2f1P5EuDqNf5j8PYpMm8,99298
53
53
  dhisana/utils/instantly_tools.py,sha256=hhqjDPyLE6o0dzzuvryszbK3ipnoGU2eBm6NlsUGJjY,4771
54
54
  dhisana/utils/linkedin_crawler.py,sha256=6fMQTY5lTw2kc65SFHgOAM6YfezAS0Yhg-jkiX8LGHo,6533
55
55
  dhisana/utils/lusha_tools.py,sha256=MdiWlxBBjSNpSKz8rhNOyLPtbeh-YWHgGiUq54vN_gM,12734
56
- dhisana/utils/mailgun_tools.py,sha256=qUD-jFMZpmkkkKtyihVSe9tgFzYe-UiiBDHQKtsLq0M,5284
57
- dhisana/utils/microsoft365_tools.py,sha256=aNIUBBz56HhvnEd0ZMy5EGAtsXcBJ_VOMO5Yy4dyojQ,18289
56
+ dhisana/utils/mailgun_tools.py,sha256=OTesN8spYrvoH4Q5BheC8TPUvUlfbZhliYOhzCrD7Mg,5506
57
+ dhisana/utils/mailreach_tools.py,sha256=uJ_gIcg8qrj5-k3jnYYhpwLVnQncoA1swzr5Jfkc1JU,3864
58
+ dhisana/utils/microsoft365_tools.py,sha256=ClqBzTrJ2SZM5K9nsOFyyHRfV-d-6jlxXNpNONtgLlY,18596
58
59
  dhisana/utils/openai_assistant_and_file_utils.py,sha256=-eyPcxFvtS-DDtYQGle1SU6C6CuxjulVIojFy27HeWc,8957
59
60
  dhisana/utils/openai_helpers.py,sha256=ZK9S5-jcLCpiiD6XBLkCqYcNz-AGYmO9xh4e2H-FDLo,40155
60
61
  dhisana/utils/openapi_spec_to_tools.py,sha256=oBLVq3WeDWvW9O02NCvY8bxQURQdKwHJHGcX8bC_b2I,1926
@@ -68,7 +69,7 @@ dhisana/utils/sales_navigator_crawler.py,sha256=z8yurwUTLXdM71xWPDSAFNuDyA_SlanT
68
69
  dhisana/utils/salesforce_crm_tools.py,sha256=r6tROej4PtfcRN2AViPD7tV24oxBNm6QCE7uwhDH5Hc,17169
69
70
  dhisana/utils/search_router.py,sha256=p_1MPHbjalBM8gZuU4LADbmqSLNtZ4zll6CbPOc0POU,4610
70
71
  dhisana/utils/search_router_jobs.py,sha256=LgCHNGLMSv-ovgzF32muprfaDTdTpIKgrP5F7swAqhk,1721
71
- dhisana/utils/sendgrid_tools.py,sha256=Q3Mr7mF0iM_zoF-Vhb1lH5r8AyqkVGgYXaCMR2i7zLQ,5157
72
+ dhisana/utils/sendgrid_tools.py,sha256=VyiLbQfa0xYY-onWqhHRcNKL7z-Wev-t4lim1d-vDVw,5526
72
73
  dhisana/utils/serarch_router_local_business.py,sha256=n9yZjeXKOSgBnr0lCSQomP1nN3ucbC9ZTTSmSHQLeVo,2920
73
74
  dhisana/utils/serpapi_additional_tools.py,sha256=Xb1tc_oK-IjI9ZrEruYhFg8UJMLHQDaO9B51YiNbeBs,10569
74
75
  dhisana/utils/serpapi_google_jobs.py,sha256=HUJFZEW8UvYqsW0sWlEDXgI_IUomh5fTkzRJzEgsDGc,4509
@@ -78,8 +79,8 @@ dhisana/utils/serpapi_search_tools.py,sha256=xiiYi6Rd6Mqn94mjSKEs5nNZk1l2-PW_hTL
78
79
  dhisana/utils/serperdev_google_jobs.py,sha256=m5_2f_5y79FOFZz1A_go6m0hIUfbbAoZ0YTjUMO2BSI,4508
79
80
  dhisana/utils/serperdev_local_business.py,sha256=JoZfTg58Hojv61cyuwA2lcnPdLT1lawnWaBNrUYWnuQ,6447
80
81
  dhisana/utils/serperdev_search.py,sha256=_iBKIfHMq4gFv5StYz58eArriygoi1zW6VnLlux8vto,9363
81
- dhisana/utils/smtp_email_tools.py,sha256=_1FoN6e-rgkjAKnCVym_IvihJFKz_dOo-43iM6CVqhA,21855
82
- dhisana/utils/test_connect.py,sha256=_FHEWUvEjqMjxrjMuZQY9c2hrB_HJjxY09IcikH130A,85459
82
+ dhisana/utils/smtp_email_tools.py,sha256=J9uDHCEu2BTyFzDBru0e1lC8bsAMt9c_mYXTzJgk9Kc,22054
83
+ dhisana/utils/test_connect.py,sha256=pYR1Ki6WKx-vAhLJxQ6At627xfOnlQeVRjnW7FBdGKM,86702
83
84
  dhisana/utils/trasform_json.py,sha256=7V72XNDpuxUX0GHN5D83z4anj_gIf5zabaHeQm7b1_E,6979
84
85
  dhisana/utils/web_download_parse_tools.py,sha256=ouXwH7CmjcRjoBfP5BWat86MvcGO-8rLCmWQe_eZKjc,7810
85
86
  dhisana/utils/workflow_code_model.py,sha256=YPWse5vBb3O6Km2PvKh1Q3AB8qBkzLt1CrR5xOL9Mro,99
@@ -93,8 +94,8 @@ dhisana/workflow/agent.py,sha256=esv7_i_XuMkV2j1nz_UlsHov_m6X5WZZiZm_tG4OBHU,565
93
94
  dhisana/workflow/flow.py,sha256=xWE3qQbM7j2B3FH8XnY3zOL_QXX4LbTW4ArndnEYJE0,1638
94
95
  dhisana/workflow/task.py,sha256=HlWz9mtrwLYByoSnePOemBUBrMEcj7KbgNjEE1oF5wo,1830
95
96
  dhisana/workflow/test.py,sha256=E7lRnXK0PguTNzyasHytLzTJdkqIPxG5_4qk4hMEeKc,3399
96
- dhisana-0.0.1.dev239.dist-info/METADATA,sha256=NYr1O3aYqoYayCOSP6MFlS5SsYhqN2vZn13XbOY7_JE,1190
97
- dhisana-0.0.1.dev239.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
98
- dhisana-0.0.1.dev239.dist-info/entry_points.txt,sha256=jujxteZmNI9EkEaK-pOCoWuBujU8TCevdkfl9ZcKHek,49
99
- dhisana-0.0.1.dev239.dist-info/top_level.txt,sha256=NETTHt6YifG_P7XtRHbQiXZlgSFk9Qh9aR-ng1XTf4s,8
100
- dhisana-0.0.1.dev239.dist-info/RECORD,,
97
+ dhisana-0.0.1.dev241.dist-info/METADATA,sha256=anx7v-Bxc5EhcMORORWmPkw2a2WYadN-xGZcNhnr-es,1190
98
+ dhisana-0.0.1.dev241.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
99
+ dhisana-0.0.1.dev241.dist-info/entry_points.txt,sha256=jujxteZmNI9EkEaK-pOCoWuBujU8TCevdkfl9ZcKHek,49
100
+ dhisana-0.0.1.dev241.dist-info/top_level.txt,sha256=NETTHt6YifG_P7XtRHbQiXZlgSFk9Qh9aR-ng1XTf4s,8
101
+ dhisana-0.0.1.dev241.dist-info/RECORD,,