Telegram-based chat on a PHP-based site: HOWTO?
Asked Answered
T

3

7

I can't figure out what exactly to use for interaction between my site and the Telegram service (first of all - how to get the authentication process done using PHP and other stuff like chat among users).

On this page: https://core.telegram.org/api I haven't got an idea how to use those functions in PHP.

According to this page: https://telegram.org/apps I have two choices:

1) The CLI-interface (unofficial, by the way): https://github.com/vysheng/tg and it doesn't have an autentification function among others. In order to authenticate yourself, you need to run:

bin/telegram-cli -k tg-server.pub 

and inside of the application you have to enter your cell phone and the secret code sent by SMS - after that you're authorized. Then you install https://github.com/zyberspace/php-telegram-cli-client and run telegram-cli as a daemon:

./bin/telegram-cli -dWS /tmp/tg.sck -k tg-server.pub &  

Does it mean that I have to create tg-server.pub manually using PHP for each user which is trying to login?

2) Webogram: https://github.com/zhukov/webogram - but it's written on JavaScript and has very complicated code.

Dear Stackoverflow gurus, maybe you're more attentive than I am and could help me to recognize the right solution (or example, I don't know, the PHP snippet or anything else) for the user's chat based on the Telegram and PHP?

I would greatly appreciate it!

Thank you!

Twirp answered 28/5, 2015 at 5:5 Comment(2)
Thanks for a great explanation .And If your working on a public repository please provide us a link to your work so we don't need to create a wheel from beginning.Felic
Possible duplicate of How to implement authorization using a Telegram API?Gnawing
B
4

I have posted a step by step guide on getting your AuthKey (VB.net) here

The main challenge with Telegram API is the documentation... but if you can work through the first part - getting an AuthKey then i believe the rest should fall in place ... with some more effort.

Working through some GitHub src might be time consuming, it might be best to get a handle on the documentation and then work your way to building your own code for TelegramAPI from scratch

Bielefeld answered 30/9, 2015 at 17:57 Comment(0)
H
1

Most likely, PHP wrapper for Telegram API doesn't exist. I'd wager it's because communicating with Telegram servers from your server-side PHP code defeats both of the core features of Telegram: speed and security.

  • no speed - a message has to hop through one additional loop (your server) before it reaches the recipient.
  • no security - browser page will communicate with your server via AJAX or forms, I assume. This means sending data as plain text (unless you're on https), open to the whole world to see (if you were to sit on a public wifi, or something like that).

You can implement the Telegram API, it's a bit involved, but doable. But it's totally pointless, in my opinion.

As an alternative, just embed the webogram in an <iframe> or something :)

Homestead answered 28/5, 2015 at 7:6 Comment(3)
Ok, got it. About implementation of the API: looking at the telegram-cli project, it doest look quite simple. What stages for this task (simplest case - implementation of several auth functions) would you assume? Because I've never written any API's in my career.Glimp
@paus: the first few functions are the hardest, because you'll have to handle the encryption, the custom command protocol, etc. After you have this ready, the rest is pretty straightforward (regular messaging stuff, at least. Not sure about photo/video methods). Their documentation is well written. Start with this, perhaps: core.telegram.org/techfaqHomestead
@SergioTulentsev its not a big deal in security . just like every other sites like twitter.com we can use ssl (https certificate ) so our communication remains secure . so you may like to edit your answer.Felic
L
0

Now, you can use MadelineProto https://github.com/danog/MadelineProto - enought powerful PHP client for MTProto Telegram!

Loo answered 5/12, 2018 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.