I am using PHP 7.4.1
and Laravel Framework 6.20.16
.
I am trying to implement the following library: telegram-bot-sdk and the following version "irazasyed/telegram-bot-sdk": "^2.0",
After installing the sdk and getting my private token from telegram’s @botfather
. I am trying to use the sdk.
I created a route and a controller:
route
Route::get('telegramHello', 'TelegramController@getHello');
controller
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use TelegramBotApi as Telegram;
use AppHelpersTelegramResponse as Response;
class TelegramController extends Controller
{
public function getHello() {
$api = new Telegram(); // ----> HERE I GET THE ERROR
$response = $api->getMe();
return Response::handleResponse($response);
}
//...
When opening my route I get the following exception:
The thing I do not understand is that I have created the config telegram.php
and loading my correct token from my .env
file:
In my .env
file it looks like the following:
Any suggestions what I am doing wrong?
I appreciate your replies!
2
Answers
The two comments above helped me the most:
""
for yourTELEGRAM_BOT_TOKEN
.env
variable useTELEGRAM_BOT_TOKEN
I hope this works also for others that have this problem.
Use Facade, not original API class. Your config is correct, you just using wrong class.
Also i may recommend you using
westacks/telebot
instead ofirazasyed/telegram-bot-sdk
. I created it as irazasyed’s was poorly documented and really buggy at a lot of places.