Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telegram-based chat on a PHP-based site: HOWTO?

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!

like image 385
Павел Иванов Avatar asked May 28 '15 05:05

Павел Иванов


People also ask

How can I send message to Telegram channel in PHP?

To send a message to the Telegram channel use the following PHP script example: <? php $apiToken = "5082654068:AAF7quCLZ4xuTq2FBdo3POssdJsM_FRHwTs"; $data = [ 'chat_id' => '515382482', 'text' => 'Hello from PHP! ' ]; $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .

Can Telegram BOT send message to phone number?

It is NOT possible for a bot to send messages to a phone number. As far as I know, it is also NOT possible to send to a @username , unless it is a @channel_username . A bot sends messages by user_id . It can know your user_id only if you have send it a message first.


2 Answers

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

like image 113
Charles Okwuagwu Avatar answered Oct 06 '22 00:10

Charles Okwuagwu


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 :)

like image 24
Sergio Tulentsev Avatar answered Oct 06 '22 00:10

Sergio Tulentsev