Slack Webhook Sender
Slack's Incoming Webhooks are a plain POST of a JSON body to a per-channel URL, but a naive port of a Discord-style sender gets Slack wrong in two specific ways. First, Slack's rich formatting is Block Kit, a JSON array of typed block objects (header, section, divider, context), not a single flat text string - a message that only ever sends "text" looks noticeably plainer than what other tools post into the same channel. Second, Slack signals rate limiting with an HTTP "Retry-After" HEADER carrying whole seconds, not a JSON body field the way Discord's webhook does - code that only checks the response body for a retry hint never backs off correctly against Slack. This header fixes both. SwsBuildHeaderBlock/SwsBuildSectionBlock/ SwsBuildFieldsBlock/SwsBuildDividerBlock/SwsBuildContextBlock each build one real Block Kit object; SwsSendBlocks assembles them into a payload with the required plain-text fallback and posts it. SwsExtractHeaderValue does a case-insensitive scan of the raw response header block WebRequest hands back, and SwsPostJson uses it to read Retry-After on a 429, waits that many seconds (capped at 15 to bound any single retry), and retries up to three times total before giving up and returning a failed SwsSendResult rather than looping forever. Notes and limitations - WebRequest() only reaches hosts the terminal has explicitly whitelisted (Tools -> Options -> Expert Advisors). Every call fails with error 4060 until hooks.slack.com is added there - this is a terminal setting the library cannot configure for itself. - The rate-limit retry is bounded at three total attempts and a 15 second maximum single wait; a webhook that stays rate-limited or down longer than that returns a failed SwsSendResult rather than blocking further, and the caller should treat that as "try again next signal", not poll in a tight loop. - SwsBuildFieldsBlock supports up to Slack's own 10-field limit on a single section block; passing more simply renders however Slack's own API decides to handle the overflow - this header does not enforce the cap itself. - JSON building here is a hand-written escaper aimed at the specific shape of a Slack payload (text/blocks/fields), not a general JSON encoder - it correctly escapes the characters that matter for this use, not arbitrary structured data. - A webhook URL is a bearer credential in itself - anyone with the URL can post to the channel. Treat it like a password: keep it out of source control and out of screenshots.
Script · MT4 · v1.0 · Free
About Slack Webhook Sender
Slack Webhook Sender is a script for MetaTrader 4. It has 1 setting, such as Webhook url. MQL source code included.
Files in the download: SlackWebhookSender.mqh, SlackWebhookSender.txt, SlackWebhookSenderDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Webhook url | paste a real Slack Incoming Webhook URL to test a live send (leave blank to skip) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Channels & Envelopes · MT4 Script · MQL4 Source Code