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

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?