dongzichan2886
2017-10-30 19:06
浏览 84
已采纳

Laravel:Telegram SDK不能与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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dougengqiu8031 2017-10-30 20:29
    已采纳

    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.

    打赏 评论