DEF STUDIO srl

Need help with Laravel and web development?

Hire one of our experts for your projects.

We build tailored products, websites and platforms — with care for UX, performance and maintainability.

Booking open for Q4 — limited slots

You are seeing the documentation for version 1, but the last version for this package is v1. Click here to go to the last version.

Fake Telegram interaction

In order to avoid sending real messages to Telegram when testing, the Telegraph facade offers a ::fake() method to start registering sent messages internally instead of sending them to Telegram APIs.

use DefStudio\Telegraph\Facades\Telegraph;

Telegraph::fake();

Telegraph::message("Hello devs!")->send();

// the message won be actually sent to telegram, but can still be asserted

Telegraph::assertSent('Hello devs!');

For a webhook command flow, call Telegraph::fake() before the handler and assert the fake payload after handling. The first-bot tutorial has a complete /start example with a persisted TelegraphBot, a known TelegraphChat, and no real Telegram requests: Build your first Telegram bot with Telegraph.

use DefStudio\Telegraph\Facades\Telegraph;
use DefStudio\Telegraph\Telegraph as TelegraphCore;

Telegraph::fake();

// Handle the webhook request for /start...

Telegraph::assertSentData(TelegraphCore::ENDPOINT_MESSAGE, [
    'chat_id' => '-123456789',
    'text' => 'Hello! Telegraph is connected.',
]);

Custom responses

If needed for testing purpose, the ::fake() helper can accept an array of responses to be returned for each endpoint call:

 Telegraph::fake([
   \DefStudio\Telegraph\Telegraph::ENDPOINT_MESSAGE => ['result' => 'oooook'],
]);

$response = Telegraph::message('foo')->send();

//$response will be a Response containing a json body: {"result":"oooook"}

Sent data dump

For debugging purpose, a dump of the sent data can be obtained with:

Telegraph::fake();

// Telegraph requests...

Telegraph::dumpSentData();
Suggest a change
Last updated 29 May 2026