Camlproto
OCaml implementation of the MTProto protocol and TL binary data serialization format 🚧
Install / Use
/learn @eilvelia/CamlprotoREADME
Camlproto 
A portable and type-safe client implementation of Telegram's MTProto protocol and TL data serialization format.
Usage
Example to use the library with Telegram:
open Camlproto
module T = TLSchema.Telegram
module Client = Telegram.Client.Make(PlatformCaml)(TransportTcpFullCaml)
let prompt str = Lwt_io.(let%lwt () = write stdout str in read_line stdin)
let main () =
(* api_id and api_hash can be obtained at https://my.telegram.org/ *)
let%lwt phone_number = prompt "Enter your phone number: " in
let%lwt api_id = prompt "Enter your api id: " in
let api_id = int_of_string api_id in
let%lwt api_hash = prompt "Enter your api hash: " in
let%lwt t = Client.create () in
let%lwt () = Client.init t (Telegram.Settings.create ~api_id ()) in
let%lwt TL_auth_sentCode { phone_code_hash; _ } =
Client.invoke t (module T.TL_auth_sendCode) {
phone_number;
api_id;
api_hash;
settings = TL_codeSettings {
allow_flashcall = None;
current_number = None;
allow_app_hash = None;
allow_missed_call = None;
logout_tokens = None;
}
} in
let%lwt phone_code = prompt "Enter the code: " in
let%lwt [@warning "-8"] TL_auth_authorization { user; _ } =
Client.invoke t (module T.TL_auth_signIn) {
phone_number;
phone_code_hash;
phone_code;
} in
let TL_user { id; _ } | TL_userEmpty { id } = user in
print_endline ("Signed as " ^ Int64.to_string id);
Lwt.return_unit
let _ = Lwt_main.run (main ())
(see examples/e02_telegram/ and examples/e01_mtproto/)
TL <-> OCaml mapping
| TL | OCaml |
|--------------------------|------------------|
| int | int |
| nat (#) | int32 |
| long | int64 |
| string | string |
| double | float |
| int128 | Cstruct.t |
| int256 | Cstruct.t |
| bytes | Cstruct.t |
| Bool | bool |
| vector a | 'a list |
| Conditional definitions | 'a option |
"Transport components"
Implemented
-
tcp_full (ocaml, node.js)
-
tcp_abridged (ocaml)
In progress
- tcp_abridged (node.js)
Not implemented
-
websocket secure (browser)
-
tcp_intermediate
-
tcp_obfuscated2
-
http
-
https
-
udp
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
