2017 © Pedro Peláez
 

library telegram-cli-client

php-client for telegram-cli

image

alexeevdv/telegram-cli-client

php-client for telegram-cli

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 64 Forks
  • 0 Open issues
  • 7 Versions
  • 3 % Grown

The README.md

Update 2015-12-23:

As i currently have no time to work on this project anymore and telegram released its own bot-api, there won't be many new updates to this project in the future. I will try to go through all currently open issues so there is nothing left in the issue section anymore (even if i need to close some things with wontfix).
If someone wants to takeover this project i am willing to give him push-rights or link to his fork on github/packagist.
, (*1)

If you want to port your project to the new bot-api take a look at the unofficial php-sdk., (*2)


zyberspace/telegram-cli-client

php-client for telegram-cli, (*3)

Packagist Codacy License, (*4)

Requirements

  • a running telegram-cli listening on a unix-socket (-S) or a port (-P) and returning all answers as JSON (--json).
    Needs to be configured already (phone-number, etc.).
  • php >= 5.3.0

Usage

Setup telegram-cli

telegram-cli needs to run on a unix-socket (-S) or a port (-P), so telegram-cli-client can connect to it. All answers need to be returned as JSON (--json).
You should also start it with -W so the contact-list gets loaded on startup.
For this example we will take the following command (execute it from the dir, where you installed telegram-cli, not the php-client), -d lets it run as daemon.:, (*5)

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

If you run the telegram-cli under another user than your php-script and you are using linux, you need to change the rights of the socket so that the php-script can access it (thanks to dennydai for this!).
For example, add both to a telegram-group and then do, (*6)

chown :telegram /tmp/tg.sck
chmod g+rwx /tmp/tg.sck

If you never started telegram-cli before, you need to start it first in normal mode, so you can type in your telegram-phone-number and register it, if needed (./bin/telegram-cli)., (*7)

To stop the daemon use killall telegram-cli or kill -TERM [telegram-pid]., (*8)

Install telegram-cli-client with composer

In your project-root:, (*9)

composer require --update-no-dev zyberspace/telegram-cli-client

Composer will then automatically add the package to your project requirements and install it (also creates the composer.json if you don't have one already).
If you want to use the discovery-shell, remove the --update-no-dev from the command., (*10)

Use it

require('vendor/autoload.php');
$telegram = new \Zyberspace\Telegram\Cli\Client('unix:///tmp/tg.sck');

$contactList = $telegram->getContactList();
$telegram->msg($contactList[0]->print_name, 'Hey man, what\'s up? :D');

Use it with the discovery-shell

A really easy way to learn the api is by using the embedded discover-shell. You need to install the dev-dependencies for this (composer update --dev)., (*11)

$ ./discovery-shell.php
-- discovery-shell to help discover a class or library --

Use TAB for autocompletion and your arrow-keys to navigate through your method-history.
Beware! This is not a full-featured php-shell. The input gets parsed with PHP-Parser to avoid the usage of
eval().
> $telegram->getContactList();
array(13) {
  [...]
}
> $telegram->msg('my_contact', 'Hi, i am sending this from a php-client for telegram-cli.');
true

Documentation

To create the docs, just run phpdoc in the the project-root.
An online-version is available at phpdoc.zyberware.org/zyberspace/telegram-cli-client., (*12)

Supported Commands

You can execute every command with the exec()-method from the RawClient-class, but there are also several command-wrappers available (doc-link) that you should prefer to use (see the example.php).
If you prefer to only use your own command-wrappers instead, just extend the RawClient-class (takes care about the socket-connection and has some helper-methods)., (*13)

In your command-wrappers or if you use exec() directly, please don't forget to escape the peers (contacts, chat-names, etc.) with escapePeer() and all string-arguments with escapeStringArgument() to avoid errors., (*14)

API-Stability

The api of the commands wrappers will definitely change in the future, for example getHistory() only returns the raw answer of the telegram-cli right now and is not really useful. Therefore you should not use this in production yet., (*15)

If you still want to use this in your project, make sure you stay at the same minor-version (~0.1.0 or 0.1.* for example)., (*16)

License

This software is licensed under the Mozilla Public License v. 2.0. For more information, read the file LICENSE., (*17)

The Versions

19/03 2017

dev-master

9999999-dev https://github.com/alexeevdv/php-telegram-cli-client

php-client for telegram-cli

  Sources   Download

MPL-2.0

The Requires

  • php >=5.3

 

The Development Requires

by Avatar zyberspace

23/12 2015

v0.4.1

0.4.1.0 https://github.com/zyberspace/php-telegram-cli-client

php-client for telegram-cli

  Sources   Download

MPL-2.0

The Requires

  • php >=5.3.0,<6.0.0

 

The Development Requires

by Avatar zyberspace

09/07 2015

v0.4.0

0.4.0.0 https://github.com/zyberspace/php-telegram-cli-client

php-client for telegram-cli

  Sources   Download

MPL-2.0

The Requires

  • php >=5.3.0,<6.0.0

 

The Development Requires

by Avatar zyberspace

11/05 2015

v0.3.0

0.3.0.0 https://github.com/zyberspace/php-telegram-cli-client

php-client for telegram-cli

  Sources   Download

MPL-2.0

The Requires

  • php >=5.3.0,<6.0.0

 

by Avatar zyberspace

10/05 2015

v0.2.0

0.2.0.0 https://github.com/zyberspace/php-telegram-cli-client

php-client for telegram-cli

  Sources   Download

MPL-2.0

The Requires

  • php >=5.4.0,<6.0.0

 

by Avatar zyberspace

10/05 2015

v0.1.1

0.1.1.0 https://github.com/zyberspace/php-telegram-cli-client

php-client for telegram-cli

  Sources   Download

MPL-2.0

The Requires

  • php >=5.4.0,<6.0.0

 

by Avatar zyberspace

18/02 2015

v0.1.0

0.1.0.0 https://github.com/zyberspace/php-telegram-cli-client

php-client for telegram-cli

  Sources   Download

MPL-2.0

The Requires

  • php >=5.4.0,<6.0.0

 

by Avatar zyberspace