By paus

2015-06-05 08:17:49 8 Comments

I want to implement multiple authorization using PHP for interaction with Telegram REST API.

What task am I trying to solve? Well, it's simple: several dozens of users (all of them have a carma like here (+10, -2, +1000 etc.) with relevant group taxonomy: web-masters and customers) have a user profile on my website. After they reach a certain amount of carma and since they are authorized in their profile they are joined to private chats based on Telegram generated for them automatically.

After some research, I found that it's very complicated because:

  1. I've never had an experience of API implementation for hardware-binded social networks.
  2. I took a look at, but it's completely unobvious how to implement these functions (for example auth.sendCode), using PHP or any other language. If these commands should be sent as JSON to server, then it doesn't look like JSON:

      auth.sentCode#efed51d9 phone_registered:Bool phone_code_hash:string send_call_timeout:int is_password:Bool = auth.SentCode;

    What is it? In which language is it written?

    UPD: It's written in TL (Type Language):

  3. I've explored the source code of several clients (Webogram, Telegram-cli (tg), tdesktop), and I found several implementations of

Unfortunately, none of them support multiple authorization on their side, and after a little bit of research, I have no idea where to dig deeper to find out more information.

Also, these implementations look bulky and compound (for example, enter image description here

There I see bunch of servers (./tg/tgl/tgl.h):

#define TG_SERVER_1 ""
#define TG_SERVER_2 ""
#define TG_SERVER_3 ""
#define TG_SERVER_4 ""
#define TG_SERVER_5 ""

I found several possibly appropriate functions (./tg/tgl/queries.c):

void empty_auth_file (void) {
  if (TLS->test_mode) {
    bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_TEST_1, strlen (TG_SERVER_TEST_1), 443);
    bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_TEST_2, strlen (TG_SERVER_TEST_2), 443);
    bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_TEST_3, strlen (TG_SERVER_TEST_3), 443);
    bl_do_set_working_dc (TLS, TG_SERVER_TEST_DEFAULT);
  } else {
    bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_1, strlen (TG_SERVER_1), 443);
    bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_2, strlen (TG_SERVER_2), 443);
    bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_3, strlen (TG_SERVER_3), 443);
    bl_do_dc_option (TLS, 4, "", 0, TG_SERVER_4, strlen (TG_SERVER_4), 443);
    bl_do_dc_option (TLS, 5, "", 0, TG_SERVER_5, strlen (TG_SERVER_5), 443);
    bl_do_set_working_dc (TLS, TG_SERVER_DEFAULT);

void bl_do_dc_option (struct tgl_state *TLS, int id, const char *name, int l1, const char *ip, int l2, int port) {
  struct tgl_dc *DC = TLS->DC_list[id];
  if (DC && !strncmp (ip, DC->ip, l2)) { return; }

  clear_packet ();
  out_int (CODE_binlog_dc_option);
  out_int (id);
  out_cstring (name, l1);
  out_cstring (ip, l2);
  out_int (port);

  add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));


What files should I transfer to PHP for multiple user auth implementation? Could you please help me to know where to start from and how to make it easier than it currently is?

Thank you in advance!

Related Questions

Sponsored Content

49 Answered Questions

30 Answered Questions

[SOLVED] How do you parse and process HTML/XML in PHP?

23 Answered Questions

[SOLVED] How do I POST JSON data with cURL?

28 Answered Questions

[SOLVED] How can I prevent SQL injection in PHP?

32 Answered Questions

[SOLVED] How do I get a YouTube video thumbnail from the YouTube API?

36 Answered Questions

[SOLVED] How do I check if a string contains a specific word?

36 Answered Questions

[SOLVED] How to pair socks from a pile efficiently?

3 Answered Questions

[SOLVED] Telegram-based chat on a PHP-based site: HOWTO?

Sponsored Content