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

Unable to add a command that handles web_app_data #1423

Open
mlocati opened this issue Oct 23, 2023 · 3 comments
Open

Unable to add a command that handles web_app_data #1423

mlocati opened this issue Oct 23, 2023 · 3 comments
Labels

Comments

@mlocati
Copy link
Contributor

mlocati commented Oct 23, 2023

🐞 Bug Report

Required Information

? !
Operating system n/a
PHP Telegram Bot version 0.81.0
PHP version n/a
MySQL version n/a
Update Method Webhook
Self-signed certificate no

RAW update (if available)

{
    "update_id": 111111111,
    "message": {
        "message_id": 222,
        "from": {
            "id": 2222222,
            "is_bot": false,
            "first_name": "FirstName",
            "last_name": "LastName",
            "username": "UserName",
            "language_code": "it"
        },
        "chat": {
            "id": 2222222,
            "first_name": "FirstName",
            "last_name": "LastName",
            "username": "UserName",
            "type": "private"
        },
        "date": 1698068479,
        "web_app_data": {
            "button_text": "Text of button used to launch the Web App",
            "data": "data receieved from the Web App"
        }
    }
}

Summary

We can launch Web Apps by using the web_app key in Keyboard or InlineKeyboard reply markups.

Web Apps can send some data back to the bot (see the JSON above).

The problem is that (AFAIK) there's no way to create a command that handles it.

  • This line make it so $command_tmp contains 'Webappdata`
  • This line make it so:
    • for a command implemented in a WebAppDataCommand class, the command identifier is web_app_data
    • for a command implemented in a WebappdataCommand class, the command identifier is webappdata

Because neither web_app_data nor webappdata are the same as Webappdata,we can't create a command that handles the update.

@noplanman
Copy link
Member

I've not looked deeply into this yet, but since that data gets passed via a message, you should be able to get it inside your GenericmessageCommand class. Have you tried this?

class GenericmessageCommand extends SystemCommand
{
    public function execute(): ServerResponse
    {
        $data = $this->getMessage()?->getWebAppData()?->getData();

        // check if $data isn't null and do something with it.
    }
}

@mlocati
Copy link
Contributor Author

mlocati commented Oct 27, 2023

That's what I'm doing right now.

But I think the code has an issue (not only for Web Apps.

If $type is not 'command', this line makes it so $command_tmp always contains a string with the first character in upper case, and all the other characters in lowercase (for example: 'web_app_data''Webappdata').

But this line makes it so all the command handlers have a snake_case syntax (for example: 'WebAppDataCommand''web_app_data').

That way, when $type !== 'command', we'll NEVER have a match between command names derived from messages and command classes here.

@noplanman
Copy link
Member

@mlocati I feel bad for not having had replied earlier and looked into this more, just didn't have the time. 😕

We're trying to get fresh energy into the project and I trust this will be picked up then, as well as a bunch of other things too!

@mlocati mlocati changed the title Unable to add a command that handles web_app_daa Unable to add a command that handles web_app_data May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants