doja-sdk 0.1.0__tar.gz
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.
- doja_sdk-0.1.0/PKG-INFO +34 -0
- doja_sdk-0.1.0/README.md +21 -0
- doja_sdk-0.1.0/doja_sdk/__init__.py +6 -0
- doja_sdk-0.1.0/doja_sdk/client.py +151 -0
- doja_sdk-0.1.0/doja_sdk/exceptions.py +16 -0
- doja_sdk-0.1.0/doja_sdk.egg-info/PKG-INFO +34 -0
- doja_sdk-0.1.0/doja_sdk.egg-info/SOURCES.txt +10 -0
- doja_sdk-0.1.0/doja_sdk.egg-info/dependency_links.txt +1 -0
- doja_sdk-0.1.0/doja_sdk.egg-info/requires.txt +1 -0
- doja_sdk-0.1.0/doja_sdk.egg-info/top_level.txt +1 -0
- doja_sdk-0.1.0/pyproject.toml +24 -0
- doja_sdk-0.1.0/setup.cfg +4 -0
doja_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: doja-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for DoJa Chatbots and WhatsApp Business Integration
|
|
5
|
+
Author-email: DoJa Consulting <contact@dojaconsulting.cloud>
|
|
6
|
+
Project-URL: Homepage, https://dojaconsulting.cloud
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
|
|
14
|
+
# DoJa Python SDK
|
|
15
|
+
|
|
16
|
+
The official Python SDK for interacting with DoJa Chatbots and WhatsApp Business Cloud API.
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
```bash
|
|
20
|
+
pip install doja-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
```python
|
|
25
|
+
from doja_sdk import DojaClient
|
|
26
|
+
|
|
27
|
+
doja = DojaClient(
|
|
28
|
+
doja_token="DOJA-SEC-YOUR_LICENSE",
|
|
29
|
+
whatsapp_token="YOUR_META_TOKEN",
|
|
30
|
+
phone_id="YOUR_PHONE_ID"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
doja.send_text("525500000000", "Hello from DoJa SDK!")
|
|
34
|
+
```
|
doja_sdk-0.1.0/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# DoJa Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python SDK for interacting with DoJa Chatbots and WhatsApp Business Cloud API.
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
```bash
|
|
7
|
+
pip install doja-sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### Usage
|
|
11
|
+
```python
|
|
12
|
+
from doja_sdk import DojaClient
|
|
13
|
+
|
|
14
|
+
doja = DojaClient(
|
|
15
|
+
doja_token="DOJA-SEC-YOUR_LICENSE",
|
|
16
|
+
whatsapp_token="YOUR_META_TOKEN",
|
|
17
|
+
phone_id="YOUR_PHONE_ID"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
doja.send_text("525500000000", "Hello from DoJa SDK!")
|
|
21
|
+
```
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# doja_sdk/client.py
|
|
2
|
+
import requests
|
|
3
|
+
import json
|
|
4
|
+
from .exceptions import DojaAuthError, DojaAPIError
|
|
5
|
+
|
|
6
|
+
class DojaClient:
|
|
7
|
+
def __init__(self, doja_token: str, whatsapp_token: str, phone_id: str):
|
|
8
|
+
"""
|
|
9
|
+
Initialize the DoJa Client.
|
|
10
|
+
Validates the DoJa License before allowing access.
|
|
11
|
+
"""
|
|
12
|
+
self._doja_token = doja_token
|
|
13
|
+
self.whatsapp_token = whatsapp_token
|
|
14
|
+
self.phone_id = phone_id
|
|
15
|
+
|
|
16
|
+
# 1. Validate the license key
|
|
17
|
+
self._validate_license()
|
|
18
|
+
|
|
19
|
+
# 2. Setup the WhatsApp Base URL
|
|
20
|
+
self.base_url = f"https://graph.facebook.com/v22.0/{self.phone_id}/messages"
|
|
21
|
+
self.headers = {
|
|
22
|
+
"Authorization": f"Bearer {self.whatsapp_token}",
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def _validate_license(self):
|
|
27
|
+
"""
|
|
28
|
+
Synchronous call to DoJa Central Server to validate the license.
|
|
29
|
+
Throws DojaAuthError if validation fails.
|
|
30
|
+
"""
|
|
31
|
+
# Note: In production, this points to your real validation server:
|
|
32
|
+
# url = "https://api.dojaconsulting.cloud/v1/license/validate"
|
|
33
|
+
|
|
34
|
+
# We simulate the API call here. In the future you will replace this with the real POST request.
|
|
35
|
+
# response = requests.post(url, json={"license_key": self._doja_token})
|
|
36
|
+
# For our v0.1.0 demo, we hardcode validation:
|
|
37
|
+
|
|
38
|
+
if not self._doja_token.startswith("DOJA-SEC-"):
|
|
39
|
+
raise DojaAuthError(
|
|
40
|
+
"❌ DOJA LICENSE INVALID: The provided 'doja_token' is suspended, expired, or invalid. "
|
|
41
|
+
"Contact contact@dojaconsulting.cloud to renew your license."
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
print(f"✅ DoJa License Validated: {self._doja_token[-4:]} (Active)")
|
|
45
|
+
|
|
46
|
+
def _send_payload(self, payload: dict) -> dict:
|
|
47
|
+
"""Internal method to execute the HTTP POST to WhatsApp"""
|
|
48
|
+
try:
|
|
49
|
+
response = requests.post(
|
|
50
|
+
self.base_url,
|
|
51
|
+
headers=self.headers,
|
|
52
|
+
data=json.dumps(payload),
|
|
53
|
+
timeout=10
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if response.status_code not in [200, 201]:
|
|
57
|
+
err_msg = f"WhatsApp API Error {response.status_code}: {response.text}"
|
|
58
|
+
raise DojaAPIError(err_msg, response.status_code, response.json())
|
|
59
|
+
|
|
60
|
+
return response.json()
|
|
61
|
+
except requests.exceptions.RequestException as e:
|
|
62
|
+
raise DojaAPIError(f"HTTP Request failed: {str(e)}")
|
|
63
|
+
|
|
64
|
+
def send_text(self, to: str, text: str):
|
|
65
|
+
payload = {
|
|
66
|
+
"messaging_product": "whatsapp",
|
|
67
|
+
"to": to,
|
|
68
|
+
"type": "text",
|
|
69
|
+
"text": {"body": text}
|
|
70
|
+
}
|
|
71
|
+
return self._send_payload(payload)
|
|
72
|
+
|
|
73
|
+
def send_document(self, to: str, url: str, caption: str = "", filename: str = ""):
|
|
74
|
+
payload = {
|
|
75
|
+
"messaging_product": "whatsapp",
|
|
76
|
+
"to": to,
|
|
77
|
+
"type": "document",
|
|
78
|
+
"document": {
|
|
79
|
+
"link": url,
|
|
80
|
+
"caption": caption,
|
|
81
|
+
"filename": filename
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return self._send_payload(payload)
|
|
85
|
+
|
|
86
|
+
def send_image(self, to: str, url: str, caption: str = ""):
|
|
87
|
+
payload = {
|
|
88
|
+
"messaging_product": "whatsapp",
|
|
89
|
+
"to": to,
|
|
90
|
+
"type": "image",
|
|
91
|
+
"image": {
|
|
92
|
+
"link": url,
|
|
93
|
+
"caption": caption
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return self._send_payload(payload)
|
|
97
|
+
|
|
98
|
+
def send_interactive_button(self, to: str, body_text: str, buttons_list: list):
|
|
99
|
+
"""buttons_list: list of dicts. Example: [{"id": "b1", "title": "Yes"}]"""
|
|
100
|
+
buttons = []
|
|
101
|
+
for btn in buttons_list:
|
|
102
|
+
buttons.append({
|
|
103
|
+
"type": "reply",
|
|
104
|
+
"reply": {
|
|
105
|
+
"id": btn["id"],
|
|
106
|
+
"title": btn["title"]
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
payload = {
|
|
111
|
+
"messaging_product": "whatsapp",
|
|
112
|
+
"to": to,
|
|
113
|
+
"type": "interactive",
|
|
114
|
+
"interactive": {
|
|
115
|
+
"type": "button",
|
|
116
|
+
"body": {"text": body_text},
|
|
117
|
+
"action": {"buttons": buttons}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return self._send_payload(payload)
|
|
121
|
+
|
|
122
|
+
def send_interactive_list(self, to: str, body_text: str, button_text: str, sections: list):
|
|
123
|
+
"""Sends a native WhatsApp list selector."""
|
|
124
|
+
payload = {
|
|
125
|
+
"messaging_product": "whatsapp",
|
|
126
|
+
"to": to,
|
|
127
|
+
"type": "interactive",
|
|
128
|
+
"interactive": {
|
|
129
|
+
"type": "list",
|
|
130
|
+
"body": {"text": body_text},
|
|
131
|
+
"action": {
|
|
132
|
+
"button": button_text,
|
|
133
|
+
"sections": sections
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return self._send_payload(payload)
|
|
138
|
+
|
|
139
|
+
def send_location(self, to: str, latitude: float, longitude: float, name: str, address: str):
|
|
140
|
+
payload = {
|
|
141
|
+
"messaging_product": "whatsapp",
|
|
142
|
+
"to": to,
|
|
143
|
+
"type": "location",
|
|
144
|
+
"location": {
|
|
145
|
+
"latitude": latitude,
|
|
146
|
+
"longitude": longitude,
|
|
147
|
+
"name": name,
|
|
148
|
+
"address": address
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return self._send_payload(payload)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# doja_sdk/exceptions.py
|
|
2
|
+
|
|
3
|
+
class DojaSDKException(Exception):
|
|
4
|
+
"""Base exception for all DoJa SDK errors"""
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
class DojaAuthError(DojaSDKException):
|
|
8
|
+
"""Raised when the DoJa license validation fails (Invalid token, expired, etc.)"""
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
class DojaAPIError(DojaSDKException):
|
|
12
|
+
"""Raised when the WhatsApp Cloud API returns an error response"""
|
|
13
|
+
def __init__(self, message, status_code=None, raw_response=None):
|
|
14
|
+
super().__init__(message)
|
|
15
|
+
self.status_code = status_code
|
|
16
|
+
self.raw_response = raw_response
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: doja-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for DoJa Chatbots and WhatsApp Business Integration
|
|
5
|
+
Author-email: DoJa Consulting <contact@dojaconsulting.cloud>
|
|
6
|
+
Project-URL: Homepage, https://dojaconsulting.cloud
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
|
|
14
|
+
# DoJa Python SDK
|
|
15
|
+
|
|
16
|
+
The official Python SDK for interacting with DoJa Chatbots and WhatsApp Business Cloud API.
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
```bash
|
|
20
|
+
pip install doja-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
```python
|
|
25
|
+
from doja_sdk import DojaClient
|
|
26
|
+
|
|
27
|
+
doja = DojaClient(
|
|
28
|
+
doja_token="DOJA-SEC-YOUR_LICENSE",
|
|
29
|
+
whatsapp_token="YOUR_META_TOKEN",
|
|
30
|
+
phone_id="YOUR_PHONE_ID"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
doja.send_text("525500000000", "Hello from DoJa SDK!")
|
|
34
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
doja_sdk/__init__.py
|
|
4
|
+
doja_sdk/client.py
|
|
5
|
+
doja_sdk/exceptions.py
|
|
6
|
+
doja_sdk.egg-info/PKG-INFO
|
|
7
|
+
doja_sdk.egg-info/SOURCES.txt
|
|
8
|
+
doja_sdk.egg-info/dependency_links.txt
|
|
9
|
+
doja_sdk.egg-info/requires.txt
|
|
10
|
+
doja_sdk.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
doja_sdk
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "doja-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="DoJa Consulting", email="contact@dojaconsulting.cloud" },
|
|
10
|
+
]
|
|
11
|
+
description = "Official Python SDK for DoJa Chatbots and WhatsApp Business Integration"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"requests",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
"Homepage" = "https://dojaconsulting.cloud"
|
doja_sdk-0.1.0/setup.cfg
ADDED