YaKotikTvoy
@YaKotikTvoy
Стьюдик

Как правильно настроить телеграмм-бота?

Старался делать согласно этим инструкциям.
<?php

/**
 * This file is part of the PHP Telegram Bot example-bot package.
 * https://github.com/php-telegram-bot/example-bot/
 *
 * (c) PHP Telegram Bot Team
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * This file contains all the configuration options for the PHP Telegram Bot.
 *
 * It is based on the configuration array of the PHP Telegram Bot Manager project.
 *
 * Simply adjust all the values that you need and extend where necessary.
 *
 * Options marked as [Manager Only] are only required if you use `manager.php`.
 *
 * For a full list of all options, check the Manager Readme:
 * https://github.com/php-telegram-bot/telegram-bot-manager#set-extra-bot-parameters
 */

return [
    // Add you bot's API key and name
    'api_key'      => 'токен бота', // ВОТ ТУТ ТОЛЬКО API(токен) вводил и всё, как правильно запустить бота?
    'bot_username' => 'Test8987', // Without "@" 

    // [Manager Only] Secret key required to access the webhook
   'secret'       => 'Hytsad8927uywqT7u',

    // When using the getUpdates method, this can be commented out
    'webhook'      => [
        'url' => 'http://localhost/example-bot/manager.php?',
        // Use self-signed certificate
        // 'certificate'     => __DIR__ . '/path/to/your/certificate.crt',
        // Limit maximum number of connections
        // 'max_connections' => 5,
    ],

    // All command related configs go here
    'commands'     => [
        // Define all paths for your custom commands
        // DO NOT PUT THE COMMAND FOLDER THERE. IT WILL NOT WORK. 
        // Copy each needed Commandfile into the CustomCommand folder and uncommend the Line 49 below
        'paths'   => [
            __DIR__ . '/CustomCommands',
        ],
        // Here you can set any command-specific parameters
        'configs' => [
            // - Google geocode/timezone API key for /date command (see DateCommand.php)
            // 'date'    => ['google_api_key' => 'your_google_api_key_here'],
            // - OpenWeatherMap.org API key for /weather command (see WeatherCommand.php)
            // 'weather' => ['owm_api_key' => 'your_owm_api_key_here'],
            // - Payment Provider Token for /payment command (see Payments/PaymentCommand.php)
            // 'payment' => ['payment_provider_token' => 'your_payment_provider_token_here'],
        ],
    ],

    // Define all IDs of admin users
    'admins'       => [
        // 123,
    ],

    // Enter your MySQL database credentials
    // 'mysql'        => [
    //     'host'     => '127.0.0.1',
    //     'user'     => 'root',
    //     'password' => 'root',
    //     'database' => 'telegram_bot',
    // ],

    // Logging (Debug, Error and Raw Updates)
     'logging'  => [
         'debug'  => __DIR__ . '/php-telegram-bot-debug.log',
         'error'  => __DIR__ . '/php-telegram-bot-error.log',
         'update' => __DIR__ . '/php-telegram-bot-update.log',
     ],

    // Set custom Upload and Download paths
    'paths'        => [
        'download' => __DIR__ . '/Download',
        'upload'   => __DIR__ . '/Upload',
    ],

    // Requests Limiter (tries to prevent reaching Telegram API limits)
    'limiter'      => [
        'enabled' => true,
    ],
];

Выдаёт вот это
[Thu Jun 29 23:32:34.499230 2023] [php:error] [pid 6632:tid 1212] [client ::1:52201] PHP Fatal error:  Uncaught TelegramBot\\TelegramBotManager\\Exception\\InvalidAccessException: Invalid access in D:\\php\\localhost\\example-bot\\vendor\\php-telegram-bot\\telegram-bot-manager\\src\\BotManager.php:124\nStack trace:\n#0 D:\\php\\localhost\\example-bot\\vendor\\php-telegram-bot\\telegram-bot-manager\\src\\BotManager.php(90): TelegramBot\\TelegramBotManager\\BotManager->validateSecret()\n#1 D:\\php\\localhost\\example-bot\\manager.php(31): TelegramBot\\TelegramBotManager\\BotManager->run()\n#2 {main}\n  thrown in D:\\php\\localhost\\example-bot\\vendor\\php-telegram-bot\\telegram-bot-manager\\src\\BotManager.php on line 124

Как запустить этот скрипт, совершенно не могу понять, совершенно не понимаю, как настроить бота. Композером все зависимости скачал.
  • Вопрос задан
  • 237 просмотров
Пригласить эксперта
Ответы на вопрос 3
@nozzy
Symfony, Laravel, SQL
Зачем тебе bot manager из этой библиотеки?
Создай новый проект и сделай по инструкции
https://github.com/php-telegram-bot/core#create-yo...
Ответ написан
Комментировать
nokimaro
@nokimaro
Меня невозможно остановить, если я смогу начать.
InvalidAccessException говорит о том что не правильно указан токен
Ответ написан
Комментировать
Какой функционал нужен от телеграм бота?
Я забил на все библиотеки, которые есть и сделал свою на Guzzle и ORM (PHP).
На самом деле все просто — создаешь бота, активируешь работу через webhook.
Webhook присылает данные в POST, их дампишь и отправляешь ответные запросы через Telegram API.
Времени на изучение уйдет час-два. Намного быстрее, чем ковыряться в чужих библиотеках.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы