webdevlix
@webdevlix
PHP NoobDev

Как заставить работать бота в связке с Laravel?

Всем привет.
Уже блин нервы берут.
Кто то работал с библиотекой https://github.com/irazasyed/telegram-bot-sdk в связкой с Laravel ?
Установил, Настроил, проверяю данные все с телеграмма приходит как надо.
Стоит метод ответа текстом и ничего не отправляет ошибок не фиксирует.
Черт поймешь почему не работает. SSL Let's Encrypt, на телеграмм я не грузил это же вроде как не самоподписной.
Код контроллера который обрабатывает все:
<?php
namespace App\Http\Controllers;

use Illuminate\Foundation\Inspiring;
use Telegram\Bot\Api;
use Telegram;
use Log;

/**
 * Class BotController
 */
class TelegramController extends Controller
{
    /** @var Api */
    protected $telegram;
    /**
     * BotController constructor.
     *
     * @param Api $telegram
     */
    public function __construct(Api $telegram)
    {
        $this->telegram = $telegram;
    }
    /**
     * Get updates from Telegram.
     */
    public function getUpdates()
    {
        $updates = $this->telegram->getUpdates()->getResult();
        // Do something with the updates
    }
    /**
     * Set a webhook.
     */
    public function setWebhook()
    {
        // Edit this with your webhook URL.
        // You can also use: route('bot-webhook')
        $url = "https://domain.com/bot/webhook";
        $response = $this->telegram->setWebhook()
            ->url($url)
            ->getResult();
        return $response->getDecodedBody();
    }
    /**
     * Remove webhook.
     *
     * @return array
     */
    public function removeWebhook()
    {
        $response = $this->telegram->removeWebhook();
        return $response->getDecodedBody();
    }
    /**
     * Handles incoming webhook updates from Telegram.
     *
     * @return string
     */
    public function webhookHandler()
    {
        // If you're not using commands system, then you can enable this.
        $update = $this->telegram->getWebhookUpdates();
        // This fetchs webhook update + processes the update through the commands system.
        #$update = $this->telegram->commandsHandler(true);
        // Commands handler method returns an Update object.
        // So you can further process $update object
        // to however you want.
        // Below is an example
        $message = $update->getMessage()->getText();
        // Triggers when your bot receives text messages like:
        // - Can you inspire me?
        // - Do you have an inspiring quote?
        // - Tell me an inspirational quote
        // - inspire me
        // - Hey bot, tell me an inspiring quote please?
        if(str_contains($message, ['inspire', 'inspirational', 'inspiring'])) {
            $this->telegram->sendMessage()
                ->chatId($update->getMessage()->getChat()->getId())
                ->text('Hallo')
                ->getResult();
        }
        return 'Ok';
    }
}
  • Вопрос задан
  • 1474 просмотра
Пригласить эксперта
Ответы на вопрос 1
itorgov
@itorgov
Full Stack Developer
Я работал с этой библиотекой.
Только я не понял куда и что у вас не отправляется :-(
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы