Example #1
0
<?php

/**
 * Handle bot messages via a webhook
 */
use Anibis\Notify\BotMessage;
use Anibis\Notify\TelegramService;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
require_once __DIR__ . '/../vendor/autoload.php';
/**
 * @var \Silex\Application $app
 */
$app = new \Anibis\App(['debug' => false]);
if (php_sapi_name() == 'cli') {
    if (!isset($argv[1])) {
        die("Please define a bot URL or enter 'delete' to add a hook\n");
    }
    $url = $argv[1];
    if ($url === "delete") {
        $url = "";
    }
    // if run from console, set or delete webhook
    $app["notify"]->send('setWebhook', ['url' => $url]);
    exit;
}
/**
 * Handle bot actions
 */
$app->post("/", function () use($app) {
Example #2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
// web/index.php
use Anibis\Criteria\SearchCriteria;
use Anibis\Db\DbService;
use Anibis\Notify\TelegramService;
use Anibis\Result\Result;
use Symfony\Component\HttpFoundation\Request;
/**
 * @var \Silex\Application $app
 */
$app = new \Anibis\App(['debug' => strpos($_SERVER['SCRIPT_NAME'], "_dev.php") !== false]);
$app->get('/', function (Request $request) use($app) {
    $s = new SearchCriteria();
    $providers = ["anibis", "homegate"];
    $results = [];
    foreach ($providers as $name) {
        try {
            $provider = $app[$name];
            $results = array_merge($results, call_user_func([$provider, "getCachedResults"], $s));
        } catch (Requests_Exception $re) {
            $app["notify"]->notify("Error while getting results for " . $name . " :" . $re->getMessage(), false);
            if ($app["dev"]) {
                throw $re;
            }
        }
    }
    // Process new offers
    /** @var DbService $db */
    $db = $app["db"];