defstudio / telegraph

Telegraph is a Laravel package for fluently interacting with Telegram Bots
MIT License
674 stars 116 forks source link

Added independent methods for saving a chat and forming its name #647

Closed andrey-helldar closed 2 weeks ago

andrey-helldar commented 2 weeks ago

The current version of the code hardcodes the name of the chat when saving to the database. For example, [supergroup] Foo.

This is inconvenient when you need to display the list of channels without prefixes.

In such cases we have to create casts for the name field of the model to apply a regular expression to remove the prefix.

To solve this problem, I propose to consider two interrelated actions at once:

  1. Put the formation of the chat name into an external protected method that developers can easily override to change the logic.
  2. also put the method of chat creation into an external method in case some of the developers need to add their own logic when saving, having access to the DefStudio\Telegraph\DTO\Chat object.