<?php
class CallbackService extends BaseSerevice {
function findRequestHandler($update){
$callBackData = explode(":", $this->getTG()->callback_data);
$this->getTG()->getButtonService()->setButtonsData($this->getTG()->message["reply_markup"]["inline_keyboard"]);
$speech = new Speech($this->getTG(), $callBackData);
$textCallback = $speech->listen();
$conjugator = new Conjugator($this->getTG(), $callBackData);
$textCallback = $conjugator->listen();
// $learnSys = new LearnSystem($this->getTG(), $callBackData);
$this->getTG()->getLearnSystem()->setCallbackData($callBackData);
$textCallback = $this->getTG()->getLearnSystem()->listenCallback();
$this->getTG()->getEvaluationSystem()->listen();
if($callBackData[0] == "task" && $callBackData[1] == "quiz"){
$quizMaker = new QuizMaker($this->getTG());
$textCallback = $quizMaker->quizListener($this->getTG(), $callBackData, $update);
}
$this->listen();
$this->getTG()->apiRequest ( "answerCallbackQuery", array (
'callback_query_id' => $this->getTG()->callback_id,
"text" => $textCallback,
"cache_time" => 0
) );
}
function listen()
{
$callBackData = explode(":", $this->getTG()->callback_data);
$actionKey = $callBackData[0];
$callbackHandler = $this->getCallbackHandler($actionKey);
$callbackHandler->setParent($this);
$callbackHandler->setActionkey($actionKey );
if(isset($callBackData[1])){
$data = $callBackData[1];
$callbackHandler->setData($data);
}
$callbackHandler->execute();
}
public function getCallbackHandler($actionKey): CallBackhandler {
$answers[ShowExamplesCallbackHandler::$key]= new ShowExamplesCallbackHandler($this->getTG());
$answers[ExtractTextCallbackHandler::$key]= new ExtractTextCallbackHandler($this->getTG());
$answers[SpeechToTextCallbackHandler::$key]= new SpeechToTextCallbackHandler($this->getTG());
$answers[CreateAds::$key]= new CreateAds($this->getTG());
$answers[DeFaTextTranslate::$key]= new DeFaTextTranslate($this->getTG());
$answers[FaDeTextTranslate::$key]= new FaDeTextTranslate($this->getTG());
$answers[DeDeTextTranslate::$key]= new DeDeTextTranslate($this->getTG());
if(isset($answers[$actionKey])){
return $answers[$actionKey];
}
else {
return new NotFoundCallbackHandler($this->getTG());
}
}
}
?>