Giter Club home page Giter Club logo

laravel's Introduction

LaravelTelegramBot

Latest Version on Packagist Total Downloads

Installation

Install this package through Composer. Run this command in your project's terminal:

composer require php-telegram-bot/laravel

Execute the following command to publish the folder structure to your Laravel application:

php artisan telegram:publish

This also includes a dummy /start command to give you a quick start.

Since we're using the database part of php-telegram-bot you should run the migrations so the database schema gets installed:

php artisan migrate

And add the following lines to your .env file:

TELEGRAM_API_TOKEN=
TELEGRAM_BOT_USERNAME=
TELEGRAM_API_URL=
TELEGRAM_ADMINS=

TELEGRAM_API_TOKEN and TELEGRAM_BOT_USERNAME should be filled with the corresponding data from @BotFather

TELEGRAM_API_URL is optional and can be filled with the URL to your custom Bot API Server if you want to use one.

TELEGRAM_ADMINS is optional and a comma-separated list of Telegram User IDs that gets passed to the enableAdmins command of php-telegram-bot to enable admin commands for those users.

After that you can run php artisan telegram:set-webhook if your development server is reachable from the outside or you're using a custom bot api server.

Or php artisan telegram:fetch to start fetching your updates via polling.

⚠️ Be aware that you have to cancel and restart the telegram:fetch command, if you change your code.

Usage

For further basic configuration of this Laravel package you do not need to create any configuration files.

Artisan terminal commands for the Webhook usage (remember, that you need an HTTPS server for it):

# Use this method to specify a url and receive incoming updates via an outgoing webhook
php artisan telegram:set-webhook
# List of available options: 
# --d|drop-pending-updates : Drop all pending updates
# --a|all-update-types : Explicitly allow all updates (including "chat_member")
# --allowed-updates= : Define allowed updates (comma-seperated)

# Use this method to remove webhook integration if you decide to switch back to getUpdates
php artisan telegram:delete-webhook
# List of available options:
# --d|drop-pending-updates : Pass to drop all pending updates

Artisan terminal commands for the Telegram getUpdates method:

# Fetches Telegram updates periodically
php artisan telegram:fetch 
# List of available options:
# --a|all-update-types : Explicitly allow all updates (including "chat_member")
# --allowed-updates= : Define allowed updates (comma-seperated)

Artisan terminal command for Telegram Server logging out:

# Sends a logout to the currently registered Telegram Server
php artisan telegram:logout

Artisan terminal command for closing Telegram Server:

# Sends a close to the currently registered Telegram Server
php artisan telegram:close

Artisan terminal command for publishing Telegram command folder structure in your project:

# Publishes folder structure for Telegram Commands
# Default StartCommand class will be created
php artisan telegram:publish

Artisan terminal command for creating new Telegram command class in your project:

# Create a new Telegram Bot Command class
# e.g. php artisan make:telegram-command Menu --> will make User command class MenuCommand 
# e.g. php artisan make:telegram-command Genericmessage --system --> will make System command class GenericmessageCommand
php artisan make:telegram-command
# List of available options:
# name : Name of the Telegram Command
# --a|admin : Generate a AdminCommand
# --s|system : Generate a SystemCommand
# Without admin or system option default User command will be created

Credits

License

Please see the license file for more information.

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  avatar

laravel's Issues

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

Database issues

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

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 ?

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].

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].

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?

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

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.

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.

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?

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', ]));

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] => 
)

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.

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?

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?

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.

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.

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..

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.

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.