Python SDK for Eitaa Bot API (sync & async)
Project description
Eitaa Bot SDK
یک کتابخانه پایتون ساده و قدرتمند برای تعامل با API رباتهای پیامرسان Eitaa.
توضیحات (Description)
این SDK راهی آسان برای ساخت و تعامل با رباتهای Eitaa با استفاده از پایتون فراهم میکند. از عملیات همزمان (synchronous) و ناهمزمان (asynchronous) پشتیبانی میکند.
نصب (Installation)
- نصب بسته با استفاده از pip:
pip install eitaayarbot
🔹 کلاسها و متدها
1. _BaseEitaaBot
کلاس پایه برای هر دو حالت سینک و آسنکرون، شامل توابع کمکی.
| متد | توضیح |
|---|---|
_build_url(method) |
ساخت URL کامل برای یک متد API |
_filter_none(data) |
حذف مقادیر None از دیکشنری |
2. EitaaBot (سینک / Sync)
| متد | پارامترها | توضیح |
|---|---|---|
__init__(token, timeout=20) |
token, timeout | مقداردهی اولیه ربات |
_request(method, http_method="POST", data=None, files=None) |
method, http_method, data, files | ارسال درخواست به API |
get_info() |
– | دریافت اطلاعات ربات |
send_message(chat_id, text, title=None, notification_disable=None, reply_to_message_id=None, date=None, pin=None, viewCountForDelete=None) |
پارامترهای اختیاری | ارسال پیام متنی با گزینههای پیشرفته |
send_file(chat_id, file_path, caption=None, title=None, date=None) |
پارامترهای اختیاری | ارسال فایل با کپشن |
send_document(chat_id, document_path, caption=None, date=None) |
پارامترهای اختیاری | ارسال سند |
close() |
– | بستن اتصال |
3. AsyncEitaaBot (آسنکرون / Async)
| متد | پارامترها | توضیح |
|---|---|---|
__init__(token, timeout=20) |
token, timeout | مقداردهی اولیه ربات |
_request(method, http_method="POST", data=None, files=None) |
method, http_method, data, files | ارسال درخواست به API |
get_info() |
– | دریافت اطلاعات ربات |
send_message(chat_id, text, title=None, notification_disable=None, reply_to_message_id=None, date=None, pin=None, viewCountForDelete=None) |
پارامترهای اختیاری | ارسال پیام متنی |
send_file(chat_id, file_path, caption=None, title=None, date=None) |
پارامترهای اختیاری | ارسال فایل با کپشن |
send_document(chat_id, document_path, caption=None, date=None) |
پارامترهای اختیاری | ارسال سند |
close() |
– | بستن اتصال |
توجه: تمام متدهای Async باید با
awaitفراخوانی شوند.
نحوه استفاده (Usage)
نمونهای ساده از نحوه استفاده از SDK:
from eitaayarbot import EitaaBot
# جایگزین کردن "YOUR_BOT_TOKEN" با توکن ربات Eitaa خودتان
BOT_TOKEN = "YOUR_BOT_TOKEN"
# ایجاد یک نمونه از EitaaBot
bot = EitaaBot(token=BOT_TOKEN)
try:
# دریافت اطلاعات ربات (Get bot info)
info = bot.get_info()
print(info) # Bot: {info['username']}
# ارسال یک پیام (Send a message)
chat_id = "YOUR_CHAT_ID" # جایگزین کردن با شناسه چت مورد نظر (Replace with your desired chat ID)
text = "سلام دنیا! این یه پیام از ربات Eitaa من هست." # Hello world! This is a message from my Eitaa bot.
bot.send_message(chat_id=chat_id, text=text)
print("پیام با موفقیت ارسال شد.") # Message sent successfully.
# ارسال یک فایل (Send a file)
file_path = "example.txt" # جایگزین کردن با مسیر فایل مورد نظر (Replace with your desired file path)
with open(file_path, "w") as f:
f.write("این یه فایل نمونه است.") # This is a sample file.
bot.send_file(chat_id=chat_id, file_path=file_path, caption="فایل نمونه") # Sample file
print("فایل با موفقیت ارسال شد.") # File sent successfully.
except RuntimeError as e:
print(f"خطا: {e}") # Error: {e}
finally:
# بستن اتصال (Close the connection)
bot.close()
import asyncio
from eitaayarbot import AsyncEitaaBot
async def main():
token = "توکن-ربات-تو"
bot = AsyncEitaaBot(token)
info = await bot.get_info()
print(info)
await bot.send_message(chat_id=12345, text="سلام دنیا Async!")
await bot.send_document(chat_id=12345, document_path="path/to/file.pdf", caption="یک سند")
await bot.close()
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eitaayarbot-1.0.0.tar.gz.
File metadata
- Download URL: eitaayarbot-1.0.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1690470cd20721cf726b6f0555645c7e6fa7004dcdb95e88de7db4bda9600d89
|
|
| MD5 |
d7805c7eb51c9ae8810fc41bdf8fb0aa
|
|
| BLAKE2b-256 |
ce658e65a8076662e656818d5ef726bded94d8087e3abbf15b9f027d01440765
|
File details
Details for the file eitaayarbot-1.0.0-py3-none-any.whl.
File metadata
- Download URL: eitaayarbot-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c918bbbc8a87567c733ab2fcc70bebbfe4d52cb4cca77f33f9ba8689b128ae95
|
|
| MD5 |
8a6e7d6866bc2dbbb30064151c92b4dc
|
|
| BLAKE2b-256 |
cbeb464900cf5b55dae2c502c81f2cb10c7276494311b01a87350befd4c0c77e
|