Skip to content

Commit

Permalink
custom webhooks url
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Jan 22, 2024
1 parent c2ecb10 commit 5031ea5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config/telegraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
*/
'webhook_handler' => DefStudio\Telegraph\Handlers\EmptyWebhookHandler::class,

/*
* Sets the webhook URL that will be exposed by the server,
* this can be customized or entirely disabled (by setting it to NULL)
*/
'webhook_url' => '/telegraph/{token}/webhook',

/*
* Sets a custom domain when registering a webhook. This will allow a local telegram bot api server
* to reach the webhook. Disabled by default
Expand Down
8 changes: 6 additions & 2 deletions docs/content/14.webhooks/2.registering-webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ navigation.title: 'Register Webhooks'

In order to receive Telegram updates through a webhook, it has to be registered to a specific bot. This can be accomplished both programmatically and through an artisan command

## artisan command
### artisan command

You can register a webhook calling the `telegraph:set-webhook` artisan command:

```shell
php artisan telegraph:set-webhook
```

## programmatically
### programmatically

if you are implementing a custom bot management logic, you can register a webhok using the `TelegraphBot` model:

Expand All @@ -24,3 +24,7 @@ $telegraphBot->registerWebhook()->send();
```

<alert type="alert">Manual updates polling is not available if a webhook is set up for the bot. Webhook should be remove first using its [unregisterWebhook](/webhooks/deleting-webhooks) method</alert>

## Routes

Telegraph register a route to handle webhook messages. By default, the URL is: `https://<server_domain>/telegraph/{token}/webhook`, but it can be customized in [telegraph.php config](/installation#Configuration) file (`webhook_url`) or entirely disabled (by setting its value to `null`)
6 changes: 6 additions & 0 deletions docs/content/2.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ return [
*/
'webhook_handler' => DefStudio\Telegraph\Handlers\EmptyWebhookHandler::class,

/*
* Sets the webhook URL that will be exposed by the server,
* this can be customized or entirely disabled (by setting it to NULL)
*/
'webhook_url' => '/telegraph/{token}/webhook',

/*
* Sets a custom domain when registering a webhook. This will allow a loca telegram bot api server
* to reach the webhook. Disabled by default
Expand Down
7 changes: 6 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
use DefStudio\Telegraph\Controllers\WebhookController;
use Illuminate\Support\Facades\Route;

Route::post('/telegraph/{token}/webhook', [WebhookController::class, 'handle'])->name('telegraph.webhook');
if($webhookUrl = config('telegraph.webhook_url', '/telegraph/{token}/webhook')){

Route::post($webhookUrl, [WebhookController::class, 'handle'])->name('telegraph.webhook');

}

0 comments on commit 5031ea5

Please sign in to comment.