A
A
Andrey Kotosin2021-01-20 08:37:20
PHP
Andrey Kotosin, 2021-01-20 08:37:20

How to create alert for telegram bot?

I am creating a telegram bot that counts the characters in the text.
In response, I want to send an inline keyboard with text on the button "Number of characters ***" It is
necessary to make it so that when the user clicks on the button, an alert pops up where it says how many characters and how many hashtags are in the text. Tell me how this can be implemented?

I use the library https://github.com/TelegramBot/Api
PS> I just started developing, I have very few skills, I didn’t google it (

Here is an example of how I want it to look.
6007c2a355bb9224826586.jpeg

An example is shown on github

$keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup(
            [
                [
                    ['text' => 'link', 'url' => 'https://core.telegram.org']
                ]
            ]
        );
        
$bot->sendMessage($chatId, $messageText, null, false, null, $keyboard);


But I can't figure out how to change the link to the alert.

UDP: >
Here is my bot application code. Now I display the button without any events, but I want that when I click in the alert, the extended text I need appears

require_once "vendor/autoload.php";

$token = "TOKEN";
$bot = new \TelegramBot\Api\Client($token);
// команда для start
$bot->command('start', function ($message) use ($bot) {
    $answer = 'Добро пожаловать в бота!

Просто пришлите мне текст с несколькими абзацами! Затем ответ бота скопируйте и вставьте в Instagram!

Обратите внимание, что Ваш текст должен быть разделен на обычные абзацы (отступы), то есть между абзацами должна быть пустая строка!';
    $bot->sendMessage($message->getChat()->getId(), $answer);
});
// Повторяет за мной
$bot->on(function (\TelegramBot\Api\Types\Update $update) use ($bot) {
    $message = $update->getMessage(); // Получаем текст сообщения
    $id = $message->getChat()->getId(); // Получаем id чата
    $messageText = str_replace(array("\r\n\r\n", "\r\r", "\n\n"), "\r\n".'⠀'."\r\n", $message->getText()); // Заменяем символы переноса на невидимый пробел
    if (iconv_strlen($messageText,'UTF-8') <= 2200) {
        $bot->sendMessage($id, $messageText); // отправляем сообщение
        $keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup(
            [
                [
                    ['callback_data' => 'start', 'text' => ' '.iconv_strlen($messageText,'UTF-8')." из 2200"]
                ]
            ]
        );
        $bot->sendMessage($id, $messageText, null, false, null, $keyboard);
    } else {
        
        $bot->sendMessage($id, "В вашем тексте больше 2200 символов!\r\n\r\nInstagram разрешает публиковать посты с количеством символов не превышающим 2200 символов, а у вас получилось ".iconv_strlen($messageText,'UTF-8')." символов."); // отправляем сообщение
    }
}, function () {
    return true;
});

$bot->run();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question