Как из $bot->command получить значение массива $pr?Вне index() ничего писать нельзя:
<?php
class ControllerApiTelegram extends Controller {
public function index() {
$this->load->model('catalog/product');
$pr = $this->model_catalog_product->getProduct(430);
//$this->log->write(print_r($pr,true));
try {
$bot = new \TelegramBot\Api\Client('875746922:AAFpVCA-KCaInxfWKesNCs-bElBb7i8ZfLc');
$bot->command('devanswer', function ($message) use ($bot) {
preg_match_all('/{"text":"(.*?)",/s', file_get_contents('http://devanswers.ru/'), $result);
$bot->sendMessage($message->getChat()->getId(),
str_replace("<br/>", "\n", json_decode('"' . $result[1][0] . '"')));
});
$bot->command('qaanswer', function ($message) use ($bot) {
global $arr
$this->log->write(print_r("тетс",true));
$bot->sendMessage($message->getChat()->getId(), str_replace("<br/>", "\n", $arr["1"]));
$bot->sendMessage($message->getChat()->getId(), str_replace("<br/>", "\n", "тестовый текст"));
});
$bot->run();
} catch (\TelegramBot\Api\Exception $e) {
$e->getMessage();
}
}
}