commandsHandler() public method

Processes Inbound Commands.
public commandsHandler ( boolean $webhook = false ) : Update | Update[]
$webhook boolean
return Telegram\Bot\Objects\Update | Telegram\Bot\Objects\Update[]
Example #1
0
unset($acheck['message']['message_id']);
unset($acheck['message']['from']);
unset($acheck['message']['chat']);
unset($acheck['message']['date']);
foreach ($commands as $command) {
    $command = substr_replace($command, '', 0, 7);
    $command = substr_replace($command, '', -4);
    $telegram->addCommand('Commands\\' . $command);
}
foreach ($acheck['message'] as $vc => $avalue) {
    switch ($vc) {
        case "text":
            if ($arup['message']['text'][0] != "/") {
                $telegram->sendMessage($arup['message']['chat']['id'], $lang['error_command']);
            } else {
                $telegram->commandsHandler(true);
            }
            break;
        case "photo":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_photo']);
            break;
        case "voice":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_voice']);
            break;
        case "audio":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_audio']);
            break;
        case "document":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_document']);
            break;
        case "sticker":
Example #2
0
}
require 'src/bootstrap.php';
use Telegram\Bot\Api;
use WeightLog\WeightLog;
use WeightLog\Db;
$db = Db::getInstance();
$telegram = new Api($token);
$weightLog = new WeightLog($db);
$telegram->addCommand(\WeightLog\TelegramCommands\OutputCommand::class);
$telegram->addCommand(\WeightLog\TelegramCommands\ApiCommand::class);
$telegram->addCommand(\WeightLog\TelegramCommands\HelpCommand::class);
$run = true;
$lastUpdateId = 0;
while ($run) {
    sleep(1);
    $updates = $telegram->commandsHandler(false);
    if (empty($updates)) {
        continue;
    }
    foreach ($updates as $update) {
        $lastUpdateId = $update['update_id'];
        if (substr(trim($update['message']['text']), 0, 1) == '/') {
            continue;
        }
        $weightGiven = preg_replace('/[^0-9\\.]/', '', $update['message']['text']);
        $person = $weightLog->getPersonFromUpdate($update);
        $lastWeight = $person['currentweight'];
        if (empty($weightGiven)) {
            $message = "Huh? I'm afraid that wasn't a valid weight :(";
        } else {
            $result = $db->perform("INSERT INTO weights (timestamp, weight, personid) VALUES (?, ?, ?)", [time(), $weightGiven, $person['id']]);