Feralheart
Feralheart

Reputation: 1940

Laravel: Telegram SDK not working with Laravel 5.5

I have two project where I want to use this SDK. One is Laravel 5.4 the second is Laravel 5.5. With Laravel 5.4 the message sending goes smoothly, but with the Laravel 5.5 I got the following error: enter image description here

The code is:

use App\Http\Controllers\TelegramController;
.
.
.
TelegramController::sendNotification('contactMail', $params);

TelegramController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Telegram\Bot\Laravel\Facades\Telegram;

class TelegramController extends Controller {

    public function getHome()
    {
        return view('/');
    }

    public function getUpdates()
    {
        $updates = Telegram::getUpdates();
        dd($updates);
    }

    public static function sendNotification($type, $params){
        switch($params['subject']){
            case 'contact':
                $subject = 'Contact';
                break;

            case 'pricequote':
                $subject = 'PriceQuote';
            break;
        }
        switch($type){
            case 'contactMail':
                $message = 'New message from:: ' . $params['email'] . ". Subject: " . $subject;
        }
        Telegram::sendMessage([
            'chat_id' => 'mychatId',
            'text' => $message,
        ]);
    }
}

What's the problem?

Edit:

I forgot to add the lines to config/app.php (thank you, Mr. Pyramid)

Now I have an another error, that it don't find the TelegramOtherException. I reinstalled it, but still I got the error:

enter image description here

Upvotes: 2

Views: 1289

Answers (1)

Mr. Pyramid
Mr. Pyramid

Reputation: 3935

Check the docs you have mentioned, it suggests two ways to install sdk via composer

{
    "require": {
      "irazasyed/telegram-bot-sdk": "^2.0"
    }
}

OR Alternatively

composer require irazasyed/telegram-bot-sdk ^2.0

Then afterwards add providers app/config.php

Telegram\Bot\Laravel\TelegramServiceProvider::class

and then Facade which is optional in app/config.php

'Telegram'  => Telegram\Bot\Laravel\Facades\Telegram::class

and at last publish it by any one of the following ways

php artisan vendor:publish --provider="Telegram\Bot\Laravel\TelegramServiceProvider"

OR

php artisan vendor:publish

REF : Telegram SDK Bot

NOTE: In Laravel 5.5 facades are automatically detected but still I recommend to do a cross check.

Upvotes: 4

Related Questions