hiinsta 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.
- hiinsta-0.1.0/LICENSE +21 -0
- hiinsta-0.1.0/PKG-INFO +96 -0
- hiinsta-0.1.0/README.md +58 -0
- hiinsta-0.1.0/hiinsta/InstagramMessenger.py +171 -0
- hiinsta-0.1.0/hiinsta/__init__.py +11 -0
- hiinsta-0.1.0/hiinsta/types/__init__.py +81 -0
- hiinsta-0.1.0/hiinsta/types/exeptions/InstagramApiExeption.py +92 -0
- hiinsta-0.1.0/hiinsta/types/exeptions/__init__.py +4 -0
- hiinsta-0.1.0/hiinsta.egg-info/PKG-INFO +96 -0
- hiinsta-0.1.0/hiinsta.egg-info/SOURCES.txt +16 -0
- hiinsta-0.1.0/hiinsta.egg-info/dependency_links.txt +1 -0
- hiinsta-0.1.0/hiinsta.egg-info/requires.txt +9 -0
- hiinsta-0.1.0/hiinsta.egg-info/top_level.txt +2 -0
- hiinsta-0.1.0/pyproject.toml +55 -0
- hiinsta-0.1.0/setup.cfg +4 -0
- hiinsta-0.1.0/setup.py +41 -0
- hiinsta-0.1.0/tests/__init__.py +1 -0
- hiinsta-0.1.0/tests/test_core.py +1 -0
hiinsta-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tomas Santana
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
hiinsta-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hiinsta
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A wrapper for Instagram's API
|
|
5
|
+
Home-page: https://github.com/yourusername/hiinsta
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: Tomas Santana <tomas@cervant.chat>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/cervant-ai/hiinsta
|
|
10
|
+
Project-URL: Repository, https://github.com/cervant-ai/hiinsta.git
|
|
11
|
+
Project-URL: Issues, https://github.com/cervant-ai/hiinsta/issues
|
|
12
|
+
Keywords: hiinsta,python,package
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Requires-Python: >=3.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: pydantic>=2.11.7
|
|
27
|
+
Requires-Dist: httpx>=0.28.1
|
|
28
|
+
Requires-Dist: requests>=2.25.1
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
31
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
32
|
+
Requires-Dist: flake8>=3.8.0; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy>=0.800; extra == "dev"
|
|
34
|
+
Dynamic: author
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
Dynamic: requires-python
|
|
38
|
+
|
|
39
|
+
# hiinsta
|
|
40
|
+
|
|
41
|
+
A Python package for interacting with Instagram's messaging API.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install hiinsta
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from hiinsta import InstagramMessenger
|
|
53
|
+
|
|
54
|
+
messenger = InstagramMessenger(access_token="YOUR_ACCESS_TOKEN")
|
|
55
|
+
|
|
56
|
+
# Example usage
|
|
57
|
+
message_id = await messenger.send_text("Hello, World!", recipient_id="RECIPIENT_ID")
|
|
58
|
+
|
|
59
|
+
print(message_id)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Development
|
|
63
|
+
|
|
64
|
+
To install in development mode:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
git clone https://github.com/cervant-ai/hiinsta.git
|
|
68
|
+
cd hiinsta
|
|
69
|
+
pip install -e .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
To install development dependencies:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install -e ".[dev]"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Testing
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pytest
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install -e ".[dev]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Testing
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pytest
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
hiinsta-0.1.0/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# hiinsta
|
|
2
|
+
|
|
3
|
+
A Python package for interacting with Instagram's messaging API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install hiinsta
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from hiinsta import InstagramMessenger
|
|
15
|
+
|
|
16
|
+
messenger = InstagramMessenger(access_token="YOUR_ACCESS_TOKEN")
|
|
17
|
+
|
|
18
|
+
# Example usage
|
|
19
|
+
message_id = await messenger.send_text("Hello, World!", recipient_id="RECIPIENT_ID")
|
|
20
|
+
|
|
21
|
+
print(message_id)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Development
|
|
25
|
+
|
|
26
|
+
To install in development mode:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git clone https://github.com/cervant-ai/hiinsta.git
|
|
30
|
+
cd hiinsta
|
|
31
|
+
pip install -e .
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
To install development dependencies:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install -e ".[dev]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Testing
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pytest
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install -e ".[dev]"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Testing
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pytest
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from typing import Optional, Any, Dict
|
|
3
|
+
from hiinsta.types import InstagramPayload
|
|
4
|
+
from hiinsta.types.exeptions import InstagramApiException
|
|
5
|
+
|
|
6
|
+
INSTAGRAM_BASE_URL = "https://graph.instagram.com"
|
|
7
|
+
INSTAGRAM_MESSAGES_ENDPOINT = "/me/messages"
|
|
8
|
+
DEFAULT_TIMEOUT = 15.0 # seconds
|
|
9
|
+
|
|
10
|
+
class InstagramMessenger:
|
|
11
|
+
"""
|
|
12
|
+
A class to interact with Instagram's messaging API.
|
|
13
|
+
"""
|
|
14
|
+
access_token: str
|
|
15
|
+
request_timeout: Optional[float] = DEFAULT_TIMEOUT
|
|
16
|
+
|
|
17
|
+
def __init__(self, access_token: str, request_timeout: Optional[float] = DEFAULT_TIMEOUT):
|
|
18
|
+
self.access_token = access_token
|
|
19
|
+
self.request_timeout = request_timeout
|
|
20
|
+
|
|
21
|
+
async def send_text(self, text: str, recipient_id: str) -> str:
|
|
22
|
+
"""
|
|
23
|
+
Send a text message to a user.
|
|
24
|
+
Args:
|
|
25
|
+
text (str): The text message to send.
|
|
26
|
+
recipient_id (str): The recipient's Instagram user ID.
|
|
27
|
+
Returns:
|
|
28
|
+
str: The message ID of the sent message.
|
|
29
|
+
"""
|
|
30
|
+
url = f"{INSTAGRAM_BASE_URL}{INSTAGRAM_MESSAGES_ENDPOINT}"
|
|
31
|
+
payload = {
|
|
32
|
+
"recipient": {
|
|
33
|
+
"id": recipient_id
|
|
34
|
+
},
|
|
35
|
+
"message": {
|
|
36
|
+
"text": text
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return await self._send_message_payload(payload)
|
|
40
|
+
|
|
41
|
+
async def send_image(self, image_url: str, recipient_id: str) -> str:
|
|
42
|
+
"""
|
|
43
|
+
Send an image or GIF to a user.
|
|
44
|
+
Args:
|
|
45
|
+
image_url (str): The URL of the image or GIF to send.
|
|
46
|
+
recipient_id (str): The recipient's Instagram user ID.
|
|
47
|
+
Returns:
|
|
48
|
+
str: The message ID of the sent message.
|
|
49
|
+
"""
|
|
50
|
+
return await self._send_attachment("image", image_url, recipient_id)
|
|
51
|
+
|
|
52
|
+
async def send_video(self, video_url: str, recipient_id: str) -> str:
|
|
53
|
+
"""
|
|
54
|
+
Send a video to a user.
|
|
55
|
+
Args:
|
|
56
|
+
video_url (str): The URL of the video to send.
|
|
57
|
+
recipient_id (str): The recipient's Instagram user ID.
|
|
58
|
+
Returns:
|
|
59
|
+
str: The message ID of the sent message.
|
|
60
|
+
"""
|
|
61
|
+
return await self._send_attachment("video", video_url, recipient_id)
|
|
62
|
+
|
|
63
|
+
async def send_audio(self, audio_url: str, recipient_id: str):
|
|
64
|
+
"""
|
|
65
|
+
Send an audio file to a user.
|
|
66
|
+
Args:
|
|
67
|
+
audio_url (str): The URL of the audio file to send.
|
|
68
|
+
recipient_id (str): The recipient's Instagram user ID.
|
|
69
|
+
Returns:
|
|
70
|
+
str: The message ID of the sent message.
|
|
71
|
+
"""
|
|
72
|
+
return await self._send_attachment("audio", audio_url, recipient_id)
|
|
73
|
+
|
|
74
|
+
async def _send_attachment(self, attachment_type: str, attachment_url: str, recipient_id: str):
|
|
75
|
+
"""
|
|
76
|
+
Send an attachment (image, video, audio, file) to a user.
|
|
77
|
+
Args:
|
|
78
|
+
attachment_type (str): The type of attachment ('image', 'video', 'audio', 'file').
|
|
79
|
+
attachment_url (str): The URL of the attachment to send.
|
|
80
|
+
recipient_id (str): The recipient's Instagram user ID.
|
|
81
|
+
"""
|
|
82
|
+
payload = {
|
|
83
|
+
"recipient": {
|
|
84
|
+
"id": recipient_id
|
|
85
|
+
},
|
|
86
|
+
"message": {
|
|
87
|
+
"attachment": {
|
|
88
|
+
"type": attachment_type,
|
|
89
|
+
"payload": {
|
|
90
|
+
"url": attachment_url
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return await self._send_message_payload(payload)
|
|
96
|
+
|
|
97
|
+
async def _send_message_payload(self, payload: dict) -> str:
|
|
98
|
+
"""
|
|
99
|
+
Send a custom payload to Instagram's API messages endpoint with robust error handling.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
payload (dict): The payload to send.
|
|
103
|
+
timeout (Optional[float]): Request timeout in seconds. Defaults to DEFAULT_TIMEOUT.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
SendResponse: A mapping with at least the "message_id" and, when available, "recipient_id".
|
|
107
|
+
|
|
108
|
+
Raises:
|
|
109
|
+
InstagramApiException: For network errors, non-2xx responses, or malformed responses.
|
|
110
|
+
"""
|
|
111
|
+
url = f"{INSTAGRAM_BASE_URL}{INSTAGRAM_MESSAGES_ENDPOINT}"
|
|
112
|
+
headers = {
|
|
113
|
+
"Authorization": f"Bearer {self.access_token}",
|
|
114
|
+
"Content-Type": "application/json",
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try:
|
|
118
|
+
async with httpx.AsyncClient(timeout=self.request_timeout) as client:
|
|
119
|
+
response = await client.post(url, json=payload, headers=headers)
|
|
120
|
+
except httpx.RequestError as e:
|
|
121
|
+
raise InstagramApiException(
|
|
122
|
+
message="Network error while sending payload",
|
|
123
|
+
endpoint=url,
|
|
124
|
+
method="POST",
|
|
125
|
+
payload=payload,
|
|
126
|
+
details=str(e),
|
|
127
|
+
) from e
|
|
128
|
+
|
|
129
|
+
# Non-2xx -> raise a structured exception with parsed error body when possible
|
|
130
|
+
if response.status_code < 200 or response.status_code >= 300:
|
|
131
|
+
raise InstagramApiException.from_httpx_response(
|
|
132
|
+
response,
|
|
133
|
+
endpoint=url,
|
|
134
|
+
method="POST",
|
|
135
|
+
payload=payload,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Parse JSON and validate presence of message_id
|
|
139
|
+
try:
|
|
140
|
+
data: Dict[str, Any] = response.json()
|
|
141
|
+
except ValueError:
|
|
142
|
+
raise InstagramApiException(
|
|
143
|
+
message="Response is not valid JSON",
|
|
144
|
+
endpoint=url,
|
|
145
|
+
method="POST",
|
|
146
|
+
payload=payload,
|
|
147
|
+
status_code=response.status_code,
|
|
148
|
+
response_text=response.text,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
message_id = data.get("message_id") or data.get("id")
|
|
152
|
+
if not message_id:
|
|
153
|
+
raise InstagramApiException(
|
|
154
|
+
message="Missing message_id in successful response",
|
|
155
|
+
endpoint=url,
|
|
156
|
+
method="POST",
|
|
157
|
+
payload=payload,
|
|
158
|
+
status_code=response.status_code,
|
|
159
|
+
response_json=data,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
return message_id
|
|
164
|
+
|
|
165
|
+
@staticmethod
|
|
166
|
+
def process_payload(payload: dict) -> InstagramPayload:
|
|
167
|
+
try:
|
|
168
|
+
return InstagramPayload(**payload)
|
|
169
|
+
except Exception as e:
|
|
170
|
+
raise ValueError(f"Invalid payload: {e}")
|
|
171
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional, Dict, TypedDict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AttachmentPayload(BaseModel):
|
|
7
|
+
url: str
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Attachment(BaseModel):
|
|
11
|
+
type: str
|
|
12
|
+
payload: AttachmentPayload
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class QuickReply(BaseModel):
|
|
16
|
+
payload: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AdsContextData(BaseModel):
|
|
20
|
+
ad_title: str
|
|
21
|
+
photo_url: str
|
|
22
|
+
video_url: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Referral(BaseModel):
|
|
26
|
+
ref: Optional[str]
|
|
27
|
+
ad_id: Optional[str]
|
|
28
|
+
source: Optional[str]
|
|
29
|
+
type: Optional[str]
|
|
30
|
+
ads_context_data: Optional[AdsContextData]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ReplyToStory(BaseModel):
|
|
34
|
+
url: str
|
|
35
|
+
id: str
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ReplyTo(BaseModel):
|
|
39
|
+
mid: Optional[str]
|
|
40
|
+
story: Optional[ReplyToStory]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Message(BaseModel):
|
|
44
|
+
mid: str
|
|
45
|
+
attachments: Optional[List[Attachment]] = None
|
|
46
|
+
is_deleted: Optional[bool] = None
|
|
47
|
+
is_echo: bool = Field(default=False)
|
|
48
|
+
is_unsupported: Optional[bool] = None
|
|
49
|
+
quick_reply: Optional[QuickReply] = None
|
|
50
|
+
referral: Optional[Referral] = None
|
|
51
|
+
reply_to: Optional[ReplyTo] = None
|
|
52
|
+
text: Optional[str] = None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class Messaging(BaseModel):
|
|
56
|
+
sender: Dict[str, str]
|
|
57
|
+
recipient: Dict[str, str]
|
|
58
|
+
timestamp: int
|
|
59
|
+
message: Message
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Entry(BaseModel):
|
|
63
|
+
id: str
|
|
64
|
+
time: int
|
|
65
|
+
messaging: List[Messaging]
|
|
66
|
+
|
|
67
|
+
class InstagramPayload(BaseModel):
|
|
68
|
+
object: str
|
|
69
|
+
entry: List[Entry]
|
|
70
|
+
|
|
71
|
+
class InstagramUser(BaseModel):
|
|
72
|
+
id: str
|
|
73
|
+
username: str
|
|
74
|
+
name: str
|
|
75
|
+
|
|
76
|
+
class SendResponse(TypedDict):
|
|
77
|
+
recipient_id: str
|
|
78
|
+
message_id: str
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class InstagramApiException(Exception):
|
|
7
|
+
"""Exception raised for Instagram API errors.
|
|
8
|
+
|
|
9
|
+
Captures HTTP details, endpoint, method, payload, and parsed error body when available.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
message: str,
|
|
15
|
+
*,
|
|
16
|
+
status_code: Optional[int] = None,
|
|
17
|
+
endpoint: Optional[str] = None,
|
|
18
|
+
method: Optional[str] = None,
|
|
19
|
+
payload: Optional[Dict[str, Any]] = None,
|
|
20
|
+
response_text: Optional[str] = None,
|
|
21
|
+
response_json: Optional[Dict[str, Any]] = None,
|
|
22
|
+
details: Optional[str] = None,
|
|
23
|
+
error_code: Optional[str] = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
super().__init__(message)
|
|
26
|
+
self.message = message
|
|
27
|
+
self.status_code = status_code
|
|
28
|
+
self.endpoint = endpoint
|
|
29
|
+
self.method = method
|
|
30
|
+
self.payload = payload
|
|
31
|
+
self.response_text = response_text
|
|
32
|
+
self.response_json = response_json
|
|
33
|
+
self.details = details
|
|
34
|
+
self.error_code = error_code
|
|
35
|
+
|
|
36
|
+
def __str__(self) -> str:
|
|
37
|
+
base = self.message
|
|
38
|
+
parts = []
|
|
39
|
+
if self.status_code is not None:
|
|
40
|
+
parts.append(f"status={self.status_code}")
|
|
41
|
+
if self.endpoint:
|
|
42
|
+
parts.append(f"endpoint={self.endpoint}")
|
|
43
|
+
if self.method:
|
|
44
|
+
parts.append(f"method={self.method}")
|
|
45
|
+
if self.error_code:
|
|
46
|
+
parts.append(f"error_code={self.error_code}")
|
|
47
|
+
if self.details:
|
|
48
|
+
parts.append(f"details={self.details}")
|
|
49
|
+
if parts:
|
|
50
|
+
base += " (" + ", ".join(parts) + ")"
|
|
51
|
+
return base
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_httpx_response(
|
|
55
|
+
cls,
|
|
56
|
+
response: Any,
|
|
57
|
+
*,
|
|
58
|
+
endpoint: Optional[str] = None,
|
|
59
|
+
method: Optional[str] = None,
|
|
60
|
+
payload: Optional[Dict[str, Any]] = None,
|
|
61
|
+
) -> "InstagramApiException":
|
|
62
|
+
"""
|
|
63
|
+
Build an exception from an httpx.Response, attempting to parse JSON error details.
|
|
64
|
+
"""
|
|
65
|
+
status = getattr(response, "status_code", None)
|
|
66
|
+
text = None
|
|
67
|
+
data: Optional[Dict[str, Any]] = None
|
|
68
|
+
code: Optional[str] = None
|
|
69
|
+
message: str = "Instagram API request failed"
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
data = response.json()
|
|
73
|
+
# Graph API errors are often under { "error": { "message": "...", "code": 190, ... } }
|
|
74
|
+
err = data.get("error") if isinstance(data, dict) else None
|
|
75
|
+
if isinstance(err, dict):
|
|
76
|
+
message = err.get("message") or message
|
|
77
|
+
code_value = err.get("code")
|
|
78
|
+
code = str(code_value) if code_value is not None else None
|
|
79
|
+
except Exception:
|
|
80
|
+
text = getattr(response, "text", None)
|
|
81
|
+
|
|
82
|
+
return cls(
|
|
83
|
+
message=message,
|
|
84
|
+
status_code=status,
|
|
85
|
+
endpoint=endpoint,
|
|
86
|
+
method=method,
|
|
87
|
+
payload=payload,
|
|
88
|
+
response_text=text,
|
|
89
|
+
response_json=data,
|
|
90
|
+
error_code=code,
|
|
91
|
+
)
|
|
92
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hiinsta
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A wrapper for Instagram's API
|
|
5
|
+
Home-page: https://github.com/yourusername/hiinsta
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: Tomas Santana <tomas@cervant.chat>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/cervant-ai/hiinsta
|
|
10
|
+
Project-URL: Repository, https://github.com/cervant-ai/hiinsta.git
|
|
11
|
+
Project-URL: Issues, https://github.com/cervant-ai/hiinsta/issues
|
|
12
|
+
Keywords: hiinsta,python,package
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Requires-Python: >=3.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: pydantic>=2.11.7
|
|
27
|
+
Requires-Dist: httpx>=0.28.1
|
|
28
|
+
Requires-Dist: requests>=2.25.1
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
31
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
32
|
+
Requires-Dist: flake8>=3.8.0; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy>=0.800; extra == "dev"
|
|
34
|
+
Dynamic: author
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
Dynamic: requires-python
|
|
38
|
+
|
|
39
|
+
# hiinsta
|
|
40
|
+
|
|
41
|
+
A Python package for interacting with Instagram's messaging API.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install hiinsta
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from hiinsta import InstagramMessenger
|
|
53
|
+
|
|
54
|
+
messenger = InstagramMessenger(access_token="YOUR_ACCESS_TOKEN")
|
|
55
|
+
|
|
56
|
+
# Example usage
|
|
57
|
+
message_id = await messenger.send_text("Hello, World!", recipient_id="RECIPIENT_ID")
|
|
58
|
+
|
|
59
|
+
print(message_id)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Development
|
|
63
|
+
|
|
64
|
+
To install in development mode:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
git clone https://github.com/cervant-ai/hiinsta.git
|
|
68
|
+
cd hiinsta
|
|
69
|
+
pip install -e .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
To install development dependencies:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install -e ".[dev]"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Testing
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pytest
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install -e ".[dev]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Testing
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pytest
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
hiinsta/InstagramMessenger.py
|
|
6
|
+
hiinsta/__init__.py
|
|
7
|
+
hiinsta.egg-info/PKG-INFO
|
|
8
|
+
hiinsta.egg-info/SOURCES.txt
|
|
9
|
+
hiinsta.egg-info/dependency_links.txt
|
|
10
|
+
hiinsta.egg-info/requires.txt
|
|
11
|
+
hiinsta.egg-info/top_level.txt
|
|
12
|
+
hiinsta/types/__init__.py
|
|
13
|
+
hiinsta/types/exeptions/InstagramApiExeption.py
|
|
14
|
+
hiinsta/types/exeptions/__init__.py
|
|
15
|
+
tests/__init__.py
|
|
16
|
+
tests/test_core.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=45", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hiinsta"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A wrapper for Instagram's API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.7"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Tomas Santana", email = "tomas@cervant.chat"},
|
|
14
|
+
]
|
|
15
|
+
keywords = ["hiinsta", "python", "package"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.7",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"pydantic>=2.11.7",
|
|
30
|
+
"httpx>=0.28.1",
|
|
31
|
+
"requests>=2.25.1",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=6.0",
|
|
37
|
+
"black>=21.0",
|
|
38
|
+
"flake8>=3.8.0",
|
|
39
|
+
"mypy>=0.800",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/cervant-ai/hiinsta"
|
|
44
|
+
Repository = "https://github.com/cervant-ai/hiinsta.git"
|
|
45
|
+
Issues = "https://github.com/cervant-ai/hiinsta/issues"
|
|
46
|
+
|
|
47
|
+
[tool.black]
|
|
48
|
+
line-length = 88
|
|
49
|
+
target-version = ['py37']
|
|
50
|
+
|
|
51
|
+
[tool.mypy]
|
|
52
|
+
python_version = "3.7"
|
|
53
|
+
warn_return_any = true
|
|
54
|
+
warn_unused_configs = true
|
|
55
|
+
disallow_untyped_defs = true
|
hiinsta-0.1.0/setup.cfg
ADDED
hiinsta-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
4
|
+
long_description = fh.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="hiinsta",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
author="Your Name",
|
|
10
|
+
author_email="your.email@example.com",
|
|
11
|
+
description="A Python package for hiinsta",
|
|
12
|
+
long_description=long_description,
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
url="https://github.com/yourusername/hiinsta",
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
classifiers=[
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.7",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
],
|
|
28
|
+
python_requires=">=3.7",
|
|
29
|
+
install_requires=[
|
|
30
|
+
"pydantic>=2.11.7",
|
|
31
|
+
"httpx>=0.28.1",
|
|
32
|
+
],
|
|
33
|
+
extras_require={
|
|
34
|
+
"dev": [
|
|
35
|
+
"pytest>=6.0",
|
|
36
|
+
"black>=21.0",
|
|
37
|
+
"flake8>=3.8.0",
|
|
38
|
+
"mypy>=0.800",
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Empty file to make tests directory a Python package
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import pytest
|