irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Home Page:https://telegram-bot-sdk.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return value of Telegram\Bot\Commands\Command::getName() must be of the type string, null returned

tayyabbashir2224 opened this issue · comments

I am creating a command to check userinfo but i am getting error,
[2023-04-19 18:04:39] local.ERROR: Return value of Telegram\Bot\Commands\Command::getName() must be of the type string, null returned {"exception":"[object] (TypeError(code: 0): Return value of Telegram\Bot\Commands\Command::getName() must be of the type string, null returned at /membri/mybbpk/vendor/irazasyed/telegram-bot-sdk/src/Commands/Command.php:50)
[stacktrace]
here is my code
UserInfoCommand.php
`<?php

namespace App\Telegram\Commands;

use Telegram\Bot\Commands\Command;
use Telegram;

class UserInfoCommand extends Command
{
protected $signature = 'userinfo {username}';

protected $description = 'Get user information from Telegram';

public function handle()
{
//    $telegram = new Telegram(config('telegram.bot_token'));

    // Get the username from the command argument.
    $username = $arguments['username'];

    // Get the user's profile photos.
    $photos = $telegram->getUserProfilePhotos([
        'user_id' => $username,
        'limit' => 1,
    ]);

    // Get the user's chat member info.
    $chat_id = $this->getUpdate()->getMessage()->getChat()->getId();
    $member = $telegram->getChatMember([
        'chat_id' => $chat_id,
        'user_id' => $username,
    ]);

    // Construct the user info message.
    $message = "User info for @$username:\n\n";
    $message .= "Status: " . $member->getStatus() . "\n";
    $message .= "First name: " . $member->getUser()->getFirstName() . "\n";
    $message .= "Last name: " . $member->getUser()->getLastName() . "\n";
    $message .= "Profile photo: " . ($photos->getTotalCount() > 0 ? $photos->getPhotos()[0][0]->getFileId() : "N/A");

    // Send the user info message to the user.
    $telegram->sendMessage([
        'chat_id' => $chat_id,
        'text' => $message,
    ]);
}

}
`

Read the error message, there is no $name property in your command and instead you have $signature which is Laravel's property. Read the latest docs for commands.