tg-bot-api / bot-api-base Goto Github PK
View Code? Open in Web Editor NEWClear and simple Telegram bot API
License: MIT License
Clear and simple Telegram bot API
License: MIT License
When I'm building a new message via SendMessageMethod
I'm passing an entities list that cannot be normalized by BotApiNormalizer
. It just ignores them and still appears as an array instead of encoded json.
$buttonA = new InlineKeyboardButtonType();
$buttonA->callbackData = 'a';
$buttonA->text = 'A';
$buttonB = new InlineKeyboardButtonType();
$buttonB->callbackData = 'b';
$buttonB->text = 'B';
$inlineKeyboard = new InlineKeyboardMarkupType();
$inlineKeyboard->inlineKeyboard = [
[$buttonA, $buttonB],
];
$messageEntity = new MessageEntityType();
$messageEntity->type = MessageEntityType::TYPE_TEXT_LINK;
$messageEntity->offset = 58;
$messageEntity->length = 23;
$messageEntity->url = 'https://google.com';
$sendMessage = new SendMessageMethod();
$sendMessage->chatId = '111222333';
$sendMessage->text = 'some text';
$sendMessage->replyMarkup = $inlineKeyboard;
$sendMessage->entities = [$messageEntity];
$this->botApi->send($sendMessage);
$normalizer = new BotApiNormalizer();
$normalizedRequest = $normalizer->normalize($sendMessage); // entities are not normalized at this step
And this method cannot be sent by the api client:
[2022-04-23 17:33:43] app.ERROR: Array to string conversion in /.../tg-bot-api/bot-api-base/src/ApiClient.php:106
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
We need to create Symfony Flex recipe for this library.
It will easy installation and easy configuration.
I tray to get some info bot Telegram don't reply support tickets!
Can you help me with Telegram. so that I am sent in the right direction.
I work for a government organization and we have a weekly exercise, now I would like to simplify this with, for example, a poll or something else where if someone responds to that I get a feedback via the telegram API.
I want to use PHP for this but see many options on the Telegram website https://core.telegram.org/bots/samples#php but now which one is and is not suitable for this and there is a little explanation somewhere how to find it tackles this?
https://telegram.org/blog/polls-2-0-vmq
Greetings Theo
Provide a detailed description of the change or addition you are proposing.
Make it clear if the issue is a bug, an enhancement or just a question.
Why is this change important to you? How would you use it?
How can it benefit other users?
Not obligatory, but suggest an idea for implementing addition or change.
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
after executing following line:
BotApi::edit(EditMessageMediaMethod::create($chatId, $messageId, InputMediaVideoType::create($url), array('replyMarkup'=>$someInlineKeyboardMarkup)));
exception throws : Bad Request: can't parse InputMedia: Can't parse media JSON object
and PHP Notice : Array to string conversion in /foo/vendor/tg-bot-api/bot-api-base/src/ApiClient.php on line 106
which is ApiClient::createStreamBody() method
I tried to send an invoice, but got the notice:
PHP Notice: Array to string conversion in .../src/ApiClient.php on line 106
And receive unsuccessful response from telegram.
Example
$invoice = SendInvoiceMethod::create(
$telegramAccount->getTelegramId(),
'title',
'description',
'payload',
'token',
'startParameter',
'USD',
[LabeledPriceType::create('label', 234)]
);
$bot->sendInvoice($invoice);
When ApiClient try to createStreamBody it cast value (array) as string:
foreach ($request->getData() as $name => $value) {
// todo [GreenPlugin] fix type cast and replace it to normalizer
$stream .= $this->createDataStream($boundary, $name, (string) $value);
}
It toolz
When I tried to install using composer, I got this error message :
[InvalidArgumentException]
Could not find a matching version of package greenplugin/telegram-bot-api.
Check the package spelling, your version constraint and that the package is
available in a stability which matches your minimum-stability (stable).
Installation does not work because there are no stable version. Please make a release so it can be used.
We need to replace ci.
composer require tg-bot-api/bot-api-base
gives error
Problem 1
- Conclusion: remove phpdocumentor/reflection-common 2.2.0
- Conclusion: don't install phpdocumentor/reflection-common 2.2.0
- phpdocumentor/reflection-docblock 4.3.0 requires phpdocumentor/reflection-common ^1.0.0 -> satisfiable by phpdocumentor/reflection-common[1.0, 1.0.1].
- phpdocumentor/reflection-docblock 4.3.1 requires phpdocumentor/reflection-common ^1.0.0 -> satisfiable by phpdocumentor/reflection-common[1.0, 1.0.1].
- Can only install one of: phpdocumentor/reflection-common[1.0, 2.2.0].
- Can only install one of: phpdocumentor/reflection-common[1.0.1, 2.2.0].
- Installation request for phpdocumentor/reflection-common (locked at 2.2.0) -> satisfiable by phpdocumentor/reflection-common[2.2.0].
- Installation request for tg-bot-api/bot-api-base ^1.6 -> satisfiable by tg-bot-api/bot-api-base[1.6.0].
- Conclusion: don't install phpdocumentor/reflection-docblock 5.1.0|install phpdocumentor/reflection-docblock 4.3.0|install phpdocumentor/reflection-docblock 4.3.1
- Conclusion: remove phpdocumentor/reflection-docblock 5.1.0|install phpdocumentor/reflection-docblock 4.3.0|install phpdocumentor/reflection-docblock 4.3.1
- tg-bot-api/bot-api-base 1.6.0 requires phpdocumentor/reflection-docblock ^4.3 -> satisfiable by phpdocumentor/reflection-docblock[4.3.0, 4.3.1, 4.3.2, 4.3.3, 4.3.4].
- Can only install one of: phpdocumentor/reflection-docblock[4.3.2, 5.1.0].
- Can only install one of: phpdocumentor/reflection-docblock[4.3.3, 5.1.0].
- Can only install one of: phpdocumentor/reflection-docblock[4.3.4, 5.1.0].
- Installation request for phpdocumentor/reflection-docblock (locked at 5.1.0) -> satisfiable by phpdocumentor/reflection-docblock[5.1.0].
Also tried to install version 1.5.0, but faced the same package conflict error.
When sending SendPollMethod, there is no poll info in response. I suppose it can be achieved by adding the following property to the MessageType class:
/**
* @var PollType
*/
public $poll;
I rely on a quick fix for this. Thank you in advance.
Need to update library to support Bot api version 5 (November 4, 2020)
Telegram released new version of bot api. Need to update the library to support their changes.
If you using Symfony flex please give feedback about our recipe in this issue.
In internal classes and in tests phpdoc is not pretty (like this).
Please improve it and write input/output types.
When I'm sends poll I receive this error. It's because wrong normalization in request.
In ApiClient.php line 128:
Notice: Array to string conversion
We need to add new normalizer like this
I'll fix it tonight
Provide a detailed description of the change or addition you are proposing.
Make it clear if the issue is a bug, an enhancement or just a question.
Why is this change important to you? How would you use it?
How can it benefit other users?
Not obligatory, but suggest an idea for implementing addition or change.
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
Telegram ожидает в поле reply_markup json с ключом inline_keyboard и значением в виде массива массивов, но после нормализации в reply_markup остается json c ключом inline_keyboard значения которого массив объектов
PHP 7.4.2
Slim 4.7
I have servers in Russia but Telegram servers are blocked.
Is there any good way to set in config proxy path? Or i need to patch/extend source code of this library?
And how exactly? Thanks.
Could not find package tg-bot-api/bot-api-base at any version matching your PHP version 7.0.10.0
Do you support PHP7?
Need to implement all new features
@BotFather
.source: https://core.telegram.org/bots/api#march-30-2020
We want to change minimal version php to 7.4 in our package version 2. It's make all methods and types more strict and clean.
In this thread we will collect suggestions for version 2.
This update will not be compatible with version 1.x, so you can suggest any reasonable improvement.
Ofcourse we will support both versions (1.x and 2.x) and update it according telegram bot api changes.
When the user which seends a message to the bot has a username, there will be an exception thrown while processing webhook updates.
ReflectionException: Property TgBotApi\BotApiBase\Type\ChatType::$username does not exist
If i remove my username in telegram, the message get processed normally.
After a quick test, it seems to be sufficient to simply add a property called $username in the ChatType class.
PHP 7.3 with lando.dev
BotApiInterface::getUserProfilePhotos(GetUserProfilePhotosMethod::create($id));
was throw this error:
Uncaught Error: Cannot use object of type stdClass as array
In UserProfilePhotosNormalizer.php line 54:
Cannot use object of type stdClass as array
Please replace line 54 of UserProfilePhotosNormalizer to $data->photos = $serializer->denormalize($data->photos, PhotoSizeType::class . '[][]');
$response = $bot->send(
\TgBotApi\BotApiBase\Method\SendMessageMethod::create($userId, 'Hi2')
);
$prevMessageId = $response->messageId;
$response = $bot->edit(
\TgBotApi\BotApiBase\Method\EditMessageTextMethod::create($userId, $prevMessageId, 'Hello')
);
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
Argument 3 passed to TgBotApi\BotApiBase\ApiClient::createDataStream() must be of the type string, int given
Need to implement all new features:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.