PHPackages                             aliw1382/telegram-tools - 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. [API Development](/categories/api)
4. /
5. aliw1382/telegram-tools

ActiveLibrary[API Development](/categories/api)

aliw1382/telegram-tools
=======================

Package for tools building your telegram bot

2.0.0(2y ago)06MITPHPPHP &gt;=8.0

Since Sep 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/aliw1382/telegram-tools)[ Packagist](https://packagist.org/packages/aliw1382/telegram-tools)[ RSS](/packages/aliw1382-telegram-tools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

[![Laravel Telegram Tools](https://private-user-images.githubusercontent.com/22743719/264762247-f7c7bef0-3b39-4f5a-868d-cc8d54410a67.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMzk3NjksIm5iZiI6MTc3NTIzOTQ2OSwicGF0aCI6Ii8yMjc0MzcxOS8yNjQ3NjIyNDctZjdjN2JlZjAtM2IzOS00ZjVhLTg2OGQtY2M4ZDU0NDEwYTY3LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDE4MDQyOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJlNDY3Yjc5ZTRhNTUzYjU0MzBlNjRhN2JjNzVlYmNkNWVhMWU4ZGZiNmQ1ZGIxNzZlMjhmNWI5YTVlOTEwMTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.PFMguipD0sw19IjGg6-YflhbeK44A1Gd_AhC5N-G-YM)](https://private-user-images.githubusercontent.com/22743719/264762247-f7c7bef0-3b39-4f5a-868d-cc8d54410a67.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMzk3NjksIm5iZiI6MTc3NTIzOTQ2OSwicGF0aCI6Ii8yMjc0MzcxOS8yNjQ3NjIyNDctZjdjN2JlZjAtM2IzOS00ZjVhLTg2OGQtY2M4ZDU0NDEwYTY3LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDE4MDQyOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJlNDY3Yjc5ZTRhNTUzYjU0MzBlNjRhN2JjNzVlYmNkNWVhMWU4ZGZiNmQ1ZGIxNzZlMjhmNWI5YTVlOTEwMTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.PFMguipD0sw19IjGg6-YflhbeK44A1Gd_AhC5N-G-YM)

[داکیومنت فارسی](README-FA.md)

About Package
=============

[](#about-package)

> This package is in its test version, it may have problems!

This package is made so that people who build Telegram bots can easily and quickly code their bots.

This package was developed and designed by Ali Shahmohammadi.

Requirement
===========

[](#requirement)

- guzzlehttp/guzzle ^7.\*
- illuminate/support ~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0
- php &gt;= 7.4

Installation ✨
==============

[](#installation-)

To install and receive the package in your Laravel project, execute the following command in the terminal of your project path.

```
$ composer require aliw1382/telegram-tools
```

Add Providers
=============

[](#add-providers)

Open the file `config/app.php` and add the following values to it.

Providers:

```
'providers' => [

    // ......

    Aliw1382\TelegramTools\Providers\TelegramToolsServiceProvider::class,

    // ......

]
```

Aliases:

```
'aliases' => [

    // ......

    'Telegram' => Aliw1382\TelegramTools\Facades\Telegram::class,

    // ......

]
```

Publish Config
==============

[](#publish-config)

```
$ php artisan vendor:publish --tag=config-telegram-tools
```

Then the file `config/telegram.php` is created.

```
'telegram-bot-api' => [

    'token' => env( 'TELEGRAM_API_TOKEN' )

]
```

.Env File
=========

[](#env-file)

Add this `.env` file and put the token received from **Bot Father** here.

```
TELEGRAM_API_TOKEN=
```

Usage
=====

[](#usage)

- The first method

```
telegram()->sendMessage( [

    'chat_id' => 'YOUR CHAT ID',
    'text'    => 'YOUR CONTENT TEXT'
    // ....

] );

telegram( 'Your Other Token Bot' )->sendMessage( [

    'chat_id' => 'YOUR CHAT ID',
    'text'    => 'YOUR CONTENT TEXT'
    // ....

] );
```

> If you use `telegram()` we use your `.env` token bot.

- The second method

```
telegram()->sendMessage()->to( 'YOUR CHAT ID' )->content( 'YOUR CONTENT TEXT' )->send();

telegram( 'Your Other Token Bot' )->sendMessage()->to( 'YOUR CHAT ID' )->content( 'YOUR CONTENT TEXT' )->send();
```

For Example For `SendMessage` With Keyboard And Parse Mode:

```
// Keyboard
telegram()->sendMessage()->to( 'YOUR CHAT ID' )->content( 'YOUR CONTENT TEXT' )->parseMode( 'html' )->button( 'Button 1' )->button( 'Button 2' )->send();

// Inline Keyboard
telegram()->sendMessage()->to( 'YOUR CHAT ID' )->content( 'YOUR CONTENT TEXT' )->parseMode( 'MarkdownV2' )->button( 'Google' , 'https://google.com' )->buttonWithCallback( 'Button 1' , 'Your Callback Data' )->send();
```

- The third method

```
\Telegram::sendMessage( 'YOUR CHAT ID', 'YOUR CONTENT TEXT' );
```

or

```
use Aliw1382\TelegramTools\Facades\Telegram;

Telegram::sendMessage( 'YOUR CHAT ID', 'YOUR CONTENT TEXT' );
```

For Example For `SendMessage` With Keyboard And Parse Mode:

```
use Aliw1382\TelegramTools\Facades\Telegram;

Telegram::sendMessage( 'YOUR CHAT ID', 'YOUR CONTENT TEXT', Telegram::buildKeyBoard( [
    [
        Telegram::buildKeyboardButton( 'Button 1' ),
        Telegram::buildKeyboardButton( 'Button 2' , true ), // for request contact
    ]
] ) , 'html' );

Telegram::sendMessage( 'YOUR CHAT ID', 'YOUR CONTENT TEXT', Telegram::buildInlineKeyBoard( [
    [
        Telegram::buildInlineKeyboardButton( 'Google' ,'https://google.com'),
        Telegram::buildInlineKeyboardButton( 'Button 1' , '','Your CALLBACK DATA' ),
        // or
        Telegram::buildInlineKeyboardButton( text: 'Button 2' ,callback_data: 'Your CALLBACK DATA' ),
    ]
] ) , 'html' );
```

✨ I hope you enjoy this package ✨

Source Code Programming
=======================

[](#source-code-programming)

> This feature is activated in version 2.0.0 !

Okay, now it's time to handle the `/start` command in the robot.

First you need to create a class to code your bot. You can use the following command to create a class for the messages that are sent to the bot.

```
$ php artisan telegram:command StartMessage --type=Message
```

After you create your command, you need to introduce it to the program, so for this, enter the file `config/telegram.php` and add the address of the created class to it.

```
'commands' => [

    App\Telegram\StartMessage::class,
    // Commands Class

]
```

This class instance is made to handle the bot `/start` message and respond to it.

```
