PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Mateo   Ollama Artificial Intelligence PHP Telegram Bot   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Ollama Artificial Intelligence PHP Telegram Bot
Telegram bot to interact with Ollama AI models
Author: By
Last change:
Date: 4 months ago
Size: 1,344 bytes
 

Contents

Class file image Download
<?php

use Mateodioev\OllamaBot\Cache\UserCache;
use
Mateodioev\OllamaBot\Db\MysqlDatabase;
use
Mateodioev\OllamaBot\Events\{CancellCompletation, Chat, PrivateTextListener, SetModel, Start, ViewCompletionDetails};
use
Mateodioev\OllamaBot\Repository\MysqlUserRepository;
use
Mateodioev\TgHandler\{Bot, Log};

use function
Mateodioev\OllamaBot\env;

require
__DIR__ . '/vendor/autoload.php';

\
Dotenv\Dotenv::createImmutable(__DIR__)->load();

// Create logger
$logStreams = new Log\BulkStream(
    new
Log\TerminalStream(),
   
// (new Log\PhpNativeStream())->activate(env('LOG_DIR', __DIR__))
);
$logger = new Log\Logger($logStreams);

// Create bot
$bot = new Bot(env('BOT_TOKEN'), $logger);
$logStreams->add(new Log\BotApiStream($bot->getApi(), (int) env('BOT_LOG_CHANNEL_ID')));

$bot->onEvent(Start::get())
    ->
onEvent(Chat::get())
    ->
onEvent(SetModel::get())
    ->
onEvent(CancellCompletation::get())
    ->
onEvent(new PrivateTextListener())
    ->
onEvent(new ViewCompletionDetails());

$db = new MysqlDatabase('mysql:host=' . env('DB_HOST') . ';dbname=' . env('DB_NAME') . ';charset=utf8mb4', env('DB_USER'), env('DB_PASS'));
UserCache::setRepo(new MysqlUserRepository($db));

$bot->longPolling(
    (int)
env('BOT_POLLING_TIMEOUT', 60),
    (bool)
env('BOT_POLLING_IGNORE_OLD_UPDATES', false),
    (bool)
env('BOT_ASYNC', true)
);