MadelineProtoDocs/docs/docs/INLINE_BUTTONS.md

56 lines
1.5 KiB
Markdown
Raw Normal View History

2018-04-11 14:17:45 +02:00
---
title: Inline buttons
description: You can easily click inline buttons using MadelineProto, just access the correct button:
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
---
2018-04-01 13:19:25 +02:00
# Inline buttons
You can easily click inline buttons using MadelineProto, just access the correct button:
```php
class EventHandler extends \danog\MadelineProto\EventHandler
{
public function onUpdateNewChannelMessage($update)
{
$this->onUpdateNewMessage($update);
}
public function onUpdateNewMessage($update)
{
if (isset($update['message']['out']) && $update['message']['out']) {
return;
}
if (isset($update['message']['reply_markup']['rows'])) {
foreach ($update['message']['reply_markup']['rows'] as $row) {
foreach ($row['buttons'] as $button) {
$button->click();
}
}
}
}
}
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->start();
$MadelineProto->setEventHandler('\EventHandler');
$MadelineProto->loop();
```
This peice of code will automatically click all buttons in all keyboards sent in any chat.
You can then access properties of `$button` (they vary depending on the [type of button](https://docs.madelineproto.xyz/API_docs/types/KeyboardButton.html)):
```php
$text = $button['text'];
```
And click them:
```php
$button->click();
```
2018-04-01 13:55:07 +02:00
<a href="https://docs.madelineproto.xyz/docs/CALLS.html">Next section</a>