-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add messages for score updated. #34
Feature/add messages for score updated. #34
Conversation
…ndomMessageByType service
{ | ||
private array $blocks = []; | ||
|
||
public static function create(): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a private constructor ? in order to avoid two way to create a new instance, I think this pattern is called named constructor, here is a reference it's an old video but i think it's a good video https://www.youtube.com/watch?v=J0SFLG5B3wo :p what do you think i am not sure if the private constructor is needed or not 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice suggestion, but the private constructor is not required, this semantic cosntructor allows the user to create and chain methods immediately.
Instead of:
$builder = new AdditionalParametersBuilder();
$builder->addText($text);
$builder->build($text);
We can directly:
AdditionalParametersBuilder::create()->addText($text)->build();
But this is open since sometimes you need to create complex messages based on conditions, IE:
$builder = new AdditionalParametersBuilder();
$builder->addText($text);
if ($condition) {
$builder->addText($text);
}
$builder->build();
Very nice work! I'd like to see the message suggestion implemented before we merge this pull request. |
Thanks @eruizdechavez , what do you mean with see the implementation? If it is at code level, we already use it in the PlusPlus conversation to build a complex message:
is that what you mean? |
@javleds what I mean I want to see it actually implemented with environment variables, SQLite (as I suggested) or any other alternative someone proposes instead of the config files. I am also flexible if you think that is extra work that should be done on a follow up pull request. |
3b154d7
to
28501d0
Compare
The origin of the messages were moved from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job! Thanks! 👏 🎉
This PR is a little bit longer, the main idea was to give a solution for the issue #25, nevertheless, to accomplish that required 2 changes:
In addition, and it is open to suggestions, we added the username and the score of the affected users.
The final output is similar to this:
![bot](https://user-images.githubusercontent.com/11241239/133535706-161ff29e-f3c0-4e19-b6b5-22a23f95e684.gif)
I will append a couple of segments that can be added to the wiki in case this PR gets approved, one for the class created to buid the message and other to replace the custom messages.
AdditionalParameters
Build markdown messages for slack can be a little bit hard since we have to create a complex array structures called
AdditionalParameters
. In that structure we have to define blocks, sections and fields.This data structure should be serialized in order to be processed by the BotMan and finally give a readable message on Slack.
In example, in order to send the following message:
We have to generate the following structure:
Painful, right?
To make easy the creation of that data structure we propose the
AdditionalParametersBuilder
class which builds this complex array usingnatural and fluent language.
In order to build the previous example we have to use the following code block:
Replace the custom messages
We have created the
config/parameters.yml
file with 3 important entries:In order to change, add or remove any message we have to edit those array properties. Also we have created 2 placeholders,
{user}
and{score}
which will be replaced for the real username and score of the leaderboard.In example:
Will be rendered as: