PHPackages                             williamson/laragram - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. williamson/laragram

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

williamson/laragram
===================

A Laravel Wrapper for telegram-cli

v1.0.1(10y ago)282.8k5[2 issues](https://github.com/jonnywilliamson/laragram/issues)MPL-2.0PHPPHP &gt;=5.4.0

Since May 10Pushed 10y ago3 watchersCompare

[ Source](https://github.com/jonnywilliamson/laragram)[ Packagist](https://packagist.org/packages/williamson/laragram)[ RSS](/packages/williamson-laragram/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (7)Used By (0)

Laravel Wrapper for telegram-cli
================================

[](#laravel-wrapper-for-telegram-cli)

This project was originally forked from: [php-telegram-cli-client](https://github.com/zyberspace/php-telegram-cli-client) and credit to [zyberspace](https://github.com/zyberspace) for the start I needed to get this project working.

What is new in 1.0?
-------------------

[](#what-is-new-in-10)

- To make the laravel service provider "deferred" (performance enhancing feature), you must now manually register the `TG` alias in the `config/app.php` alias section.

What is it?
-----------

[](#what-is-it)

This project allows you to use the lovely Laravel syntax you are familar with to quickly and easily send messages / images / documents / audio files / location via [Telegram Messenger](https://telegram.org) with the aid of [telegram-cli](https://github.com/vysheng/tg/) running on your server.

It allows you do things like:

```
	TG::sendMessage('User_name', 'Hi there your account has been set up! Thanks!');
```

or

```
	TG::sendDocument('User_name', '/home/data/files/important.pdf');
```

or

```
	TG::sendImage('User_name', 'http://upload.wikimedia.org/wikipedia/commons/1/16/HDRI_Sample_Scene_Balls_(JPEG-HDR).jpg');
```

Of course if you don't like using Facades you can always revert to

```
	// $tg is an instantiated TgCommands Object. Laravel will create this out of the IOC container for
	// you if typehinted in constructor etc.
	$tg->sendMessage('User_name', 'Hi there your account has been set up! Thanks!');
```

Requirements
------------

[](#requirements)

- A **running** [telegram-cli](https://github.com/vysheng/tg/) listening on a unix-socket (`-S`) or a port (`-P`). Needs to be configured already (phone-number, etc.).
- php &gt;= 5.4.0
- curl installed
- json flag added to the telegram daemon startup command

Installing Telegram-cli
-----------------------

[](#installing-telegram-cli)

### Setup telegram-cli

[](#setup-telegram-cli)

[Telegram-cli](https://github.com/vysheng/tg/) needs to run on a unix-socket (`-S`) or a port (`-P`), so *laragram* can connect to it. Please read the instructions at [telegram-cli](https://github.com/vysheng/tg/) on how to `configure` and then `make`

If your build was successful you can continue!

### First time running telegram-cli

[](#first-time-running-telegram-cli)

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.

Assuming you installed telegram in `~/telegram` your command should look like this: `~/telegram/bin/telegram-cli`.

Once registered, you can exit telegram-cli (`safe_quit`) and launch it as a daemon.

### Running telegram-cli as a daemon

[](#running-telegram-cli-as-a-daemon)

To run telegram-cli as a daemon you need to use the `-d` flag and set a unix socket `-S`.

```
~/telegram/bin/telegram-cli -k ~/telegram/tg-server.pub -dWS /tmp/tg.sck --json
```

Or instead you may use a TCP port

```
~/telegram/bin/telegram-cli -k ~/telegram/tg-server.pub -dWP 7777 --json

```

The `-W` switch means the contact-list gets loaded on startup - this allows you to send messages straight away. The `&` at the ends means that the command will load in the background allowing you to continue with the script.

To stop the daemon use `killall telegram-cli` or `kill -TERM [telegram-pid]`.

You now have [Telegram-cli](https://github.com/vysheng/tg/) working and waiting to be told what to send!

To ensure your daemon does not exit unexpectantly, you can use something like supervisor to make sure the process always is running. See notes at the end of how this can be set up.

Installing Laragram
-------------------

[](#installing-laragram)

### Install Laragram with composer

[](#install-laragram-with-composer)

In your laravel project-root:

```
composer require williamson/laragram
```

### Service Providers and Facades

[](#service-providers-and-facades)

Open `config/app.php` file, find the providers array and add to the bottom

```
        'Williamson\Laragram\Laravel\LaragramServiceProvider'
```

If you're running Laravel 5.1 or greater you can use this syntax instead in the `config/app.php` file:

```
        Williamson\Laragram\Laravel\LaragramServiceProvider::class
```

***Note the lack of single quotes for the laravel 5 version.***

Now you add the following line to the Alias array in `config/app.php` to register the shorthand `TG` facade

```
        'TG' => \Williamson\Laragram\Laravel\LaragramFacade::class,
```

Open `config/services.php` file, add the following array to specify what type of socket you would like to connect to the telegram daemon.

```
    'telegram' => [
        'socket' =>'tcp://127.0.0.1:7778'
    ]
```

Other values include unix sockets. ie `'socket' => 'unix:///tmp/tg.sck'`

You're done!

Using Laragram
--------------

[](#using-laragram)

Now anywhere in your app you can send a telegram message quickly and easily like follows:

```
   // routes.php

     Route::get('/test', function (){
          TG::sendMsg('', 'Hello there!');
     });
```

Remember that the name should have underscores instead of spaces eg `firstname_lastname`, OR you can use `user#`and then the persons telegram ID directly. This method is far more reliable. eg `user#123456789`

In addition to sendMessage, the following commands are available to you:

```
broadcastMsg
chatAddUser
chatCreateGroup
chatCreateSecret
chatDelUser
chatExportLink
chatInfo
chatRename
chatSetPhoto
contactAdd
contactDelete
contactList
contactRename
deleteMsg
exportCard
getContactList
getDialogList
getHistory
getUserInfo
markRead
msg
sendAudio
sendContact
sendDocument
sendLocation
sendMsg
sendPhoto
sendText
sendTypingStart
sendTypingStop
sendVideo
setProfileName
setProfilePhoto
setStatusOffline
setStatusOnline
setUsername

```

License
-------

[](#license)

This software is licensed under the [Mozilla Public License v. 2.0](http://mozilla.org/MPL/2.0/). For more information, read the file `LICENSE`.

Using Supervisor
----------------

[](#using-supervisor)

Assuming that you have

- supervisord installed on your system (if not [supervisord install](http://supervisord.org/installing.html) ) and
- telegram has been installed in `/home/username/telegram`

Then create a new file `/etc/supervisor/conf.d/telegram.conf`

and copy the following into it, adding/replacing any log files you wish to create

```
[program:telegram]
command=/bin/bash -c "rm -f /tmp/tg.sck && /home/username/telegram/bin/telegram-cli -k /home/username/telegram/tg-server.pub -dWS /tmp/tg.sck --json"
;For tcp socket this could be
;command=/bin/bash -c "/home/username/telegram/bin/telegram-cli -k /home/username/telegram/tg-server.pub -dWP 7777 --json"
directory=/home/username/telegram
redirect_stderr=true
stopsignal=KILL
stopasgroup=true
autostart=true
autorestart=true
startretries=3
user=
stdout_logfile=
stderr_logfile=
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
```

Save the file and restart supervisor (make sure that telegram-cli is NOT running before you do this, supervisor will now take care of insuring that the process always runs even if it crashes).

```
sudo service supervisor restart
```

You can view how the process is doing by using the monitoring program `sudo supervisorctl`

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~89 days

Total

5

Last Release

3661d ago

Major Versions

v0.1.2 → v1.02016-05-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d49027d932462d2ae04ee9af02a66ef589e60e8d73d03c43f06985d17b5805e?d=identicon)[jonnywilliamson](/maintainers/jonnywilliamson)

---

Top Contributors

[![jonnywilliamson](https://avatars.githubusercontent.com/u/2513663?v=4)](https://github.com/jonnywilliamson "jonnywilliamson (35 commits)")[![pr00thmatic](https://avatars.githubusercontent.com/u/5183802?v=4)](https://github.com/pr00thmatic "pr00thmatic (1 commits)")

---

Tags

laraveltelegramphp-cli

### Embed Badge

![Health badge](/badges/williamson-laragram/health.svg)

```
[![Health](https://phpackages.com/badges/williamson-laragram/health.svg)](https://phpackages.com/packages/williamson-laragram)
```

###  Alternatives

[setiawanhu/laravel-madeline-proto

A third party Telegram client library danog/MadelineProto wrapper for Laravel

515.2k](/packages/setiawanhu-laravel-madeline-proto)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
