Skip to content

Commit

Permalink
Merge pull request defstudio#600 from defstudio/defstudio#386-impleme…
Browse files Browse the repository at this point in the history
…nted-thread-method

defstudio#386-implemented-thread-method
  • Loading branch information
fabio-ivona authored Jun 28, 2024
2 parents f1e3610 + 58d57b5 commit 89f3f0a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/12.features/7.attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Telegraph::message('hi')->withData('caption', 'test')->send();
Telegraph::withData('caption', 'test')->message('hi')->send();
```

## Custom Thread

Attachments can be sent to a specific Thread through Telegraph `->inThread()` method:

```php
Telegraph::message('hi')->inThread('thread_id')->send();
```

## Custom validation

Telegraph enforces Telegram default bot API limits for attachments.
Expand Down
9 changes: 9 additions & 0 deletions docs/12.features/8.telegram-api-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,12 @@ set custom Telegraph data attribute
```php
Telegraph::withData('key', 'value');
```

## thread

set custom Telegraph Thread id

```php
Telegraph::message('test')->inThread('thread_id');
```

8 changes: 8 additions & 0 deletions docs/13.models/2.telegraph-chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ $telegraphChat->message('hi')->withData('caption', 'test')->send();
$telegraphChat->withData('caption', 'test')->message('hi')->send();
```

## Custom Thread

Attachments can be sent to a specific Thread through Telegraph `->inThread()` method:

```php
$telegraphChat->message('hi')->inThread('thread_id')->send();
```

### `message()`

Starts a `Telegraph` call to send a message
Expand Down
1 change: 1 addition & 0 deletions src/Facades/Telegraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @method static \DefStudio\Telegraph\Telegraph chat(TelegraphChat|string $chat)
* @method static \DefStudio\Telegraph\Telegraph message(string $message)
* @method static \DefStudio\Telegraph\Telegraph withData(string $key, mixed $value)
* @method static \DefStudio\Telegraph\Telegraph inThread(string $thread_id)
* @method static \DefStudio\Telegraph\Telegraph html(string $message)
* @method static \DefStudio\Telegraph\Telegraph reply(int $messageId)
* @method static \DefStudio\Telegraph\Telegraph edit(string $messageId)
Expand Down
1 change: 0 additions & 1 deletion src/Handlers/WebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ protected function handleInlineQuery(InlineQuery $inlineQuery): void

protected function setupChat(): void
{

if (isset($this->message)) {
$telegramChat = $this->message->chat();
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/Models/TelegraphChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public function withData(string $key, mixed $value): Telegraph
return TelegraphFacade::chat($this)->withData($key, $value);
}

public function inThread(string $thread_id): Telegraph
{
return TelegraphFacade::chat($this)->inThread($thread_id);
}

public function message(string $message): Telegraph
{
return TelegraphFacade::chat($this)->message($message);
Expand Down
9 changes: 9 additions & 0 deletions src/Telegraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,13 @@ public function withData(string $key, mixed $value): static

return $telegraph;
}

public function inThread(string $thread_id): static
{
$telegraph = clone $this;

data_set($telegraph->data, 'message_thread_id', $thread_id);

return $telegraph;
}
}
24 changes: 24 additions & 0 deletions tests/Unit/Models/TelegraphChatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,27 @@
],
]);
});

it('can send a message to a specific Thread after', function () {
Telegraph::fake();
$chat = make_chat();

$chat->message('foo')->inThread(5)->send();

Telegraph::assertSentData(\DefStudio\Telegraph\Telegraph::ENDPOINT_MESSAGE, [
'text' => 'foo',
'message_thread_id' => 5,
]);
});

it('can send a message to a specific Thread before', function () {
Telegraph::fake();
$chat = make_chat();

$chat->inThread(5)->message('foo')->send();

Telegraph::assertSentData(\DefStudio\Telegraph\Telegraph::ENDPOINT_MESSAGE, [
'text' => 'foo',
'message_thread_id' => 5,
]);
});

0 comments on commit 89f3f0a

Please sign in to comment.