Skip to content

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

Open
@lipengxiang8888

Description

@lipengxiang8888
    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();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions