[PR #846] [MERGED] Add new Slack handlers using Slackbot and webhooks #1379

Closed
opened 2026-03-04 03:11:17 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Seldaek/monolog/pull/846
Author: @hkdobrev
Created: 9/6/2016
Status: Merged
Merged: 11/25/2016
Merged by: @Seldaek

Base: 1.xHead: slack-webhooks


📝 Commits (10+)

  • 393e243 Add a Slackbot handler
  • f584e56 Extract logic for preparing Slack data to SlackRecord
  • 274f778 Make channel in SlackRecord optional to allow for webhooks
  • 4b671eb Add a Slack Webhooks handler using the same SlackRecord util
  • 0956a74 Adds new Slack handlers to the docs
  • 115f671 Use constants for Slack colors
  • 000a219 Mark former public methods of SlackHandler as deprecated
  • 862c087 Expose a getter for the SlackRecord in Slack handlers
  • 2d1fbbe Make SlackRecord::stringify() work without a line formatter
  • 7c2f58e Add initial tests for SlackRecord

📊 Changes

9 files changed (+1001 additions, -158 deletions)

View changed files

📝 doc/02-handlers-formatters-processors.md (+3 -1)
src/Monolog/Handler/Slack/SlackRecord.php (+248 -0)
📝 src/Monolog/Handler/SlackHandler.php (+51 -144)
src/Monolog/Handler/SlackWebhookHandler.php (+108 -0)
src/Monolog/Handler/SlackbotHandler.php (+80 -0)
tests/Monolog/Handler/Slack/SlackRecordTest.php (+341 -0)
📝 tests/Monolog/Handler/SlackHandlerTest.php (+17 -13)
tests/Monolog/Handler/SlackWebhookHandlerTest.php (+106 -0)
tests/Monolog/Handler/SlackbotHandlerTest.php (+47 -0)

📄 Description

See https://github.com/Seldaek/monolog/issues/743#issuecomment-242994019

This is keeping the previous SlackHandler, but extracts the message formatting logic and introduces two new Slack handlers:

  • SlackbotHandler - this is the simplest way to log to Slack and most people could use that. It doesn't allow fancy formatting, but has autolinking and the simplest configuration with two clicks in the Slack settings and getting a token.
  • SlackWebhookHandler - This is a bit more advanced as it allows for the same formatting and adding attachements as the SlackHandler, but it uses the Slack Webhooks which are quite easier to set up than the OAuth API. The minimum it requires is a webhook URL which is a retrievable with about two clicks in the Slack settings. Even the channel is optional as it could be configured in the integration.

This is probably not the leanest way to implement what we've discussed in https://github.com/Seldaek/monolog/issues/743, but after working at this I believe this is the simplest and the right approach.

While we could implement everything in one handler the API would become horrible and it would be harder to understand from users. Providing choice with simple to use separate classes is better IMHO. Apart from this the SlackHandler extends the SocketHandler and the webhooks and the Slackbot wouldn't work nicely with that.

What do you think?

@Seldaek @gkedzierski @Gummibeer @nisbeti


  • Extracting Slack formatting logic in SlackRecord
  • SlackbotHandler
  • SlackWebhookHandler
  • Refactor SlackHandler using the new SlackRecord
  • Add new handlers to the docs
  • Unit tests of SlackRecord
  • Unit tests for SlackbotHandler
  • Unit tests for SlackWebhookHandler
  • Update unit tests for SlackHandler

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Seldaek/monolog/pull/846 **Author:** [@hkdobrev](https://github.com/hkdobrev) **Created:** 9/6/2016 **Status:** ✅ Merged **Merged:** 11/25/2016 **Merged by:** [@Seldaek](https://github.com/Seldaek) **Base:** `1.x` ← **Head:** `slack-webhooks` --- ### 📝 Commits (10+) - [`393e243`](https://github.com/Seldaek/monolog/commit/393e243499c1c573a942a469e1656d9e95a84469) Add a Slackbot handler - [`f584e56`](https://github.com/Seldaek/monolog/commit/f584e56ae14e665c2b5b13024962f33f03518af6) Extract logic for preparing Slack data to SlackRecord - [`274f778`](https://github.com/Seldaek/monolog/commit/274f778b2429073231a39e3a1126c3f24d93707a) Make channel in SlackRecord optional to allow for webhooks - [`4b671eb`](https://github.com/Seldaek/monolog/commit/4b671eb82c16bff4c941bcbf067921980400baed) Add a Slack Webhooks handler using the same SlackRecord util - [`0956a74`](https://github.com/Seldaek/monolog/commit/0956a74897fe3ef39ff4e5871d2e90b3c7cc95b7) Adds new Slack handlers to the docs - [`115f671`](https://github.com/Seldaek/monolog/commit/115f6710b1eed135489716010d7958b838773b41) Use constants for Slack colors - [`000a219`](https://github.com/Seldaek/monolog/commit/000a21969f0a57e829434a5e7de6498afe4bef48) Mark former public methods of SlackHandler as deprecated - [`862c087`](https://github.com/Seldaek/monolog/commit/862c0875d2b2ef2b690e074926ebe72a5cb0ec17) Expose a getter for the SlackRecord in Slack handlers - [`2d1fbbe`](https://github.com/Seldaek/monolog/commit/2d1fbbe4232a5070f1b60b33a238a614a4a3b385) Make SlackRecord::stringify() work without a line formatter - [`7c2f58e`](https://github.com/Seldaek/monolog/commit/7c2f58e7aa09e8aee2c000432ca086ebdc4452a0) Add initial tests for SlackRecord ### 📊 Changes **9 files changed** (+1001 additions, -158 deletions) <details> <summary>View changed files</summary> 📝 `doc/02-handlers-formatters-processors.md` (+3 -1) ➕ `src/Monolog/Handler/Slack/SlackRecord.php` (+248 -0) 📝 `src/Monolog/Handler/SlackHandler.php` (+51 -144) ➕ `src/Monolog/Handler/SlackWebhookHandler.php` (+108 -0) ➕ `src/Monolog/Handler/SlackbotHandler.php` (+80 -0) ➕ `tests/Monolog/Handler/Slack/SlackRecordTest.php` (+341 -0) 📝 `tests/Monolog/Handler/SlackHandlerTest.php` (+17 -13) ➕ `tests/Monolog/Handler/SlackWebhookHandlerTest.php` (+106 -0) ➕ `tests/Monolog/Handler/SlackbotHandlerTest.php` (+47 -0) </details> ### 📄 Description See https://github.com/Seldaek/monolog/issues/743#issuecomment-242994019 This is keeping the previous `SlackHandler`, but extracts the message formatting logic and introduces two new Slack handlers: - `SlackbotHandler` - this is the simplest way to log to Slack and most people could use that. It doesn't allow fancy formatting, but has autolinking and the simplest configuration with two clicks in the Slack settings and getting a token. - `SlackWebhookHandler` - This is a bit more advanced as it allows for the same formatting and adding attachements as the `SlackHandler`, but it uses the Slack Webhooks which are quite easier to set up than the OAuth API. The minimum it requires is a webhook URL which is a retrievable with about two clicks in the Slack settings. Even the channel is optional as it could be configured in the integration. This is probably not the leanest way to implement what we've discussed in https://github.com/Seldaek/monolog/issues/743, but after working at this I believe this is the simplest and the right approach. While we could implement everything in one handler the API would become horrible and it would be harder to understand from users. Providing choice with simple to use separate classes is better IMHO. Apart from this the `SlackHandler` extends the `SocketHandler` and the webhooks and the Slackbot wouldn't work nicely with that. What do you think? @Seldaek @gkedzierski @Gummibeer @nisbeti --- - [x] Extracting Slack formatting logic in `SlackRecord` - [x] `SlackbotHandler` - [x] `SlackWebhookHandler` - [x] Refactor `SlackHandler` using the new `SlackRecord` - [x] Add new handlers to the docs - [x] Unit tests of `SlackRecord` - [x] Unit tests for `SlackbotHandler` - [x] Unit tests for `SlackWebhookHandler` - [x] Update unit tests for `SlackHandler` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 03:11:17 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#1379
No description provided.