hamed
hamed

Reputation: 8033

telegram bot api - send additional data with replay keyboard

I'm working on telegram bot api and I sendReplayKeyboard with my message text to user. When a user click on a button, telegram sends a post with below structure to my webhook. Here is json structure of post:

{
    "update_id": *******,
    "message": {
        "message_id": ***,
        "from": {
            "id": *****,
            "is_bot": false,
            "first_name": "*****",
            "username": "******",
            "language_code": "en-US"
        },
        "chat": {
            "id": *****,
            "first_name": "******",
            "username": "*****",
            "type": "private"
        },
        "date": 1518716587,
        "text": "Button Text"
    }
}

My problem is telegram does not accept any additional data for replay keyboard button. So, I have to check message.text with string and this is not a good practice. For example if the button has emoji, the emoji code must be in the check. Also, I have different menu type and I need to find out type of clicked button, but I have just text of the button. So I need to assign id and type to each button. But I don't know how can I do it.

Here is the post data that my bots sends to user:

$keyboard = array(
        'resize_keyboard' => true,
        'keyboard' => array(
            array(
                array(
                   "text" => "Button Text"
                   //There is not any `id` or `type`,...
                )
            )
        )
    );

$post_fields = array(
    'chat_id' => **********
    'text' => ************,
    'reply_markup' => json_encode($keyboard)
);

Note: I don't want to InlineKeyboard and I need to use RelplayKeyboard.

If it's not possible, is there any alternative way? For example put additional data in button text and hide it from user.

Upvotes: 1

Views: 1552

Answers (1)

علیرضا
علیرضا

Reputation: 2642

It seems you need to save each user stat, so you can elect suitable reaction to similar text of button.

Also note that emoji is not horrible! and you don't need emoji code! You just need to compare text that include emoji with a predefined string:

if('راهنما 💡'===$receivedText)
    doSomeMagic();

Upvotes: 0

Related Questions