【问题标题】:Laravel: Telegram SDK not working with Laravel 5.5Laravel:电报 SDK 不适用于 Laravel 5.5
【发布时间】:2018-04-11 20:43:48
【问题描述】:

我有两个项目要使用this SDK。一个是 Laravel 5.4,第二个是 Laravel 5.5。 使用 Laravel 5.4 消息发送顺利,但使用 Laravel 5.5 我收到以下错误:

代码是:

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

电报控制器:

<?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,
        ]);
    }
}

有什么问题?

编辑:

我忘记在 config/app.php 中添加这些行(谢谢 Pyramid 先生)

现在我有另一个错误,它找不到TelegramOtherException。我重新安装了它,但仍然出现错误:

【问题讨论】:

  • 你是如何安装 sdk 的?
  • 我将"irazasyed/telegram-bot-sdk": "2.*" 放入composer.json,而不是运行composer update
  • 检查我的答案并按照文档进行操作

标签: php laravel telegram telegram-bot laravel-5.5


【解决方案1】:

查看您提到的文档,它建议了两种通过composer安装sdk的方法

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

或者

composer require irazasyed/telegram-bot-sdk ^2.0

然后添加providersapp/config.php

Telegram\Bot\Laravel\TelegramServiceProvider::class

然后Facadeapp/config.php 中是可选的

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

并最终通过以下任一方式发布

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

php artisan vendor:publish

参考:Telegram SDK Bot

注意:在 Laravel 5.5 中会自动检测外观,但我仍然建议进行交叉检查。

【讨论】:

  • 谢谢,我忘记在 app.php 中添加行了。现在我有另一个例外,我用它的图片编辑了问题。
  • 你试过这些composer dump-autoload然后composer update
猜你喜欢
  • 2021-05-16
  • 2018-06-07
  • 2018-09-22
  • 1970-01-01
  • 1970-01-01
  • 2018-07-29
  • 1970-01-01
  • 2018-09-19
  • 1970-01-01
相关资源
最近更新 更多