PHP Classes

PHP Telegram CLI Wrapper: Send messages and other commands to Telegram users

Recommend this page to a friend!
  Info   Demos   View files View files (54)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (2)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 797 All time: 4,273 This week: 204Up
Version License PHP version Categories
telegram-cli-wrapper 1.0.3MIT/X Consortium ...5.3PHP 5, Unix, Chat
Description Author

This class can send messages and other commands to Telegram users.

It connects to the telegram CLI program via local Unix domain sockets.

The class can send many other types of command. Currently it can:

- Change the status to online or offline
- Get the contact list
- Send typing status
- Send a message to a peer
- Delete contact
- Delete user from chat
- Mark messages as read
- Get the dialog list
- Get a peer chat information
- Get user information
- Block or unblock_user
- Broadcast message
- Create group chat
- Rename_chat
- Set profile name
- Add contact
- Add user to chat
- Rename contact
- Get chat history

Innovation Award
PHP Programming Innovation award winner
November 2015
Winner


Prize: One book of choice by Packt
Telegram is a popular application for exchanging messages between users in an encrypted format.

This class can send messages and interaction with Telegram chat users using the Telegram CLI application.

Manuel Lemos
Picture of Joseluis Laso
  Performance   Level  
Name: Joseluis Laso <contact>
Classes: 16 packages by
Country: Spain Spain
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Details

A wrapper for Telegram-CLI

Dependencies

Follow the instructions for your operating system.

You need to start the telegram-cli the first time manually in order to register the phone number.

./bin/telegram-cli

After that, start telegram-cli as a daemon from the root of the tg repo.

./bin/telegram-cli --json -dWS /tmp/tg.sck &

You can try to use that one to install telegram-cli as a daemon in your server (I was unable to do) https://github.com/vysheng/tg/wiki/Running-Telegram-CLI-as-Daemon

Notes

Basically you have to create a group telegram and add users www-data (or apache), root (or the user you use to access through ssh) and telegramd. give permissions to /tmp/tg.sck to that group (telegram) You can start telegram-cli manually following the above order or just let the script to start it.

Install

Once installed vysheng/tg clone this project with:


Run ```composer install``` inside the folder repo in order to create autoload files.

##Examples
Take a look on test folder to see how easy is to use the wrapper.

If you don't want to have started telegram-cli you can use TelegramCliHelper in order to start it automatically each time
is needed. To do that you need to create a config.ini in the config folder (you have config.ini.dis as a template)

All the examples in the test folder use this Helper.

##Why TelegramCliHelper and Why to use it ?

The better way to use telegram-cli IMHO is to have started always the telegram-cli as a daemon. But maybe you want to
test something or only start it when you really need it. Becase you use a lazy cron that checks for chats once per hour or
something like that. In a real environment I would prefer to have started telegram-cli and a php script checking in loop
all chats in order to serve to users in real time.

##Last thoughts
In order that you know how to use the automated system to accept "orders" from the users or notify them by Telegram
I have prepared a little web application that you can find in /public folder.
Remember that some "orders" need defailed configuration in /config/config.ini,  openweathermap is one of them. You can
create a free account. The weather is cached in order that don't exceed the number of free calls.

Obviously all of this is only a big example, a proof of concept if you want. 
You have to create the services that your web need and provide access to your users in the way you consider the better.

In order to simplify at maximum the examples I have created a simpleStorage system for users that come to the web, on the
/data/user folder the users are serialized and labeled with the phone number. In your definitive system you have to connect
your real users with the phone number, probably with a mysql table or something like that.

Any pull request or issue with improvement proposal are welcome.

  Online demoExternal page  

Open in a separate window

  Files folder image Files  
File Role Description
Files folder imageconfig (1 file)
Files folder imagepublic (9 files, 3 directories)
Files folder imagesrc (4 files, 3 directories)
Files folder imagetest (7 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file config.ini.dis Doc. Documentation

  Files folder image Files  /  public  
File Role Description
Files folder imagecss (1 file)
Files folder imageimg (3 files)
Files folder imagejs (2 files)
  Accessible without login Plain text file area.php Example Example script
  Accessible without login Plain text file check.php Example Example script
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file login.php Example Example script
  Accessible without login Plain text file messages.php Example Example script
  Accessible without login Plain text file profile.php Example Example script
  Accessible without login Plain text file register.php Example Example script
  Accessible without login Plain text file send.php Example Example script

  Files folder image Files  /  public  /  css  
File Role Description
  Accessible without login Plain text file styles.css Data Auxiliary data

  Files folder image Files  /  public  /  img  
File Role Description
  Accessible without login Image file ajax-loader.gif Data Auxiliary data
  Accessible without login Image file telegram-lo.png Icon Icon image
  Accessible without login Image file telegram.png Data Auxiliary data

  Files folder image Files  /  public  /  js  
File Role Description
  Accessible without login Plain text file common.js Data Auxiliary data
  Accessible without login Plain text file ie10-viewport-bug-workaround.js Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageModels (4 files)
Files folder imageServices (3 directories)
Files folder imageStorage (2 files)
  Accessible without login Plain text file Config.php Class Class source
  Accessible without login Plain text file Response.php Class Class source
  Accessible without login Plain text file TelegramCliHelper.php Class Class source
  Accessible without login Plain text file TelegramCliWrapper.php Class Class source

  Files folder image Files  /  src  /  Models  
File Role Description
  Accessible without login Plain text file BasicObject.php Class Class source
  Accessible without login Plain text file Dialog.php Class Class source
  Accessible without login Plain text file Flags.php Class Class source
  Accessible without login Plain text file User.php Class Class source

  Files folder image Files  /  src  /  Services  
File Role Description
Files folder imageJoke (1 file)
Files folder imageMedia (1 file, 1 directory)
Files folder imageWeather (1 file)

  Files folder image Files  /  src  /  Services  /  Joke  
File Role Description
  Accessible without login Plain text file IcndbApi.php Class Class source

  Files folder image Files  /  src  /  Services  /  Media  
File Role Description
Files folder imageimages (15 files)
  Accessible without login Plain text file MediaSelector.php Class Class source

  Files folder image Files  /  src  /  Services  /  Media  /  images  
File Role Description
  Accessible without login Image file 0.jpg Icon Icon image
  Accessible without login Image file 1.jpg Icon Icon image
  Accessible without login Image file 10.jpg Icon Icon image
  Accessible without login Image file 11.jpg Icon Icon image
  Accessible without login Image file 12.jpg Icon Icon image
  Accessible without login Image file 13.jpg Icon Icon image
  Accessible without login Image file 14.jpg Icon Icon image
  Accessible without login Image file 2.jpg Icon Icon image
  Accessible without login Image file 3.jpg Icon Icon image
  Accessible without login Image file 4.jpg Icon Icon image
  Accessible without login Image file 5.jpg Icon Icon image
  Accessible without login Image file 6.jpg Icon Icon image
  Accessible without login Image file 7.jpg Icon Icon image
  Accessible without login Image file 8.jpg Icon Icon image
  Accessible without login Image file 9.jpg Icon Icon image

  Files folder image Files  /  src  /  Services  /  Weather  
File Role Description
  Accessible without login Plain text file OpenWeatherApi.php Class Class source

  Files folder image Files  /  src  /  Storage  
File Role Description
  Accessible without login Plain text file LocalFilesStorage.php Class Class source
  Accessible without login Plain text file StorageInterface.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file addContact.php Example Example script
  Accessible without login Plain text file myChatWith.php Example Example script
  Accessible without login Plain text file myContacts.php Example Example script
  Accessible without login Plain text file myDialogs.php Example Example script
  Accessible without login Plain text file server-sample.php Example Example script
  Accessible without login Plain text file userInfo.php Example Example script
  Accessible without login Plain text file whoAmI.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:797
This week:0
All time:4,273
This week:204Up
User Comments (1)
It's Cool )) but not full ))
6 years ago (Inoyatullokhon Junaydullaev)
55%StarStarStar
 
For more information send a message to info at phpclasses dot org.