Laravel:Telegram SDK 不适用于 Laravel 5.5
Laravel: Telegram SDK not working with Laravel 5.5
我有两个要使用的项目 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中添加这些行(谢谢金字塔先生)
现在我有另一个错误,它没有找到 TelegramOtherException
。我重新安装了它,但仍然出现错误:
查看你提到的文档,它建议了两种通过composer
安装sdk的方法
{
"require": {
"irazasyed/telegram-bot-sdk": "^2.0"
}
}
或者
composer require irazasyed/telegram-bot-sdk ^2.0
然后添加providers
app/config.php
Telegram\Bot\Laravel\TelegramServiceProvider::class
然后 Facade
在 app/config.php
中是可选的
'Telegram' => Telegram\Bot\Laravel\Facades\Telegram::class
最后通过以下任意一种方式发布
php artisan vendor:publish --provider="Telegram\Bot\Laravel\TelegramServiceProvider"
或
php artisan vendor:publish
REF : Telegram SDK Bot
注意: 在 Laravel 5.5 中自动检测立面,但我仍然建议进行交叉检查。
我有两个要使用的项目 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中添加这些行(谢谢金字塔先生)
现在我有另一个错误,它没有找到 TelegramOtherException
。我重新安装了它,但仍然出现错误:
查看你提到的文档,它建议了两种通过composer
{
"require": {
"irazasyed/telegram-bot-sdk": "^2.0"
}
}
或者
composer require irazasyed/telegram-bot-sdk ^2.0
然后添加providers
app/config.php
Telegram\Bot\Laravel\TelegramServiceProvider::class
然后 Facade
在 app/config.php
'Telegram' => Telegram\Bot\Laravel\Facades\Telegram::class
最后通过以下任意一种方式发布
php artisan vendor:publish --provider="Telegram\Bot\Laravel\TelegramServiceProvider"
或
php artisan vendor:publish
REF : Telegram SDK Bot
注意: 在 Laravel 5.5 中自动检测立面,但我仍然建议进行交叉检查。