コード例 #1
0
    if ($p->chatid() < 0) {
        // if message has been sent from a member of a Telegram group
        // ignore it and do not reply (to avoid not necessary messages on the group)
        $response = logarray('ignore', null);
    } else {
        // reply with an error message
        $answer = "Error...";
        $p->bot()->send_message($p->chatid(), $answer);
        $response = logarray('error', $answer);
    }
    return $response;
}
// instantiating a new bot
$bot = new telegram_bot($token);
// instantiating a new triggers set
$ts = new telegram_trigger_set($botname, $singletrigger);
// registering the triggers
$ts->register_trigger_command("trigger_welcome", ["/start", "/welcome", "/hi"], 0);
$ts->register_trigger_command("trigger_help", ["/help"], 0);
$ts->register_trigger_command("trigger_photo", ["/getphoto", "/photo", "/picture"], -1);
// parameters count is ignore
// error trigger
$ts->register_trigger_error("trigger_err");
// receiving data sent from the user
$message = $bot->read_post_message();
$date = $message->message->date;
$chatid = $message->message->chat->id;
$text = $message->message->text;
// running triggers management
$response = $ts->run($bot, $chatid, $text);
// returns an array of triggered events
コード例 #2
0
        $response = logarray('error', $answer);
    }
    $p->state()->movetostate("in_chat");
    // moving to state "in_chat"
    return $response;
}
// instantiating a new bot
$bot = new telegram_bot($TELEGRAM_TOKEN);
// receiving data sent from the user
$data = $bot->read_post_message();
$message = $data->message;
$date = $message->date;
$chatid = $message->chat->id;
$text = @$message->text;
// instantiating a new triggers set
$ts = new telegram_trigger_set($TELEGRAM_BOTNAME, $chatid, $singletrigger);
// registering the triggers
$ts->register_trigger_text_command("trigger_welcome", ["/start", "/welcome", "/hi"], 0, null);
// initial state
$ts->register_trigger_text_command("trigger_help", ["/help"], 0, "in_chat");
// /help command is accepted only when state is "in_chat"
$ts->register_trigger_text_command("trigger_write", ["/write"], "in_chat");
// /write command is accepted only when state is "in_chat"
$ts->register_trigger_any("trigger_input", "waiting_for_input");
// each input retrieved will trigger the trigger_input function when state is "waiting_for_input"
// error trigger
$ts->register_trigger_error("trigger_err", "*");
// this trigger is registered indipendently on the state
// running triggers management
$response = $ts->run($bot, $message);
// returns an array of triggered events
コード例 #3
0
        $answer = "Error...";
        $p->bot()->send_message($p->chatid(), $answer);
        $response = logarray('error', $answer);
    }
    return $response;
}
// instantiating a new bot
$bot = new telegram_bot($TELEGRAM_TOKEN);
// receiving data sent from the user
$data = $bot->read_post_message();
$message = $data->message;
$date = $message->date;
$chatid = $message->chat->id;
$text = @$message->text;
// instantiating a new triggers set
$ts = new telegram_trigger_set($TELEGRAM_BOTNAME, $chatid, $singletrigger);
// registering the triggers
$ts->register_trigger_text_command("trigger_welcome", ["/start", "/welcome", "/hi"], 0);
// state parameter is ignored
$ts->register_trigger_text_command("trigger_help", ["/help"], 0);
// state parameter is ignored
$ts->register_trigger_text_command("trigger_photo", ["/lena", "/getphoto", "/photo", "/picture"]);
// state and count parameters are ignored
// error trigger
$ts->register_trigger_error("trigger_err");
// state parameter is ignored
// running triggers management
$response = $ts->run($bot, $message);
// returns an array of triggered events
// log messages exchange on the database
@db_log($TELEGRAM_BOTNAME, 'recv', $chatid, 'text', $text, $date);
コード例 #4
0
        // for other content types, see https://core.telegram.org/bots/api#inlinequeryresult
    }
    // sending the results
    $results = json_encode($results);
    $cache_time = 300;
    // indicates how many seconds the content has to be kept in Telegram's servers cache (useful if many users require a content with the same identifier); use 0 or null for dynamic (never cached) elements
    $bot->send_inline($inline_query_id, $results, $cache_time);
    // for further information, see https://core.telegram.org/bots/api#inline-mode
    // logging sent results into database
    @db_log($botname, 'inline', $inline_query_id, 'inline', $date);
    // terminating the program
    exit;
}
// managing standard/not inline messages
// instantiating a new triggers set
$ts = new telegram_trigger_set($botname, $chatid, $singletrigger);
// registering the triggers
$ts->register_trigger_text_command("trigger_welcome", ["/start", "/welcome", "/hi"], 0);
// state parameter is ignored
$ts->register_trigger_text_command("trigger_help", ["/help"], 0);
// state parameter is ignored
// error trigger
$ts->register_trigger_error("trigger_err");
// state parameter is ignored
// running triggers management
$response = $ts->run($bot, $message);
// returns an array of triggered events
// log messages exchange on the database
@db_log($botname, 'recv', $chatid, 'text', $text, $date);
if (count($response) > 0) {
    foreach ($response as $r) {