Hi,
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 ) {
return;
}
$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
.
CFR. “Split a string by string” (the “by string” could be ‘ ‘)
php.net/manual/en/function.explode.php
Thread Starter
dkwmd
(@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");
break;
case "/email":
ctgame_sendmessage($userid, "Comando selezionato $cmd"."\n");
break;
case "/track":
ctgame_sendmessage($userid, "Comando selezionato $cmd"."\n");
break;
default:
break;
}
}
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:
[insert_php]
if(empty($var){
//do something
} else {
//do something else
}[/insert_php]
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?
@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: wordpress.org/support/topic/how-to-setup-dynamic-answer-to-mybot-message?replies=4.