# Telegram Account (MTProto)

Telegram Account (MTProto) API APIPedia: Otomatisasi akun Telegram pribadi lewat MTProto, terpisah dari Telegram Bot API. Panggil dengan satu token API di `https://api.apipedia.id/v1/telegram/account`.

Mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Kredensialnya api_id dan api_hash milik pengguna (dari my.telegram.org) ditambah session string hasil login OTP; login berjalan bertahap: minta kode, verifikasi kode, lalu kadang kata sandi verifikasi dua langkah. Session string setara akses penuh ke akun pribadi, jadi disimpan terenkripsi, tidak pernah dikembalikan utuh ke klien, dan tidak pernah ikut di log. PERINGATAN: otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen — pakai Telegram Bot API bila memungkinkan. Session disimpan terenkripsi AES-256-GCM dengan kunci di env server, tidak pernah di database. Tanpa kunci itu seluruh endpoint menjawab 503 alih-alih menyimpan session tanpa enkripsi.

- Base URL: `https://api.apipedia.id/v1/telegram/account`
- Autentikasi: `Authorization: Bearer apk_…` (token dari console.apipedia.id)
- Kategori: Messaging
- Halaman: https://apipedia.id/docs/telegram-account
- OpenAPI: https://console.apipedia.id/openapi/telegram-account.yaml

Semua respons memakai amplop `{ "is_success", "message", "data" }` kecuali disebutkan lain. Kode error umum: lihat https://apipedia.id/docs#kode-status-error.

## Endpoint (7)

- `GET /dialogs`: Daftar chat milik akun
- `POST /login/password`: Langkah 3 - kata sandi verifikasi dua langkah
- `POST /login/start`: Langkah 1 - minta kode OTP ke akun
- `POST /login/verify`: Langkah 2 - verifikasi kode OTP
- `POST /messages`: Kirim pesan sebagai pengguna
- `GET /session`: Status session akun (tanpa session string)
- `DELETE /session`: Cabut session dan logout di Telegram

### Daftar chat milik akun

`GET https://api.apipedia.id/v1/telegram/account/dialogs`

PERINGATAN JUJUR: endpoint ini mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen; pakai Telegram Bot API (/telegram/bot/*) bila memungkinkan. Setiap jawaban sukses membawa peringatan yang sama di `message` dan `data.peringatan`.

Daftar chat (dialog) akun, urut seperti di aplikasi Telegram. Per item: `id` (string), `nama`, `tipe` (`user`, `group`, atau `channel`), dan `pesan_belum_dibaca`. Isi pesan tidak ikut.

| Parameter | Lokasi | Tipe | Wajib | Keterangan |
|---|---|---|---|---|
| `limit` | query | integer | tidak | Jumlah chat, 1-100. Default `50`. |
| `connection_id` | query | string | tidak | Id koneksi akun Telegram. Wajib bila lebih dari satu akun terhubung. |

Contoh request:

```bash
curl -X GET "https://api.apipedia.id/v1/telegram/account/dialogs?limit=20" \
  -H "Authorization: Bearer apk_xxxxxxxxxxxxxxxx"
```

Contoh respons (200):

```json
{
  "is_success": true,
  "message": "Chat list retrieved. WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible.",
  "data": {
    "connection_id": "5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97",
    "items": [
      {
        "id": "987654321",
        "nama": "Rani Pratama",
        "tipe": "user",
        "pesan_belum_dibaca": 2
      },
      {
        "id": "-4012345678",
        "nama": "Tim Operasional",
        "tipe": "group",
        "pesan_belum_dibaca": 0
      },
      {
        "id": "-1009876543210",
        "nama": "Kanal Pengumuman",
        "tipe": "channel",
        "pesan_belum_dibaca": 14
      }
    ],
    "peringatan": "WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible."
  }
}
```

Error khusus endpoint ini:

- **409**: Belum ada session aktif, ada lebih dari satu akun terhubung tanpa `connection_id`, atau session sudah dicabut di sisi Telegram (`More than one Telegram account is connected. Specify the "connection_id" of the account to use.`)
- **503**: Server belum diberi TELEGRAM_SESSION_KEY. Seluruh endpoint Account menolak bekerja alih-alih menyimpan session tanpa enkripsi. (`Telegram Account is not available yet: the server has no TELEGRAM_SESSION_KEY configured, and account sessions are never stored without encryption. Contact the administrator.`)

### Langkah 3 - kata sandi verifikasi dua langkah

`POST https://api.apipedia.id/v1/telegram/account/login/password`

PERINGATAN JUJUR: endpoint ini mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen; pakai Telegram Bot API (/telegram/bot/*) bila memungkinkan. Setiap jawaban sukses membawa peringatan yang sama di `message` dan `data.peringatan`.

Hanya dipanggil bila `POST /telegram/account/login/verify` menjawab `butuh_password: true`. Body: `login_id` yang sama, `password` kata sandi verifikasi dua langkah (diverifikasi lewat SRP dan tidak pernah disimpan), `account_label` opsional. Jawaban suksesnya sama dengan login yang selesai di langkah 2.

Body (`application/json`, wajib):

```json
{
  "login_id": "b7e2c1d4-9a3f-4e6b-8c5d-1f2a3b4c5d6e",
  "password": "kata-sandi-2fa-anda"
}
```

Contoh request:

```bash
curl -X POST "https://api.apipedia.id/v1/telegram/account/login/password" \
  -H "Authorization: Bearer apk_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"login_id":"b7e2c1d4-9a3f-4e6b-8c5d-1f2a3b4c5d6e","password":"kata-sandi-2fa-anda"}'
```

Contoh respons (200):

```json
{
  "is_success": true,
  "message": "Telegram account connected. WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible.",
  "data": {
    "butuh_password": false,
    "connection_id": "5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97",
    "account": {
      "id": "5512345678",
      "username": "rani_pratama",
      "first_name": "Rani",
      "phone_number": "+62812****789"
    },
    "session_fingerprint": "sha256:3f9a1c7e5b2d8a40",
    "peringatan": "WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible."
  }
}
```

Error khusus endpoint ini:

- **503**: Server belum diberi TELEGRAM_SESSION_KEY. Seluruh endpoint Account menolak bekerja alih-alih menyimpan session tanpa enkripsi. (`Telegram Account is not available yet: the server has no TELEGRAM_SESSION_KEY configured, and account sessions are never stored without encryption. Contact the administrator.`)

### Langkah 1 - minta kode OTP ke akun

`POST https://api.apipedia.id/v1/telegram/account/login/start`

PERINGATAN JUJUR: endpoint ini mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen; pakai Telegram Bot API (/telegram/bot/*) bila memungkinkan. Setiap jawaban sukses membawa peringatan yang sama di `message` dan `data.peringatan`.

Langkah pertama login MTProto: Telegram mengirim kode ke aplikasi Telegram di perangkat lain atau lewat SMS (Telegram yang memilih; lihat `dikirim_ke`). Body: `api_id` (angka) dan `api_hash` (32 karakter heksadesimal) milik Anda sendiri dari my.telegram.org, bukan milik APIPedia; `phone_number` dalam format internasional, mis. `+628123456789`.

`login_id` dipakai di langkah berikutnya dan berlaku 15 menit (`kedaluwarsa_pada`). Login yang sedang berjalan hanya hidup di memori server, jadi bisa hilang bila server dimulai ulang; ulangi dari langkah ini bila `/login/verify` menjawab 404. `phone_code_hash` dari Telegram tidak pernah dikirim ke klien, dan nomor telepon dikembalikan dalam bentuk tersamar.

Body (`application/json`, wajib):

```json
{
  "api_id": 1234567,
  "api_hash": "0123456789abcdef0123456789abcdef",
  "phone_number": "+628123456789"
}
```

Contoh request:

```bash
curl -X POST "https://api.apipedia.id/v1/telegram/account/login/start" \
  -H "Authorization: Bearer apk_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"api_id":1234567,"api_hash":"0123456789abcdef0123456789abcdef","phone_number":"+628123456789"}'
```

Contoh respons (200):

```json
{
  "is_success": true,
  "message": "Login code has been sent by Telegram. Continue with POST /login/verify. WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible.",
  "data": {
    "login_id": "b7e2c1d4-9a3f-4e6b-8c5d-1f2a3b4c5d6e",
    "dikirim_ke": "Telegram app",
    "phone_number": "+62812****789",
    "kedaluwarsa_pada": "2026-10-30T03:15:00.000Z",
    "peringatan": "WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible."
  }
}
```

Error khusus endpoint ini:

- **503**: Server belum diberi TELEGRAM_SESSION_KEY. Seluruh endpoint Account menolak bekerja alih-alih menyimpan session tanpa enkripsi. (`Telegram Account is not available yet: the server has no TELEGRAM_SESSION_KEY configured, and account sessions are never stored without encryption. Contact the administrator.`)

### Langkah 2 - verifikasi kode OTP

`POST https://api.apipedia.id/v1/telegram/account/login/verify`

PERINGATAN JUJUR: endpoint ini mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen; pakai Telegram Bot API (/telegram/bot/*) bila memungkinkan. Setiap jawaban sukses membawa peringatan yang sama di `message` dan `data.peringatan`.

Body: `login_id` dari langkah 1; `code` kode yang dikirim Telegram; `account_label` opsional (nama akun di halaman Koneksi, bawaan username atau nama depan).

DUA hasil sukses yang harus ditangani klien: (1) login selesai - `butuh_password: false`, akun tersimpan sebagai koneksi `telegram-account` dan `connection_id` dikembalikan (contoh di bawah); (2) akun memakai verifikasi dua langkah - `data` hanya `{ butuh_password: true, peringatan }`, lanjutkan ke `POST /telegram/account/login/password` dengan `login_id` yang sama.

Session string hasil login disimpan terenkripsi AES-256-GCM dan TIDAK PERNAH dikembalikan ke klien; yang keluar hanya sidik jarinya (`session_fingerprint`).

Body (`application/json`, wajib):

```json
{
  "login_id": "b7e2c1d4-9a3f-4e6b-8c5d-1f2a3b4c5d6e",
  "code": "12345",
  "account_label": "Akun CS"
}
```

Contoh request:

```bash
curl -X POST "https://api.apipedia.id/v1/telegram/account/login/verify" \
  -H "Authorization: Bearer apk_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"login_id":"b7e2c1d4-9a3f-4e6b-8c5d-1f2a3b4c5d6e","code":"12345","account_label":"Akun CS"}'
```

Contoh respons (200):

```json
{
  "is_success": true,
  "message": "Telegram account connected. WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible.",
  "data": {
    "butuh_password": false,
    "connection_id": "5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97",
    "account": {
      "id": "5512345678",
      "username": "rani_pratama",
      "first_name": "Rani",
      "phone_number": "+62812****789"
    },
    "session_fingerprint": "sha256:3f9a1c7e5b2d8a40",
    "peringatan": "WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible."
  }
}
```

Error khusus endpoint ini:

- **503**: Server belum diberi TELEGRAM_SESSION_KEY. Seluruh endpoint Account menolak bekerja alih-alih menyimpan session tanpa enkripsi. (`Telegram Account is not available yet: the server has no TELEGRAM_SESSION_KEY configured, and account sessions are never stored without encryption. Contact the administrator.`)

### Kirim pesan sebagai pengguna

`POST https://api.apipedia.id/v1/telegram/account/messages`

PERINGATAN JUJUR: endpoint ini mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen; pakai Telegram Bot API (/telegram/bot/*) bila memungkinkan. Setiap jawaban sukses membawa peringatan yang sama di `message` dan `data.peringatan`.

Mengirim pesan SEBAGAI akun pribadi Anda (bukan bot) - bagian inilah yang paling berisiko membuat akun dibatasi atau diblokir, terutama untuk pesan massal ke orang yang tidak mengenal Anda.

Body: `peer` wajib (`@username`, nomor telepon yang ada di kontak, atau id numerik chat); `text` wajib, maks 4096 karakter; `parse_mode` opsional (`html` atau `md`; nilai lain diabaikan); `reply_to_message_id` opsional; `connection_id` opsional, wajib bila lebih dari satu akun terhubung.

Body (`application/json`, wajib):

```json
{
  "peer": "@rani_pratama",
  "text": "Halo Rani, laporan bulan ini sudah saya kirim ke email.",
  "parse_mode": "md"
}
```

Contoh request:

```bash
curl -X POST "https://api.apipedia.id/v1/telegram/account/messages" \
  -H "Authorization: Bearer apk_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"peer":"@rani_pratama","text":"Halo Rani, laporan bulan ini sudah saya kirim ke email.","parse_mode":"md"}'
```

Contoh respons (200):

```json
{
  "is_success": true,
  "message": "Message sent as your account. WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible.",
  "data": {
    "connection_id": "5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97",
    "message_id": 1873,
    "tanggal": "2026-10-30T04:20:45.000Z",
    "peringatan": "WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible."
  }
}
```

Error khusus endpoint ini:

- **409**: Belum ada session aktif, ada lebih dari satu akun terhubung tanpa `connection_id`, atau session sudah dicabut di sisi Telegram (`More than one Telegram account is connected. Specify the "connection_id" of the account to use.`)
- **503**: Server belum diberi TELEGRAM_SESSION_KEY. Seluruh endpoint Account menolak bekerja alih-alih menyimpan session tanpa enkripsi. (`Telegram Account is not available yet: the server has no TELEGRAM_SESSION_KEY configured, and account sessions are never stored without encryption. Contact the administrator.`)

### Status session akun (tanpa session string)

`GET https://api.apipedia.id/v1/telegram/account/session`

PERINGATAN JUJUR: endpoint ini mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen; pakai Telegram Bot API (/telegram/bot/*) bila memungkinkan. Setiap jawaban sukses membawa peringatan yang sama di `message` dan `data.peringatan`.

Daftar akun Telegram yang terhubung milik pemanggil, terbaru dulu. Session string TIDAK PERNAH ikut; yang ada hanya sidik jarinya, identitas akun, nomor tersamar, `terhubung_pada`, dan `terakhir_dipakai` (null bila belum pernah dipakai). `items` kosong berarti belum ada akun yang terhubung.

Contoh request:

```bash
curl -X GET "https://api.apipedia.id/v1/telegram/account/session" \
  -H "Authorization: Bearer apk_xxxxxxxxxxxxxxxx"
```

Contoh respons (200):

```json
{
  "is_success": true,
  "message": "Telegram session status retrieved. WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible.",
  "data": {
    "items": [
      {
        "connection_id": "5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97",
        "account": {
          "id": "5512345678",
          "username": "rani_pratama",
          "first_name": "Rani",
          "phone_number": "+62812****789"
        },
        "session_fingerprint": "sha256:3f9a1c7e5b2d8a40",
        "terhubung_pada": "2026-10-30T03:02:11.000Z",
        "terakhir_dipakai": "2026-10-30T04:20:45.000Z"
      }
    ],
    "peringatan": "WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible."
  }
}
```

Error khusus endpoint ini:

- **503**: Server belum diberi TELEGRAM_SESSION_KEY. Seluruh endpoint Account menolak bekerja alih-alih menyimpan session tanpa enkripsi. (`Telegram Account is not available yet: the server has no TELEGRAM_SESSION_KEY configured, and account sessions are never stored without encryption. Contact the administrator.`)

### Cabut session dan logout di Telegram

`DELETE https://api.apipedia.id/v1/telegram/account/session`

PERINGATAN JUJUR: endpoint ini mengendalikan AKUN Telegram pribadi lewat MTProto, bukan bot. Otomatisasi akun pribadi melanggar Ketentuan Layanan Telegram dan berisiko akun diblokir permanen; pakai Telegram Bot API (/telegram/bot/*) bila memungkinkan. Setiap jawaban sukses membawa peringatan yang sama di `message` dan `data.peringatan`.

Logout di sisi Telegram lebih dulu, lalu menghapus koneksi beserta session terenkripsinya dari APIPedia. Bila logout di Telegram gagal (mis. session sudah dicabut dari perangkat lain), data di APIPedia tetap dihapus dan `dicabut_di_telegram` bernilai false - cabut juga dari Telegram > Settings > Devices.

Body opsional: `connection_id`. Wajib diisi bila lebih dari satu akun terhubung (tanpa itu dijawab 409).

Body (`application/json`):

```json
{
  "connection_id": "5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97"
}
```

Contoh request:

```bash
curl -X DELETE "https://api.apipedia.id/v1/telegram/account/session" \
  -H "Authorization: Bearer apk_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"connection_id":"5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97"}'
```

Contoh respons (200):

```json
{
  "is_success": true,
  "message": "Telegram session revoked. WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible.",
  "data": {
    "connection_id": "5f0c9a2e-7b1d-4c3e-9a8f-2d6b4e1c0a97",
    "dicabut_di_telegram": true,
    "peringatan": "WARNING: Automating a personal account violates the Telegram Terms of Service and risks a permanent account ban. Use the Telegram Bot API where possible."
  }
}
```

Error khusus endpoint ini:

- **409**: Belum ada session aktif, ada lebih dari satu akun terhubung tanpa `connection_id`, atau session sudah dicabut di sisi Telegram (`More than one Telegram account is connected. Specify the "connection_id" of the account to use.`)
- **503**: Server belum diberi TELEGRAM_SESSION_KEY. Seluruh endpoint Account menolak bekerja alih-alih menyimpan session tanpa enkripsi. (`Telegram Account is not available yet: the server has no TELEGRAM_SESSION_KEY configured, and account sessions are never stored without encryption. Contact the administrator.`)
