telegram-mtproto-ruby 0.1.0
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.
- checksums.yaml +7 -0
- data/README.md +188 -0
- data/Rakefile +8 -0
- data/examples/complete_demo.rb +211 -0
- data/lib/telegram/auth.rb +438 -0
- data/lib/telegram/binary_reader.rb +156 -0
- data/lib/telegram/connection/tcp_full_connection.rb +248 -0
- data/lib/telegram/crypto.rb +323 -0
- data/lib/telegram/crypto_rsa_keys.rb +86 -0
- data/lib/telegram/senders/mtproto_encrypted_sender.rb +234 -0
- data/lib/telegram/senders/mtproto_plain_sender.rb +116 -0
- data/lib/telegram/serialization.rb +106 -0
- data/lib/telegram/tl/api.tl +2750 -0
- data/lib/telegram/tl/mtproto.tl +116 -0
- data/lib/telegram/tl_object.rb +132 -0
- data/lib/telegram/tl_reader.rb +120 -0
- data/lib/telegram/tl_schema.rb +113 -0
- data/lib/telegram/tl_writer.rb +103 -0
- data/lib/telegram_m_t_proto_clean.rb +1456 -0
- data/lib/telegram_mtproto/ruby/version.rb +9 -0
- data/lib/telegram_mtproto/ruby.rb +12 -0
- data/lib/telegram_mtproto/version.rb +5 -0
- data/lib/telegram_mtproto.rb +20 -0
- data/lib/telegram_plain_tcp.rb +92 -0
- data/sig/telegram/mtproto/ruby.rbs +8 -0
- metadata +69 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "telegram_mtproto/version"
|
4
|
+
require_relative "telegram_m_t_proto_clean"
|
5
|
+
|
6
|
+
module TelegramMtproto
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
# Main MTProto client class
|
10
|
+
#
|
11
|
+
# Example usage:
|
12
|
+
# client = TelegramMtproto.new(api_id, api_hash, phone_number)
|
13
|
+
# result = client.send_code
|
14
|
+
# if result[:success]
|
15
|
+
# auth_result = client.sign_in(result[:phone_code_hash], pin_code)
|
16
|
+
# end
|
17
|
+
def self.new(api_id, api_hash, phone_number)
|
18
|
+
TelegramMTProtoClean.new(api_id, api_hash, phone_number)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'timeout'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
class TelegramPlainTcp
|
6
|
+
def initialize(host, port)
|
7
|
+
@host = host
|
8
|
+
@port = port
|
9
|
+
@socket = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def connect
|
13
|
+
return if @socket
|
14
|
+
|
15
|
+
Rails.logger.info "🔌 PLAIN TCP: connecting to #{@host}:#{@port}..."
|
16
|
+
@socket = TCPSocket.new(@host, @port)
|
17
|
+
Rails.logger.info "✅ PLAIN TCP: connected to #{@host}:#{@port}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def send(data)
|
21
|
+
connect unless @socket
|
22
|
+
|
23
|
+
Rails.logger.info "📤 PLAIN TCP: sending #{data.length} bytes"
|
24
|
+
Rails.logger.info "📡 PLAIN TCP SEND (#{data.length} bytes): #{data.unpack1('H*')}"
|
25
|
+
|
26
|
+
written = @socket.write(data)
|
27
|
+
Rails.logger.info "📤 PLAIN TCP: wrote #{written} bytes to socket"
|
28
|
+
end
|
29
|
+
|
30
|
+
def recv(timeout: 60)
|
31
|
+
connect unless @socket
|
32
|
+
|
33
|
+
Rails.logger.info "📥 PLAIN TCP: waiting for response (#{timeout}s timeout)..."
|
34
|
+
|
35
|
+
begin
|
36
|
+
Timeout::timeout(timeout) do
|
37
|
+
# Read first 8 bytes for MTProto header
|
38
|
+
header = read_exactly(8)
|
39
|
+
Rails.logger.info "📥 PLAIN TCP: got header: #{header.unpack1('H*')}"
|
40
|
+
|
41
|
+
# auth_key_id (8 bytes) + msg_id (8 bytes) already read
|
42
|
+
# Now read length (4 bytes)
|
43
|
+
length_bytes = read_exactly(4)
|
44
|
+
length = length_bytes.unpack1('L<')
|
45
|
+
Rails.logger.info "📥 PLAIN TCP: message length: #{length} bytes"
|
46
|
+
|
47
|
+
# Read the actual message body
|
48
|
+
body = read_exactly(length)
|
49
|
+
Rails.logger.info "📥 PLAIN TCP: got body: #{length} bytes"
|
50
|
+
|
51
|
+
# Combine all parts
|
52
|
+
result = header + length_bytes + body
|
53
|
+
Rails.logger.info "📡 PLAIN TCP RECV (#{result.length} bytes): #{result.unpack1('H*')}"
|
54
|
+
|
55
|
+
result
|
56
|
+
end
|
57
|
+
rescue Timeout::Error
|
58
|
+
Rails.logger.error "❌ PLAIN TCP: timeout waiting for response"
|
59
|
+
raise "PLAIN TCP timeout"
|
60
|
+
rescue => e
|
61
|
+
Rails.logger.error "❌ PLAIN TCP: recv error: #{e.message}"
|
62
|
+
raise "PLAIN TCP recv error: #{e.message}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def close
|
67
|
+
if @socket
|
68
|
+
Rails.logger.debug "🔌 Closing plain TCP connection"
|
69
|
+
begin
|
70
|
+
@socket.close
|
71
|
+
rescue => e
|
72
|
+
Rails.logger.debug "❌ Error closing plain TCP: #{e.message}"
|
73
|
+
end
|
74
|
+
@socket = nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def read_exactly(bytes_needed)
|
81
|
+
result = ''.b
|
82
|
+
while result.length < bytes_needed
|
83
|
+
chunk = @socket.read(bytes_needed - result.length)
|
84
|
+
if chunk.nil? || chunk.empty?
|
85
|
+
raise "EOF while reading: expected #{bytes_needed}, got #{result.length}"
|
86
|
+
end
|
87
|
+
result += chunk
|
88
|
+
Rails.logger.debug "📥 PLAIN TCP: read #{chunk.length} bytes (#{result.length}/#{bytes_needed})"
|
89
|
+
end
|
90
|
+
result
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: telegram-mtproto-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mikefluff
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: A complete Ruby implementation of Telegram's MTProto 2.0 protocol with
|
13
|
+
DH handshake, AES-IGE encryption, and TL schema support. Includes auth.sendCode,
|
14
|
+
auth.signIn, contacts.getContacts, messages.sendMessage, and updates.getDifference
|
15
|
+
methods.
|
16
|
+
email:
|
17
|
+
- mike@mikefluff.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- examples/complete_demo.rb
|
25
|
+
- lib/telegram/auth.rb
|
26
|
+
- lib/telegram/binary_reader.rb
|
27
|
+
- lib/telegram/connection/tcp_full_connection.rb
|
28
|
+
- lib/telegram/crypto.rb
|
29
|
+
- lib/telegram/crypto_rsa_keys.rb
|
30
|
+
- lib/telegram/senders/mtproto_encrypted_sender.rb
|
31
|
+
- lib/telegram/senders/mtproto_plain_sender.rb
|
32
|
+
- lib/telegram/serialization.rb
|
33
|
+
- lib/telegram/tl/api.tl
|
34
|
+
- lib/telegram/tl/mtproto.tl
|
35
|
+
- lib/telegram/tl_object.rb
|
36
|
+
- lib/telegram/tl_reader.rb
|
37
|
+
- lib/telegram/tl_schema.rb
|
38
|
+
- lib/telegram/tl_writer.rb
|
39
|
+
- lib/telegram_m_t_proto_clean.rb
|
40
|
+
- lib/telegram_mtproto.rb
|
41
|
+
- lib/telegram_mtproto/ruby.rb
|
42
|
+
- lib/telegram_mtproto/ruby/version.rb
|
43
|
+
- lib/telegram_mtproto/version.rb
|
44
|
+
- lib/telegram_plain_tcp.rb
|
45
|
+
- sig/telegram/mtproto/ruby.rbs
|
46
|
+
homepage: https://github.com/mikefluff/telegram-mtproto-ruby
|
47
|
+
licenses: []
|
48
|
+
metadata:
|
49
|
+
allowed_push_host: https://rubygems.org
|
50
|
+
homepage_uri: https://github.com/mikefluff/telegram-mtproto-ruby
|
51
|
+
source_code_uri: https://github.com/mikefluff/telegram-mtproto-ruby
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.0.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.6.9
|
67
|
+
specification_version: 4
|
68
|
+
summary: Pure Ruby MTProto 2.0 implementation for Telegram API
|
69
|
+
test_files: []
|