Skip to main content

"Pwn the protocol, dissect the wire, automate the unscriptable." — 0xshijn


🎯 Giới thiệu tổng quan

IGChat-v2 (v3.0.0) được thiết kế và phát triển bởi Phước Toàn (Shiin / 0xshijn) như một giải pháp toàn diện, độc lập và chuẩn xác để tự động hóa Instagram Direct và các tính năng tương tác mạng xã hội Instagram.

v3.0.0 mang đến nền tảng hiện đại, tối ưu và chuẩn xác dành riêng cho Instagram:

  • ✅ 100% Pure Instagram: Sử dụng chuẩn Instagram Direct DGW WebSocket, Slide GraphQL, và Polaris Web REST API.
  • ✅ Kiến trúc phân tầng chuyên nghiệp: Python Async Client (igchat) kết hợp Go Bridge companion (instameow) giao tiếp qua JSON-RPC 2.0 dòng.

⚡ Điểm nổi bật & Tính năng kỹ thuật

🚀 Async-First Python Client

Toàn bộ I/O xây dựng trên asyncio và httpx.AsyncClient với connection pooling tối ưu, timeout hữu hạn, và kiểm soát ngoại lệ chuẩn xác.

🌉 Go Bridge thời gian thực (v3.0.0)

Tiến trình Go (build/igchat-bridge.exe) tích hợp instameow xử lý WebSocket DGW và MQTT bypass với cơ chế generation-fenced và tự động phục hồi.

🛡️ Bảo vệ an toàn & SSRF Guard

Kiểm tra URL nghiêm ngặt chặn tấn công SSRF vào mạng nội bộ/cloud metadata khi tải media; che giấu bí mật tự động trong log stderr; khóa quyền file lưu trữ (0600 / Windows ACL).

🤖 Khung Bot tích hợp sẵn

Lớp InstagramBot sẵn sàng vận hành với bộ đệm LRU chống lặp tin nhắn, rate-limiting độc lập theo từng user, router lệnh async và hỗ trợ quyền Admin an toàn.


🏗️ Kiến trúc hệ thống

flowchart LR
    App["Ứng dụng Python / Bot"] --> BotMod["igchat.bot"]
    BotMod --> DirectMod["igchat.direct"]
    BotMod --> SocialMod["igchat.social"]

    DirectMod --> BridgeMod["igchat.bridge"]
    DirectMod --> CoreMod["igchat.core"]
    SocialMod --> CoreMod
    
    BridgeMod <-->|"JSON-RPC 2.0 (stdin/stdout)"| BridgeGo["Go Bridge (igchat-bridge.exe)"]
    BridgeGo <-->|"DGW WebSocket / Slide GraphQL"| IGDirect["Instagram Direct Engine"]
    CoreMod <-->|"HTTPS (httpx connection pool)"| IGRest["Polaris Web REST/GraphQL"]
Package / Module Đường dẫn Vai trò
igchat.client igchat/client.py High-Level Fluent SDK (IGClient): Context manager, event decorators @client.on(...), pagination tự động
igchat.filters igchat/filters.py Bộ lọc tin nhắn nâng cao: Hỗ trợ toán tử logic &, |, ~, ^ (text, command, regex, media, group, sender...)
igchat.stealth igchat/stealth.py Ghost Mode & Humanizer: Ẩn danh hoàn toàn (chặn presence/đã xem), mô phỏng tốc độ gõ phím phân phối Gaussian
igchat.export igchat/export.py Sao lưu hội thoại forensic: Xuất dữ liệu Direct ra JSON, Markdown hoặc trang HTML Dark Mode giao diện Instagram
igchat.core igchat/core/ Data models (InstagramSession, MessageEvent), HTTP pooling, SSRF guard, bảo mật file, redaction
igchat.auth igchat/auth/ Bootstrap session, Encrypted Vault (PBKDF2 + authenticated stream cipher), Web AJAX login kèm 2FA TOTP
igchat.bridge igchat/bridge/ Quản lý tiến trình Go Bridge qua line JSON-RPC, generation-fencing, ReconnectPolicy exponential backoff
igchat.direct igchat/direct/ Direct listener, gửi/sửa/thu hồi tin, reaction, Themes & Direct Polls, Voice waveform (64 peaks)
igchat.social igchat/social/ Profile, bio, quan hệ bạn bè, Phân tích Unfollowers & Close Friends (analytics.py), tương tác bài viết
igchat.bot igchat/bot/ Khung bot hoàn chỉnh, router lệnh, bộ lọc chống spam, rate limiter theo user, xử lý tín hiệu OS
bridge/ bridge/ Source code Go bridge dựa trên instameow biên dịch ra build/igchat-bridge.exe

🛠️ Cài đặt & Chuẩn bị môi trường

Yêu cầu hệ thống

  • Python 3.10+ (khuyên dùng Python 3.11 hoặc 3.12/3.13)
  • Go 1.23+ (dùng để biên dịch bridge Go)
  • Git (để clone submodule bridge/meta)

1. Clone repository & cài đặt Python package

git clone https://github.com/0xshijn/igchat-v2.git
cd igchat-v2

# Khởi tạo môi trường ảo Python
python -m venv .venv

# Kích hoạt môi trường ảo:
# Windows (PowerShell):
.venv\Scripts\Activate.ps1
# Linux / macOS:
source .venv/bin/activate

# Nâng cấp pip và cài đặt phụ thuộc
python -m pip install --upgrade pip
python -m pip install -e .

2. Biên dịch Go Bridge companion

cd bridge
go test -v ./...
go build -trimpath -ldflags="-s -w -X main.bridgeVersion=3.0.0" -o ../build/igchat-bridge.exe .
cd ..

Kiểm tra binary bridge bằng script smoke test:

python scripts/smoke_bridge_rpc.py build/igchat-bridge.exe --expected-version 3.0.0

🚀 Hướng dẫn sử dụng nhanh

1. Gửi tin nhắn Direct cơ bản

import asyncio
from igchat.auth import bootstrap_session
from igchat.direct import send_text_message


async def main() -> None:
    # 1. Khởi tạo session từ cookie Instagram
    cookie_str = "sessionid=YOUR_SESSION_ID; ds_user_id=YOUR_USER_ID; csrftoken=YOUR_CSRF_TOKEN;"
    session = await bootstrap_session(cookie_str)
    print(f"Logged in as: @{session.username} ({session.user_id})")

    # 2. Gửi tin nhắn Direct qua Polaris Web GraphQL
    result = await send_text_message(
        session,
        thread_id="340282366841710300949128134123456789012",
        text="Hello from igchat v3.0.0!",
    )
    print(f"Message sent! ID: {result.get('message_id')}")


if __name__ == "__main__":
    asyncio.run(main())

2. Lắng nghe tin nhắn theo thời gian thực (DirectListener)

import asyncio
from typing import Any
from igchat.auth import bootstrap_session
from igchat.direct import DirectListener


async def handle_message(event: dict[str, Any]) -> None:
    data = event.get("data", {})
    thread_id = data.get("threadId") or data.get("thread_id")
    sender_id = data.get("senderId") or data.get("sender_id")
    text = data.get("text", "")
    print(f"[{thread_id}] @{sender_id}: {text}")


async def main() -> None:
    session = await bootstrap_session("sessionid=...; ds_user_id=...; csrftoken=...;")
    listener = DirectListener(session=session)
    listener.on_message(handle_message)

    print("Đang lắng nghe tin nhắn Instagram Direct...")
    await listener.start()


if __name__ == "__main__":
    asyncio.run(main())

3. Sử dụng Fluent SDK hiện đại (IGClient)

import asyncio
from igchat import IGClient, filters
from igchat.stealth import GhostMode, Humanizer


async def main() -> None:
    # Khởi tạo client hiện đại với Ghost Mode (chống phát hiện / ẩn trạng thái online)
    stealth = GhostMode(stealth_read_receipts=True, suppress_presence=True)

    async with IGClient(cookie="sessionid=...; ds_user_id=...;", stealth=stealth) as client:
        print(f"Connected as @{client.username} (ID: {client.user_id})")

        # 1. Gửi tin nhắn kèm độ trễ gõ phím người thật
        humanizer = Humanizer(cpm=320.0)
        await humanizer.simulate_typing(client.session, "340282366841710300949128134123456789012", 20)
        await client.send_text("340282366841710300949128134123456789012", "Hello via Fluent IGClient!")

        # 2. Xử lý sự kiện với bộ lọc kết hợp (bitwise operators)
        @client.on(filters.command("hello") & filters.private)
        async def on_hello(event: dict) -> None:
            thread_id = event["data"]["threadId"]
            await client.send_text(thread_id, "Hello! I am running on pure Python async IGClient.")

        # 3. Phân tích người không follow lại (Non-followers)
        analytics = await client.analyze_followers()
        print(f"Ai không follow lại tôi: {analytics.not_following_back}")


if __name__ == "__main__":
    asyncio.run(main())

🤖 Khởi chạy Bot Mẫu (main.py)

Dự án cung cấp sẵn khung bot hoàn chỉnh với đầy đủ các lệnh tiện ích và quản trị.

1. Cấu hình bot

Sao chép file cấu hình mẫu:

cp config.example.json config.json

Chỉnh sửa nội dung config.json:

{
  "botName": "igchat-v2 bot",
  "prefix": "/",
  "cookies": "sessionid=...; ds_user_id=...; csrftoken=...;",
  "admins": ["1000xxxxxxxxxx"],
  "log_message_content": false,
  "debug_errors": false
}

2. Chạy bot

python main.py
📋 Danh sách 54 lệnh tích hợp sẵn trong bot (Bấm để xem chi tiết)
Nhóm Lệnh Mô tả
Hệ thống /hi, /ping, /help, /id, /notif Kiểm tra kết nối, độ trễ, danh sách lệnh, thread/user ID, thông báo gần đây
Tin nhắn /echo, /react, /edit, /unsend, /pin, /unpin, /forward, /more Lặp lại nội dung, thả cảm xúc, sửa/thu hồi tin E2EE, ghim/bỏ ghim, chuyển tiếp
Bảo vệ /antiunsend [on|off], /antiedit [on|off] Tự động phát hiện và cảnh báo khi có tin nhắn bị thu hồi hoặc chỉnh sửa
Quản trị Nhóm /rename, /groupavatar, /tagall, /mute, /pinthread, /add, /kick, /promote, /demote, /leave Đổi tên nhóm, đổi avatar, tag tất cả, bật/tắt thông báo, thêm/xóa thành viên, thăng/hạ admin
Hộp thư /inbox, /thread [số], /requests, /accept <id>, /deletethread Xem hộp thư gần đây, lịch sử chat, duyệt tin nhắn chờ, xóa cuộc trò chuyện
Instagram Notes /note [text|clear|list], /delnote, /notes, /notemusic <bài>, /music <q> Đăng/xóa Note 24h, đăng Note kèm bài hát, tìm kiếm âm nhạc
Mạng xã hội /info, /profile <user>, /bio <text>, /follow, /unfollow, /block, /unblock, /search <q> Xem profile, đổi bio bot, theo dõi/hủy theo dõi, chặn/bỏ chặn, tìm kiếm người dùng
Media & Tải về /image <url>, /voice <url>, /media, /dl <url>, /autodl [on|off], /post, /upstory Gửi ảnh/voice từ URL, bóc tách link tải Reel/Post, tự động tải link IG, đăng bài lên Feed/Story
Tương tác Bài viết /like <url>, /unlike, /comment <url> <text>, /save, /unsave Thả tim/bỏ tim bài viết, gửi bình luận, lưu/bỏ lưu bài viết Instagram

🧪 Kiểm thử chất lượng mã nguồn (Quality Gate)

Dự án đạt 100% tiêu chuẩn chất lượng nghiêm ngặt trước khi đóng gói:

# 1. Chạy toàn bộ test suite Python (50 unit tests & 54 command runner tests)
pytest tests/ -v
python tests/test_all_commands.py

# 2. Kiểm tra định dạng mã nguồn
black --check .
ruff check .

# 3. Kiểm tra kiểu dữ liệu tĩnh nghiêm ngặt
mypy igchat main.py scripts examples tests

# 4. Kiểm tra Go Bridge
cd bridge && go test -v . ./bridge && go vet . ./bridge && cd ..

📜 Giấy phép & Tác giả

Dự án được phân phối dưới giấy phép Apache License 2.0.
Thành phần Go bridge sử dụng instameow thuộc mautrix-meta theo giấy phép GPL-3.0.

Phát triển & duy trì bởi Phước Toàn (Shiin / 0xshijn)
Portfolio · Telegram · Instagram · GitHub

Metadata

Release files for igchat-v2 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for igchat-v2 3.1.0
File Size Uploaded Provenance Actions
igchat_v2-3.1.0.tar.gz 87.2 kB Without provenance Details for igchat_v2-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for igchat-v2 3.1.0
File Interpreter ABI Platform Actions
igchat_v2-3.1.0-py3-none-any.whl Python 3 none any Details for igchat_v2-3.1.0-py3-none-any.whl

Total release size: 180.8 kB

Release files / igchat_v2-3.1.0.tar.gz

Download URL igchat_v2-3.1.0.tar.gz
Size 87.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0912ae20f997420796b11980d2fca36402fe6d681a40a863b117d8b9b6cab451
BLAKE2b-256 checksum
How to use checksums
aa51d8484946631ad379086332e2076d10b53a176257154fca6df6d089cbf0d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / igchat_v2-3.1.0-py3-none-any.whl

Download URL igchat_v2-3.1.0-py3-none-any.whl
Size 93.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecc9c43e4ec24f884b518f17c56c06dbc6228aae3e60e5fe5b6b0fc9e3c62c0d
BLAKE2b-256 checksum
How to use checksums
7684d75521fb90af47b5d2fbb3e0987873f17dcf816d2e98e57af59d831c5739
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for igchat-v2 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page