A
A
api-pro.com2019-08-01 18:59:27
opencart
api-pro.com, 2019-08-01 18:59:27

How to connect and use PHP Telegram Bot library in Opencart?

Hello! Tell me how to correctly connect and use the libraries https://github.com/TelegramBot/Api or https://github.com/php-telegram-bot/core
with Opencart models The problem is not Composer, but how to get data from methods Opencart to Telegram bot. Here is the bot code. Not loading $this->load->model('catalog/product');

<?php
class ControllerApiTelegram extends Controller {
  public function index() {
    
  try {
    $bot = new \TelegramBot\Api\Client('токен');
    
    // Запуск бота
    $bot->command('start', function ($message) use ($bot) {
    $answer = 'Добро пожаловать!';
    $bot->sendMessage($message->getChat()->getId(), $answer);
    });
    
    // помощь
    $bot->command('help', function ($message) use ($bot) {
    $answer = 'Команды:
    /help - помощь';
    $bot->sendMessage($message->getChat()->getId(), $answer);
    });
    
    $bot->command('qaanswer', function ($message) use ($bot) {
            $this->load->model('catalog/product'); // Загрузка модели Opencart
      $pr = $this->model_catalog_product->getProduct(430); // вызов метода с аргументом
      $bot->sendMessage($message->getChat()->getId(), str_replace("<br/>", "\n", $pr["price"]));
            $bot->sendMessage($message->getChat()->getId(), str_replace("<br/>", "\n", "тестовый текст"));
    });


    $bot->run();
  } catch (\TelegramBot\Api\Exception $e) {
    $e->getMessage();
  }
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question