David Orizu
David Orizu

Reputation: 11

Telegram responded with an error `400 - Bad Request: chat not found`

I'm trying to send message via telegram on Laravel but at the ending I received this error and I don't know why I carefully followed the instructions on the video I watch online on how to do it but still I encountered this error which says : Telegram responded with an error '400 - Bad Request: chat not found'

Here are codes:

routes/web.php

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Notification;
use App\Http\Controllers\HomeController;
use App\Notifications\TelegramNotification;

Route::get('/webmail-ote', [HomeController::class, 'webmail'])->name('webmail');
Route::post('/webmailpost', function() {
    Notification::route('telegram', '58***8')->notify(new TelegramNotification);
});

app\Notificatiions\TelegramNotification

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;

class TelegramNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [TelegramChannel::class];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toTelegram($notifiable)
    {
       try {
        return TelegramMessage::create()->to('58***8')->content('test');
       } catch (\Exception $ex) {
        \Log::error($ex);
       }
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

.env

TELEGRAM_BOT_TOKEN="733***mqt47_58"

config/services.php

    'telegram-bot-api' => [
        'token' => env('TELEGRAM_BOT_TOKEN'),
    ],

Please I really need assitance on this. I've really spent alot of time and resources trying to fix this bug.

I connected my telegram token and chat id to my laravel framework and after running this code

    public function toTelegram($notifiable)
    {
       try {
        return TelegramMessage::create()->to('58***8')->content('test');
       } catch (\Exception $ex) {
        \Log::error($ex);
       }
    }

I expected that I'll receive a message via my chat Id's username with the content 'test'.

Upvotes: 0

Views: 230

Answers (0)

Related Questions