php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.88k stars 955 forks source link

Class 'Longman\TelegramBot\Commands\SystemCommand' not found #1080

Closed farmaworld closed 4 years ago

farmaworld commented 4 years ago
<?php
/**
 * This file is part of the TelegramBot package.
 *
 * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Longman\TelegramBot\Commands\SystemCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;

/**
 * Start command
 *
 * Gets executed when a user first starts using the bot.
 */
class StartCommand extends SystemCommand
{
    /**
     * @var string
     */
    protected $name = 'start';

    /**
     * @var string
     */
    protected $description = 'Start command';

    /**
     * @var string
     */
    protected $usage = '/start';

    /**
     * @var string
     */
    protected $version = '1.1.0';

    /**
     * @var bool
     */
    protected $private_only = true;

    /**
     * Command execute method
     *
     * @return \Longman\TelegramBot\Entities\ServerResponse
     * @throws \Longman\TelegramBot\Exception\TelegramException
     */
public function execute()
{
    $message = $this->getMessage();
    $chat_id = $message->getChat()->getId();
    $user_id = $message->getFrom()->getId();
    $username = $message->getFrom()->getUsername();

    $result = Request::sendMessage([
        'chat_id' => $chat_id,
        'text'    => "Hello {$username}",
    ]);

    return $result;
}
}

i don't understund why i have this error thanks

noplanman commented 4 years ago

What version of the bot are you using? Also, did you install it correctly with composer and include the autoloader?

farmaworld commented 4 years ago

i installed with composer, i don,t have the version.. where i search the version?

noplanman commented 4 years ago

You can see the version in vendor/longman/telegram-bot/src/Telegram.php file, a variable called $version

farmaworld commented 4 years ago

0.62.0

farmaworld commented 4 years ago

vendor ------------------composer ____------------------guzzlettp ____------------------longman---------------telegram-bot-----src ____------------------psr ____------------------ralouphie ____------------------symphony ____-------------------autoload.php my_PHP_file

noplanman commented 4 years ago

Could you share your my_PHP_file file please? Remember to remove your API Key, bot username and any other credentials!

farmaworld commented 4 years ago

in my path dir where is vendor i have: hook.php manager.php GetUpadatesCLI.php set.php unset.php GetUpdates work fine and also set and unset php file now in this direcotory i want create my file to send any message to the bot but i don't undesrtund how make this file please if you have any example thanks

farmaworld commented 4 years ago
<?php

//Composer Loader
$loader = (require __DIR__ . '/vendor/autoload.php');
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/';
//$credentials = array('host'=>'localhost', 'user'=>'dbuser', 'password'=>'dbpass', 'database'=>'dbname');
try {
    // create Telegram API object
    $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);

// ......my code................

    $telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
    // log telegram errors
    // echo $e;
}
noplanman commented 4 years ago

@farmaworld Have you set the webhook URL in set.php correctly, to point to your hook.php file? That is important, so that the webhook called by Telegram points to the correct hook.

You can also get the status of your webhook with the getWebhookInfo method, to check if there are any errors: https://core.telegram.org/bots/api#getwebhookinfo

farmaworld commented 4 years ago

i connect all file whit database and work fine. everythink i write in the chat box i save in the database. i don't understund how send message? i inizialize a new telegram object new Telegram($API_KEY, $BOT_NAME); but i don't have a chat_it

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

To send a message (or photo or whatever) you must have a chat ID.

Then the code you have above will work :+1:

You can also simplify it a bit:

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