Skip to content
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

What is this error for keyboard ? #98

Open
sallsabil opened this issue Nov 29, 2018 · 8 comments
Open

What is this error for keyboard ? #98

sallsabil opened this issue Nov 29, 2018 · 8 comments

Comments

@sallsabil
Copy link

sallsabil commented Nov 29, 2018

unreal4u/telegram-api v3.4.1 A complete Telegram ...

PHP Version: 7.2

Output:

[Thu Nov 29 07:37:28.746106 2018] [php7:error] [pid 20800] [client 138.201.36.31:46950] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to unreal4u\\TelegramAPI\\Abstracts\\TelegramMethods::formatReplyMarkup() must be an instance of unreal4u\\TelegramAPI\\Abstracts\\TelegramTypes, string given, called in /root/vendor/unreal4u/telegram-api/src/Abstracts/TelegramMethods.php on line 55 and defined in /root/vendor/unreal4u/telegram-api/src/Abstracts/TelegramMethods.php:124\nStack trace:\n#0 /root/vendor/unreal4u/telegram-api/src/Abstracts/TelegramMethods.php(55): unreal4u\\TelegramAPI\\Abstracts\\TelegramMethods->formatReplyMarkup('{"keyboard":[[{...')\n#1 /root/vendor/unreal4u/telegram-api/src/InternalFunctionality/PostOptionsConstructor.php(82): unreal4u\\TelegramAPI\\Abstracts\\TelegramMethods->performSpecialConditions()\n#2 /root/vendor/unreal4u/telegram-api/src/InternalFunctionality/PostOptionsConstructor.php(50): unreal4u\\TelegramAPI\\InternalFunctionality\\PostOptionsConstructor->checkIsMultipart(Object(unreal4u\\TelegramAPI\\Telegram\\Methods\\SendMessage))\n#3 /root/vendor/unreal4u/telegram-api/src/TgLog.php(88): unreal4u\\ in /root/vendor/unreal4u/telegram-api/src/Abstracts/TelegramMethods.php on line 124

When I use this code:

	$sendMessage->chat_id = $chatId;
	$sendMessage->text = "<code>◀️دکمه های اصلی▶️</code>";
	$sendMessage->parse_mode = 'HTML';
	$sendMessage->reply_markup = new \unreal4u\TelegramAPI\Telegram\Types\ReplyKeyboardMarkup();
	$sendMessage->reply_markup->resize_keyboard = true;
	
	$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
	$keyboardButton->text = '🎤یک';
	$sendMessage->reply_markup->keyboard[0][] = $keyboardButton;
	$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
	$keyboardButton->text = '⛽️دو';
	$sendMessage->reply_markup->keyboard[0][] = $keyboardButton;
	$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
	$keyboardButton->text = '➕سه';
	$sendMessage->reply_markup->keyboard[1][] = $keyboardButton;
	$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
	$keyboardButton->text = '📩چهار';
	$sendMessage->reply_markup->keyboard[1][] = $keyboardButton;
	$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
	$keyboardButton->text = '📘پنج';
	$sendMessage->reply_markup->keyboard[2][] = $keyboardButton;
	$tgLog->performApiRequest($sendMessage);
	$loop->run();

I face the Fatal error above.
What is wrong ?

@unreal4u
Copy link
Owner

I think this may be an error in the code. I'll look into it tonight ;)

Thanks for reporting this!

@unreal4u unreal4u self-assigned this Nov 29, 2018
@sallsabil
Copy link
Author

Hey
I'm waiting

@sallsabil
Copy link
Author

Is the error because of PHP 7.2 ?

@unreal4u
Copy link
Owner

unreal4u commented Dec 3, 2018

Hi, I tested your code and it worked in one go.

image

This isn't a problem of PHP either, as this message was sent using:
PHP 7.2.10 (cli) (built: Sep 15 2018 02:33:49)

I don't know how else to try to reproduce it, can you provide some more context? Maybe publishing the entire script?

@unreal4u
Copy link
Owner

unreal4u commented Dec 3, 2018

PD: This was the script I used:

<?php

declare(strict_types = 1);

include __DIR__.'/basics.php';

use React\EventLoop\Factory;
use unreal4u\TelegramAPI\HttpClientRequestHandler;
use unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
use unreal4u\TelegramAPI\TgLog;

$loop = Factory::create();
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));

$sendMessage = new SendMessage();
$sendMessage->chat_id = A_USER_CHAT_ID;
//$sendMessage->chat_id = $chatId;
$sendMessage->text = "<code>◀️دکمه های اصلی▶️</code>";
$sendMessage->parse_mode = 'HTML';
$sendMessage->reply_markup = new \unreal4u\TelegramAPI\Telegram\Types\ReplyKeyboardMarkup();
$sendMessage->reply_markup->resize_keyboard = true;

$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
$keyboardButton->text = '🎤یک';
$sendMessage->reply_markup->keyboard[0][] = $keyboardButton;
$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
$keyboardButton->text = '⛽️دو';
$sendMessage->reply_markup->keyboard[0][] = $keyboardButton;
$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
$keyboardButton->text = '➕سه';
$sendMessage->reply_markup->keyboard[1][] = $keyboardButton;
$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
$keyboardButton->text = '📩چهار';
$sendMessage->reply_markup->keyboard[1][] = $keyboardButton;
$keyboardButton = new \unreal4u\TelegramAPI\Telegram\Types\KeyboardButton();
$keyboardButton->text = '📘پنج';
$sendMessage->reply_markup->keyboard[2][] = $keyboardButton;

$tgLog->performApiRequest($sendMessage);
$promise = $tgLog->performApiRequest($sendMessage);

$promise->then(
    function ($response) {
        echo '<pre>';
        var_dump($response);
        echo '</pre>';
    },
    function (\Exception $exception) {
        // Onoes, an exception occurred...
        echo 'Exception ' . get_class($exception) . ' caught, message: ' . $exception->getMessage();
    }
);

$loop->run();

It is based on this one: https://github.com/unreal4u/telegram-api/blob/master/examples/send-message-with-inlinekeyboard.php

But with your modifications in it, the only thing I did replace was the chatId due to obvious reasons :)

@sallsabil
Copy link
Author

sallsabil commented Dec 4, 2018

Add this after the above code:

if($chatId == A_USER_CHAT_ID) {
	$sendMessage->chat_id = A_USER_CHAT_ID;
	$sendMessage->text = '%D9%86%D9%87%0A%D8%AF%D8%A7%D8%B1%DB%8C%D9%85+%D8%B3%D8%B1%D9%88%D8%B1%D8%B4';
	$sendMessage->parse_mode = 'HTML';
	$tgLog->performApiRequest($sendMessage);
	$loop->run();
}

I removed this my problem solved!

I discovered If you send message after a message that has keyboard you face that fatal error.

@unreal4u
Copy link
Owner

unreal4u commented Dec 4, 2018

I think that if you initialize a new object you won't have the issue:

if($chatId == A_USER_CHAT_ID) {
    $sendMessage = new SendMessage();
    $sendMessage->chat_id = A_USER_CHAT_ID;
    $sendMessage->text = '%D9%86%D9%87%0A%D8%AF%D8%A7%D8%B1%DB%8C%D9%85+%D8%B3%D8%B1%D9%88%D8%B1%D8%B4';
    $sendMessage->parse_mode = 'HTML';
    $tgLog->performApiRequest($sendMessage);
    $loop->run();
}

@sallsabil
Copy link
Author

No difference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants