Error in /data/data/com.termux/files/home/vendor/telegram-bot/api/src/BotApi.php on line 329 when running Telegram bot with php

38 views Asked by At

I want to create a Telegram bot using PHP, but it gives me an error in termux Fatal error: Uncaught TelegramBot\Api\InvalidJsonException: Syntax error in /data/data/com.termux/files/home/vendor/telegram-bot/api/src/BotApi.php:329 Stack trace: #0 /data/data/com.termux/files/home/vendor/telegram-bot/api/src/Client.php(169): TelegramBot\Api\BotApi::jsonValidate('', true) #1 /data/data/com.termux/files/home/bot.php(23): TelegramBot\Api\Client->run() #2 {main} thrown in /data/data/com.termux/files/home/vendor/telegram-bot/api/src/BotApi.php on line 329

I made this code

<?php

require_once 'vendor/autoload.php';

use TelegramBot\Api\Client;
use TelegramBot\Api\Types\Message;
$token = 'my token';

$bot = new Client($token);

$bot->on(function (Message $message) use ($bot) {
    $chatId = $message->getChat()->getId();
    $text = $message->getText();

    
    $bot->sendMessage($chatId, "hi: $text");
}, function () {
    return true;
});

$bot->run();

0

There are 0 answers