Skip to content
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

Add a way to customize Slack messages #2

Open
clemherreman opened this issue May 19, 2017 · 1 comment
Open

Add a way to customize Slack messages #2

clemherreman opened this issue May 19, 2017 · 1 comment

Comments

@clemherreman
Copy link

clemherreman commented May 19, 2017

Hi!

First of all, thank you for sharing this with the community. You rock!

I'd like to have a way to customize the messages sent to Slack, without having to edit platform2slack code. This could be just a callback, given when setting up my hook, much like validateToken():

// Optional settings
$settings = [
    'channel' => '#random',
    'region' => 'eu',
];

$platformsh2slack = new Hanoii\Platformsh2Slack\Platformsh2Slack(
    'https://hooks.slack.com/services/...',
    $settings
);


// 'environment.delete' come from the `switch ($platformsh->type)`
$platformsh2slack->customizeSlackText('environment.delete', function ($defaultText, $platformsh) {
    return sprintf('Oh noes, the env "%s" has been deleted', $platformsh->payload->environment->name);
});

// "all" is a special event
$platformsh2slack->customizeSlackText('all', function ($defaultText, $platformsh) {
    return sprintf('Hey @here: %s', $defaultText); // Prefix any message sent to slack.
});

My own usecase is that I want to customize the way routes are displayed, to make it more user-friendly (read: project manager friendly)

I'm willing to take some time and write the PR, but I wanted to know if you were interested in such a new feature.

@hanoii
Copy link
Owner

hanoii commented May 23, 2017

Hey, thanks, I am glad you like it. I appreciate the suggestion, I recently moved this into a proper composer library and the formatting of message was carried over from the original script. It's definitely a place to improve.

To be honest, I believe that callbacks are not the way to go. Not very OOP.

What you could and show do is extend the class and override the methods you need.

Right now that's processPlatformshPayload(), however, it kind of have quite a bit of logic. That function needs to be properly refactored into something that's easier to extend from upper classes and make better functions to extend.

If you are want to contribute some refactor I am happy to review.

Also, if if you want to suggest a more user friendly way of displaying routes, and if I like it more or it looks better that what I did, I am also happy to change it. I haven't given it much thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants