GithubHelp home page GithubHelp logo

php-telegram-bot / laravel Goto Github PK

View Code? Open in Web Editor NEW
161.0 161.0 47.0 8.1 MB

Laravel package for PHP Telegram Bot Library

License: Other

PHP 100.00%
hacktoberfest laravel laravel-package php php-telegram-bot telegram telegram-bot

laravel's Introduction

PHP Telegram Bot

PHP Telegram Bot logo

A Telegram Bot based on the official Telegram Bot API

API Version Join the bot support group on Telegram Donate

Tests Code Coverage Code Quality Latest Stable Version Dependencies Total Downloads Downloads Month Minimum PHP Version License

Table of Contents

Introduction

This is a pure PHP Telegram Bot, fully extensible via plugins.

Telegram announced official support for a Bot API, allowing integrators of all sorts to bring automated interactions to the mobile platform. This Bot aims to provide a platform where one can simply write a bot and have interactions in a matter of minutes.

The Bot can:

  • Retrieve updates with webhook and getUpdates methods.
  • Supports all types and methods according to Telegram Bot API 7.1 (February 2024).
  • Supports supergroups.
  • Handle commands in chat with other bots.
  • Manage Channel from the bot admin interface.
  • Full support for inline bots.
  • Inline keyboard.
  • Messages, InlineQuery and ChosenInlineQuery are stored in the Database.
  • Conversation feature.

This code is available on GitHub. Pull requests are welcome.

Instructions

Create your first bot

  1. Message @BotFather with the following text: /newbot

    If you don't know how to message by username, click the search field on your Telegram app and type @BotFather, where you should be able to initiate a conversation. Be careful not to send it to the wrong contact, because some users have similar usernames to BotFather.

    BotFather initial conversation

  2. @BotFather replies with:

    Alright, a new bot. How are we going to call it? Please choose a name for your bot.
    
  3. Type whatever name you want for your bot.

  4. @BotFather replies with:

    Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.
    
  5. Type whatever username you want for your bot, minimum 5 characters, and must end with bot. For example: telesample_bot

  6. @BotFather replies with:

    Done! Congratulations on your new bot. You will find it at
    telegram.me/telesample_bot. You can now add a description, about
    section and profile picture for your bot, see /help for a list of
    commands.
    
    Use this token to access the HTTP API:
    123456789:AAG90e14-0f8-40183D-18491dDE
    
    For a description of the Bot API, see this page:
    https://core.telegram.org/bots/api
    
  7. Note down the 'token' mentioned above.

Optionally set the bot privacy:

  1. Send /setprivacy to @BotFather.

    BotFather later conversation

  2. @BotFather replies with:

    Choose a bot to change group messages settings.
    
  3. Type (or select) @telesample_bot (change to the username you set at step 5 above, but start it with @)

  4. @BotFather replies with:

    'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.
    'Disable' - your bot will receive all messages that people send to groups.
    Current status is: ENABLED
    
  5. Type (or select) Disable to let your bot receive all messages sent to a group.

  6. @BotFather replies with:

    Success! The new status is: DISABLED. /help
    

Require this package with Composer

Install this package through Composer. Edit your project's composer.json file to require longman/telegram-bot.

Create composer.json file

{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "php": "^8.1",
        "longman/telegram-bot": "*"
    }
}

and run composer update

or

run this command in your command line:

composer require longman/telegram-bot

Choose how to retrieve Telegram updates

The bot can handle updates with Webhook or getUpdates method:

Webhook getUpdates
Description Telegram sends the updates directly to your host You have to fetch Telegram updates manually
Host with https Required Not required
MySQL Not required (Not) Required

Using a custom Bot API server

For advanced users only!

As from Telegram Bot API 5.0, users can run their own Bot API server to handle updates. This means, that the PHP Telegram Bot needs to be configured to serve that custom URI. Additionally, you can define the URI where uploaded files to the bot can be downloaded (note the {API_KEY} placeholder).

Longman\TelegramBot\Request::setCustomBotApiUri(
    $api_base_uri          = 'https://your-bot-api-server', // Default: https://api.telegram.org
    $api_base_download_uri = '/path/to/files/{API_KEY}'     // Default: /file/bot{API_KEY}
);

Note: If you are running your bot in --local mode, you won't need the Request::downloadFile() method, since you can then access your files directly from the absolute path returned by Request::getFile().

Webhook installation

Note: For a more detailed explanation, head over to the example-bot repository and follow the instructions there.

In order to set a Webhook you need a server with HTTPS and composer support. (For a self signed certificate you need to add some extra code)

Create set.php with the following contents:

<?php
// Load composer
require __DIR__ . '/vendor/autoload.php';

$bot_api_key  = 'your:bot_api_key';
$bot_username = 'username_bot';
$hook_url     = 'https://your-domain/path/to/hook.php';

try {
    // Create Telegram API object
    $telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);

    // Set webhook
    $result = $telegram->setWebhook($hook_url);
    if ($result->isOk()) {
        echo $result->getDescription();
    }
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
    // log telegram errors
    // echo $e->getMessage();
}

Open your set.php via the browser to register the webhook with Telegram. You should see Webhook was set.

Now, create hook.php with the following contents:

<?php
// Load composer
require __DIR__ . '/vendor/autoload.php';

$bot_api_key  = 'your:bot_api_key';
$bot_username = 'username_bot';

try {
    // Create Telegram API object
    $telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);

    // Handle telegram webhook request
    $telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
    // Silence is golden!
    // log telegram errors
    // echo $e->getMessage();
}

Self Signed Certificate

Upload the certificate and add the path as a parameter in set.php:

$result = $telegram->setWebhook($hook_url, ['certificate' => '/path/to/certificate']);

Unset Webhook

Edit unset.php with your bot credentials and execute it.

getUpdates installation

For best performance, the MySQL database should be enabled for the getUpdates method!

Create getUpdatesCLI.php with the following contents:

#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';

$bot_api_key  = 'your:bot_api_key';
$bot_username = 'username_bot';

$mysql_credentials = [
   'host'     => 'localhost',
   'port'     => 3306, // optional
   'user'     => 'dbuser',
   'password' => 'dbpass',
   'database' => 'dbname',
];

try {
    // Create Telegram API object
    $telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);

    // Enable MySQL
    $telegram->enableMySql($mysql_credentials);

    // Handle telegram getUpdates request
    $telegram->handleGetUpdates();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
    // log telegram errors
    // echo $e->getMessage();
}

Next, give the file permission to execute:

$ chmod +x getUpdatesCLI.php

Lastly, run it!

$ ./getUpdatesCLI.php

getUpdates without database

If you choose to / or are obliged to use the getUpdates method without a database, you can replace the $telegram->enableMySql(...); line above with:

$telegram->useGetUpdatesWithoutDatabase();

Filter Update

โ— Note that by default, Telegram will send any new update types that may be added in the future. This may cause commands that don't take this into account to break!

It is suggested that you specifically define which update types your bot can receive and handle correctly.

You can define which update types are sent to your bot by defining them when setting the webhook or passing an array of allowed types when using getUpdates.

use Longman\TelegramBot\Entities\Update;

// For all update types currently implemented in this library:
// $allowed_updates = Update::getUpdateTypes();

// Define the list of allowed Update types manually:
$allowed_updates = [
    Update::TYPE_MESSAGE,
    Update::TYPE_CHANNEL_POST,
    // etc.
];

// When setting the webhook.
$telegram->setWebhook($hook_url, ['allowed_updates' => $allowed_updates]);

// When handling the getUpdates method.
$telegram->handleGetUpdates(['allowed_updates' => $allowed_updates]);

Alternatively, Update processing can be allowed or denied by defining a custom update filter.

Let's say we only want to allow messages from a user with ID 428, we can do the following before handling the request:

$telegram->setUpdateFilter(function (Update $update, Telegram $telegram, &$reason = 'Update denied by update_filter') {
    $user_id = $update->getMessage()->getFrom()->getId();
    if ($user_id === 428) {
        return true;
    }

    $reason = "Invalid user with ID {$user_id}";
    return false;
});

The reason for denying an update can be defined with the $reason parameter. This text gets written to the debug log.

Support

Types

All types are implemented according to Telegram API 7.1 (February 2024).

Inline Query

Full support for inline query according to Telegram API 7.1 (February 2024).

Methods

All methods are implemented according to Telegram API 7.1 (February 2024).

Send Message

Messages longer than 4096 characters are split up into multiple messages.

$result = Request::sendMessage([
    'chat_id' => $chat_id,
    'text'    => 'Your utf8 text ๐Ÿ˜œ ...',
]);

Send Photo

To send a local photo, add it properly to the $data parameter using the file path:

$result = Request::sendPhoto([
    'chat_id' => $chat_id,
    'photo'   => Request::encodeFile('/path/to/pic.jpg'),
]);

If you know the file_id of a previously uploaded file, just use it directly in the data array:

$result = Request::sendPhoto([
    'chat_id' => $chat_id,
    'photo'   => 'AAQCCBNtIhAoAAss4tLEZ3x6HzqVAAqC',
]);

To send a remote photo, use the direct URL instead:

$result = Request::sendPhoto([
    'chat_id' => $chat_id,
    'photo'   => 'https://example.com/path/to/pic.jpg',
]);

sendAudio, sendDocument, sendAnimation, sendSticker, sendVideo, sendVoice and sendVideoNote all work in the same way, just check the API documentation for the exact usage. See the ImageCommand.php for a full example.

Send Chat Action

Request::sendChatAction([
    'chat_id' => $chat_id,
    'action'  => Longman\TelegramBot\ChatAction::TYPING,
]);

getUserProfilePhoto

Retrieve the user photo. (see WhoamiCommand.php for a full example)

getFile and downloadFile

Get the file path and download it. (see WhoamiCommand.php for a full example)

Send message to all active chats

To do this you have to enable the MySQL connection. Here's an example of use (check DB::selectChats() for parameter usage):

$results = Request::sendToActiveChats(
    'sendMessage', // Callback function to execute (see Request.php methods)
    ['text' => 'Hey! Check out the new features!!'], // Param to evaluate the request
    [
        'groups'      => true,
        'supergroups' => true,
        'channels'    => false,
        'users'       => true,
    ]
);

You can also broadcast a message to users, from the private chat with your bot. Take a look at the admin commands below.

Utils

MySQL storage (Recommended)

If you want to save messages/users/chats for further usage in commands, create a new database (utf8mb4_unicode_520_ci), import structure.sql and enable MySQL support BEFORE handle() method:

$mysql_credentials = [
   'host'     => 'localhost',
   'port'     => 3306, // optional
   'user'     => 'dbuser',
   'password' => 'dbpass',
   'database' => 'dbname',
];

$telegram->enableMySql($mysql_credentials);

You can set a custom prefix to all the tables while you are enabling MySQL:

$telegram->enableMySql($mysql_credentials, $bot_username . '_');

You can also store inline query and chosen inline query data in the database.

External Database connection

It is possible to provide the library with an external MySQL PDO connection. Here's how to configure it:

$telegram->enableExternalMySql($external_pdo_connection);
//$telegram->enableExternalMySql($external_pdo_connection, $table_prefix)

Channels Support

All methods implemented can be used to manage channels. With admin commands you can manage your channels directly with your bot private chat.

Commands

Predefined Commands

The bot is able to recognise commands in a chat with multiple bots (/command@mybot).

It can also execute commands that get triggered by events, so-called Service Messages.

Custom Commands

Maybe you would like to develop your own commands. There is a guide to help you create your own commands.

Also, be sure to have a look at the example commands to learn more about custom commands and how they work.

You can add your custom commands in different ways:

// Add a folder that contains command files
$telegram->addCommandsPath('/path/to/command/files');
//$telegram->addCommandsPaths(['/path/to/command/files', '/another/path']);

// Add a command directly using the class name
$telegram->addCommandClass(MyCommand::class);
//$telegram->addCommandClasses([MyCommand::class, MyOtherCommand::class]);

Commands Configuration

With this method you can set some command specific parameters, for example:

// Google geocode/timezone API key for /date command
$telegram->setCommandConfig('date', [
    'google_api_key' => 'your_google_api_key_here',
]);

// OpenWeatherMap API key for /weather command
$telegram->setCommandConfig('weather', [
    'owm_api_key' => 'your_owm_api_key_here',
]);

Admin Commands

Enabling this feature, the bot admin can perform some super user commands like:

  • List all the chats started with the bot /chats
  • Clean up old database entries /cleanup
  • Show debug information about the bot /debug
  • Send message to all chats /sendtoall
  • Post any content to your channels /sendtochannel
  • Inspect a user or a chat with /whois

Take a look at all default admin commands stored in the src/Commands/AdminCommands/ folder.

Set Admins

You can specify one or more admins with this option:

// Single admin
$telegram->enableAdmin(your_telegram_user_id);

// Multiple admins
$telegram->enableAdmins([
    your_telegram_user_id,
    other_telegram_user_id,
]);

Telegram user id can be retrieved with the /whoami command.

Channel Administration

To enable this feature follow these steps:

  • Add your bot as channel administrator, this can be done with any Telegram client.
  • Enable admin interface for your user as explained in the admin section above.
  • Enter your channel name as a parameter for the /sendtochannel command:
$telegram->setCommandConfig('sendtochannel', [
    'your_channel' => [
        '@type_here_your_channel',
    ]
]);
  • If you want to manage more channels:
$telegram->setCommandConfig('sendtochannel', [
    'your_channel' => [
        '@type_here_your_channel',
        '@type_here_another_channel',
        '@and_so_on',
    ]
]);
  • Enjoy!

Upload and Download directory path

To use the Upload and Download functionality, you need to set the paths with:

$telegram->setDownloadPath('/your/path/Download');
$telegram->setUploadPath('/your/path/Upload');

Documentation

Take a look at the repo Wiki for further information and tutorials! Feel free to improve!

Assets

All project assets can be found in the assets repository.

Example bot

We're busy working on a full A-Z example bot, to help get you started with this library and to show you how to use all its features. You can check the progress of the example-bot repository).

Projects with this library

Here's a list of projects that feats this library, feel free to add yours!

Troubleshooting

If you like living on the edge, please report any bugs you find on the PHP Telegram Bot issues page.

Contributing

See CONTRIBUTING for more information.

Security

See SECURITY for more information.

Donate

All work on this bot consists of many hours of coding during our free time, to provide you with a Telegram Bot library that is easy to use and extend. If you enjoy using this library and would like to say thank you, donations are a great way to show your support.

Donations are invested back into the project ๐Ÿ‘

Thank you for keeping this project alive ๐Ÿ™

For enterprise

Available as part of the Tidelift Subscription.

The maintainers of PHP Telegram Bot and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

License

Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.

Credits

Credit list in CREDITS


laravel's People

Contributors

igormonkey avatar noplanman avatar tiifuchs avatar torrents-forever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel's Issues

Commands don't answer after correct update data received from telegram.

I've get confused when bot was silent on webhook method. DB updates correct. But bot don't answer on any command. So I desided to test on update method and got the same =( DB updating with correct recieving data from telegram, but don't answer. So I add Request::sendMessage to handleGetUpdates() in my controller to check if there any connect problems with telegram on my side:

public function handleGetUpdates(PhpTelegramBotContract $telegram)
{
	try {
		\Longman\TelegramBot\Request::initialize($telegram);
		\Longman\TelegramBot\Request::sendMessage(["chat_id" => "MY_TG_ID", "text" => "123"]);
		
		return $telegram->handleGetUpdates();
	} catch (TelegramException $e) {
		TelegramLog::error($e->getMessage());
	}
}

But bot breakes the silence)

So I thing there is some problems with Command factory, but I can't find where. Can somebody help me with this?

Can we have example into the line too..

Hi there,

Will support this project, however wondering how can I implement the commands etc..Maybe we can have example too for the laravel program.

Need to get more info on where we need to add TOKENBOT etc...

Thanks..

I'm getting error when i install package on laravel 8

I'm using php 8 to work with laravel 8. And I'm getting this error while installing:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - longman/telegram-bot 0.53.0 requires php ^5.5|^7.0 -> your php version (8.0.7) does not satisfy that requirement.
    - php-telegram-bot/laravel 0.0.1 requires longman/telegram-bot ^0.53.0 -> satisfiable by longman/telegram-bot[0.53.0].
    - Root composer.json requires php-telegram-bot/laravel ^0.0.1 -> satisfiable by php-telegram-bot/laravel[0.0.1].


Installation failed, deleting ./composer.json.

Multiple Bots

Hello, I have been using the package for some time, and now I want to add more bots, like I want to create new controller for another bot which will have its own commands and stuff, any idea?

Database issues

Need to sync migrations or delete all migrations and use sql file from core repo.

log cycling

Hey! There is a problem i was found at TelegramFetchCommand.php

while (true) {

    $response = rescue(fn() => $bot->handleGetUpdates($options));

    if ($response !== null && ! $response->isOk()) {
        $this->error($response->getDescription());
    }

}

setting timeout option doesn't delay while response will be ok . It means if you lost connection with db for some time, you got error log cycling.

Migrations are broken because of `->index('user_id')`

Cannot run migrations of a fresh database:

bash-5.1# php artisan migrate
Migrating: 2018_04_18_193554_create_botan_shortener_table
Migrated:  2018_04_18_193554_create_botan_shortener_table (73.51ms)
Migrating: 2018_04_18_193554_create_callback_query_table

   Illuminate\Database\QueryException

  SQLSTATE[42P07]: Duplicate table: 7 ERROR:  relation "user_id" already exists (SQL: create index "user_id" on "callback_query" ("user_id"))

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
    699โ–•         // If an exception occurs when attempting to run a query, we'll format the error
    700โ–•         // message to include the bindings with SQL, which will make this exception a
    701โ–•         // lot more helpful to the developer instead of just the database's errors.
    702โ–•         catch (Exception $e) {
  โžœ 703โ–•             throw new QueryException(
    704โ–•                 $query, $this->prepareBindings($bindings), $e
    705โ–•             );
    706โ–•         }
    707โ–•     }

      +9 vendor frames
  10  modules/Bot/database/migrations/2018_04_18_193554_create_callback_query_table.php:22
      Illuminate\Support\Facades\Facade::__callStatic("create")

      +22 vendor frames
  33  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Usage of ->index('user_id') function causes this issue. Index should have an unique name or is better to omit index name in this function call. Also there are a lot of ->index('chat_id') usages that also will cause the same trouble.

Problem with install package

Hi I try install package but I get this errors. Its fresh install only laravel and this package
This my composer.json
"require": {
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.54",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"longman/telegram-bot": "^0.74.0",
"php-telegram-bot/laravel": "^1.0"
},

Problem 1
- php-telegram-bot/laravel[1.1.0, ..., 1.1.1] require illuminate/database ^6.0 -> found illuminate/database[v6.0.0, ..., 6.x-dev] but these were not loaded, likely because it conflicts with another require.
- Root composer.json requires php-telegram-bot/laravel ^1.1 -> satisfiable by php-telegram-bot/laravel[1.1.0, 1.1.1].

Dependency conflict

I am developing locally to do PR so in the future. But I can not install the package due to dependency conflict. An update to php-telegram-bot/core is required.
Sorry for bad English.

  Problem 1
    - php-telegram-bot/laravel dev-dev requires longman/telegram-bot ^0.60 -> satisfiable by longman/telegram-bot[0.60.0].
    - Installation request for php-telegram-bot/laravel dev-dev -> satisfiable by php-telegram-bot/laravel[dev-dev].
    - Conclusion: remove monolog/monolog 2.0.0
    - Conclusion: don't install monolog/monolog 2.0.0
    - longman/telegram-bot 0.60.0 requires monolog/monolog ^1.24 -> satisfiable by monolog/monolog[1.24.0, 1.25.0, 1.25.1, 1.x-dev].
    - Can only install one of: monolog/monolog[1.24.0, 2.0.0].
    - Can only install one of: monolog/monolog[1.25.0, 2.0.0].
    - Can only install one of: monolog/monolog[1.25.1, 2.0.0].
    - Can only install one of: monolog/monolog[1.x-dev, 2.0.0].
    - Installation request for monolog/monolog (locked at 2.0.0) -> satisfiable by monolog/monolog[2.0.0].

Example of working Laravel

Hi there,

its been a while and there are no example on how to used it? Maybe We can get one example of working command? Thanks?

SQL Error [Column not found]

Hello,

when i use this script (version 1.1.1) and use the following code i get a DB error

Do i need to create users in the DB first or how does it works?

use PhpTelegramBot\Laravel\PhpTelegramBotContract;
class TelegramWebhookController extends Controller
{
    public function HandleWebhook(PhpTelegramBotContract $telegramBot)
    {
        $telegramBot->handle();

    }
2020-01-11 19:43:46] local.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'first_name' in 'field list' {"exception":"[object]
(Longman\\TelegramBot\\Exception\\TelegramException(code: 0): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'first_name' in 'field list' at 
/home/{USER}/domains/{DOMAIN}/laravel/vendor/longman/telegram-bot/src/DB.php:498)

i'm using laravel 6.10
Here are my settings

(
    [version:protected] => 0.60.0
    [api_key:protected] => *****
    [bot_username:protected] => *****
    [bot_id:protected] => *****
    [input:protected] => 
    [commands_paths:protected] => Array
        (
            [0] => /home/{user}/domains/{domain}/laravel/vendor/longman/telegram-bot/src/Commands/SystemCommands
        )

    [update:protected] => 
    [upload_path:protected] => 
    [download_path:protected] => 
    [mysql_enabled:protected] => 1
    [pdo:protected] => PDO Object
        (
        )

    [commands_config:protected] => Array
        (
        )

    [admins_list:protected] => Array
        (
        )

    [last_command_response:protected] => 
    [run_commands:protected] => 
    [getupdates_without_database:protected] => 
    [last_update_id:protected] => 
)

Not working in Lumen

Hi. I'm getting this error in Lumen:

Argument 1 passed to PhpTelegramBot\Laravel\PhpTelegramBotServiceProvider::PhpTelegramBot\Laravel{closure}() must be an instance of Illuminate\Contracts\Foundation\Application, instance of Laravel\Lumen\Application given, called in /vendor/illuminate/container/Container.php on line 776 in /vendor/php-telegram-bot/laravel/src/Laravel/PhpTelegramBotServiceProvider.php:55

How to work with this?

How to work with this? There is no instruction here on how the received data is processed during :fetch. How can I test the bot locally? What format are the requests? How to link a bot to a controller? How to use the created commands?

Error on instalation

I have created new Laravel 8 project. Nothing changed. Laravel is fresh. And run command:
composer require php-telegram-bot/laravel
it returns error like this:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires php-telegram-bot/laravel ^0.0.1 -> satisfiable by php-telegram-bot/laravel[0.0.1].
- php-telegram-bot/laravel 0.0.1 requires illuminate/database 5.* -> found illuminate/database[v5.0.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.
Problem 2
- symfony/deprecation-contracts v3.1.1 requires php >=8.1 -> your php version (8.0.20) does not satisfy that requirement.
- fakerphp/faker v1.19.0 requires symfony/deprecation-contracts ^2.2 || ^3.0 -> satisfiable by symfony/deprecation-contracts[v3.1.1].
- fakerphp/faker is locked to version v1.19.0 and an update of this package was not requested.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require php-telegram-bot/laravel:*" to figure out if any version is installable, or "composer require php-telegram-bot/laravel:^2.1" if you know which you need.

Telegram returned an invalid response!

Hello,
I am getting this error sometimes, I don't know what the problem is, I searched and saw some people was having the problem and some had reported it was due to blocked telegram in some countries but since my server was in germany and I also could make some requests and it only failed sometimes, for example I was not able to run /debug command and it always failed, but when I ran all the codes in debug command from an other route (not as a command) it worked fine! anyways to solve the problem I had to add the following code to Request.php file in send function before self::execute and it solved my problem but since I have edited core files I thought it would be good to report the problem Im having. I have been using the library on my laravel project for more than a year and didn't have this problem until yesterday and I haven't updated anything on my server. the code I added:
\Longman\TelegramBot\Request::setClient(new Client([ 'base_uri' => 'https://api.telegram.org', ]));

How to call DB::getPdo(); from the controller?

class DashboardController extends Controller
{
        $results = DB::selectChats([
            'groups'      => true,
            'supergroups' => true,
            'channels'    => true,
            'users'       => true,
            'text'        => null
        ]);

        dd($results); //false
}

dd($results); //false

install for Laravel 9

composer require php-telegram-bot/laravel

Print Errors:

Problem 1
    - Root composer.json requires php-telegram-bot/laravel ^0.0.1 -> satisfiable by php-telegram-bot/laravel[0.0.1].
    - php-telegram-bot/laravel 0.0.1 requires illuminate/database 5.* -> found illuminate/database[v5.0.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.

This repo may be install on new version Laravel 9 ?

Problem with Laravel 6.6.0

I have created a project with Laravel 6.6.0 and require the library with command composer require php-telegram-bot/laravel. The error occurs.

$ composer require php-telegram-bot/laravel
Using version ^1.1 for php-telegram-bot/laravel
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for monolog/monolog (locked at 2.0.1) -> satisfiable by monolog/monolog[2.0.1].
    - php-telegram-bot/laravel 1.1.0 requires longman/telegram-bot ^0.60 -> satisfiable by longman/telegram-bot[0.60.0].
    - php-telegram-bot/laravel 1.1.1 requires longman/telegram-bot ^0.60 -> satisfiable by longman/telegram-bot[0.60.0].
    - Conclusion: don't install longman/telegram-bot 0.60.0
    - Installation request for php-telegram-bot/laravel ^1.1 -> satisfiable by php-telegram-bot/laravel[1.1.0, 1.1.1].


Installation failed, reverting ./composer.json to its original content.

How to use this version?

Hello, i have a fresh setup of laravel 10 and php-telegram-bot/laravel

  • longman/telegram-bot (0.81.0):
  • php-telegram-bot/laravel (v2.1.0):

In .env i provided api_key and username.

In web.php i tried to use this:

use PhpTelegramBot\Laravel\PhpTelegramBotContract;
Route::post('/webhook', function (PhpTelegramBotContract $telegramBot) {
return $telegramBot->handle();
});

But i have an error.

ReflectionException: Class "PhpTelegramBot\Laravel\PhpTelegramBotContract" does not exist in file D:\OpenServer\domains\aml-bot\vendor\laravel\framework\src\Illuminate\Routing\ResolvesRouteDependencies.php on line 81

In previous version (laravel 9 and php-telegram-bot/laravel v 2.0.3) i don`t have such errors. Please, help me.

Multiple bots

Hello, I have been using the package for some time, and now I want to add more bots, like I want to create new console command for another bot which will have its own fetch loop, any idea?

Update README and improve setup process

We should test a clean setup with this package and bring everything up to date.

The readme should explain the needed steps and additionally the optional steps and should explicitly mark them as optional including an explanation why you could need it in special circumstances.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.