Skip to content

The robot sends messages normally, but there is no data in the database #1488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lipengxiang8888 opened this issue Apr 17, 2025 · 0 comments
Labels

Comments

@lipengxiang8888
Copy link

    try {
        // Bot API key and username
        $bot_api_key  = 'xxx';
        $bot_username = 'xxx';
        
        // Create Telegram API object
        $telegram = new Telegram($bot_api_key, $bot_username);
        
        // 设置 MySQL
        $mysql_credentials = [
            'host'     => env('database.hostname'),
            'port'     => 3306, // optional
            'user'     => env('database.username'),
            'password' => env('database.password'),
            'database' => env('database.database'),
        ];
    
        // Enable MySQL
        // $telegram->enableMySql($mysql_credentials, 'kf_' . $bot_username . '_');
        // echo "MySQL 是否启用: " . ($telegram->isDbEnabled() ? "是" : "否");
        // 发送消息
        $result = Request::sendMessage([
            'chat_id' => 'xxxx',
            'text'    => 'Your utf8 text 😜 ...',
        ]);
        
        $telegram->enableAdmin('6264203299');
    
        // 检查消息发送结果
        if ($result->isOk()) {
             Log::write('Message sent successfully: ' . $result->getDescription());
        } else {
             Log::write('Failed to send message: ' . $result->getDescription());
        }
    
        // 处理 Telegram webhook 请求
        $telegram->handleGetUpdates();
    
    } catch (Longman\TelegramBot\Exception\TelegramException $e) {
        // 记录 Telegram 错误
        Log::write('TelegramException错误:'.$e->getMessage());
        echo 'Error: ' . $e->getMessage();
    } catch (Exception $e) {
        // 记录其他错误
        Log::write('其他错误:'.$e->getMessage());
        echo 'Error: ' . $e->getMessage();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant