Support » Plugin: Telegram Bot & Channel » how to make /command $var1 var2

  • Resolved dkwmd


    Hi i try to make command /repeat with: i repeat [php_insert]echo $var1 $var[/php_insert]
    but when i try to message the bot with /repeat blah blah it not respon.

    can you show some example how to make /command with $var1 var2

    thank you its a wonderful plugin..

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Marco Milesi


    at the moment the best way is to split the text received. More documentation will be added soon.

    I suggest to do it with “real php”. I am developing custom filters where you can append your functions. For example:

    add_action('telegram_parse','myfunction', 10, 2);
    function myfunction( $telegram_user_id, $text ) {
    $plugin_post_id = telegram_getid( $telegram_user_id );
        if ( !$plugin_post_id ) {
        $userid = telegramcustom_getuserid ( $telegram_user_id );
        if ( $text == '/text') { //or 'text'
           //do, check or parse something
           //to send a message, use telegram_sendmessage( $telegram_user_id, $string);

    I think that the best way to test is to create a mini plugin made of a single php file in wp-content/plugins/mytelegramcustomization.php.

    Plugin Author Marco Milesi


    CFR. “Split a string by string” (the “by string” could be ‘ ‘)

    Thread Starter dkwmd


    Thanks for the snippet. i will try this today 🙂

    hello .. I wrote this feature is still experimental and in spite of the action seems to work well

    function ctgame_command( $userid, $text ) {
            $tl = telegram_getid( $userid );
            if ( !$tl ) return;
            $args = explode(" ", $text);
            $cmd = $args[0];
            switch ($cmd) {
                case "/text":
                    ctgame_sendmessage($userid, "Comando selezionato $cmd"."\n");
                case "/email":
                    ctgame_sendmessage($userid, "Comando selezionato $cmd"."\n");
                case "/track":
                    ctgame_sendmessage($userid, "Comando selezionato $cmd"."\n");

    Hi, everyone! Sorry, I’m not a programmer, just know a bit, so if I have a silly question, forgive me.
    I found the same problem — can’t understand how to use these $vars in commands.
    If I understand correctly from upper posts there is no currently a way to parse the $var from command without adding some php code/files to the server?

    I guessed it should work like this:
    1. I enter command name “/test,/test $var”
    2. I set the command body as:

    //do something
    } else {
    //do something else

    In this way empty section works fine, but when I type to the bot something like “/test 10” it returns me error message. What should I do to get $var value?
    Or am I doing everything completely wrong?

    Plugin Author Marco Milesi


    @enzolarosa way should work fine: $args[0] contains the command and $args[1] the first var.

    I suggest to use filters instead of “Insert Php”. Check this thread:

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to make /command $var1 var2’ is closed to new replies.