
內容簡介
這個外掛可以整合 WordPress 和 Slack。
核心概念
預設情況下,這個外掛什麼都不會做。沒錯。
Slack 有許多 API 整合,但這個外掛僅使用其中三種。
使用 Incoming Webhook 發送訊息到 Slack。
使用 Outgoing Webhook 從 Slack 請求資料。
使用 Custom Bot 與 Slack 互動。
使用 Sending Invitation 邀請現有的使用者(注意:這是非官方的 API 使用方法)。
也就是說,這個外掛幫助連結 Slack 和 WordPress,讓你專注於該做的任務。
使用情境
以下是我們在 WordPress 使用時的一些使用案例:
當某篇文章等待審核時,使用簡單通知功能貼文於 Slack。
每週將 Google Analytics 的存取摘要發布到 Slack 上,在工作夥伴無法進入 Google Analytics 的情況下仍使他們掌握進度。
使用轉換 Slack 對話至單一文章,並創建訪問文章。
如需更詳細資訊,請閱讀文件。我們有一些範例供參考。
整合方法
最簡單的使用方法是將內容張貼到 Slack。你可以像下面這樣使用:
do_action( 'hameslack', $text_to_post, $attachments, $channel );
也可以使用函數,但我更傾向使用 do_action,以避免煩人的 if ( function_exists('func_name'))。
只要正確設定,就一切正常。
安裝
從外掛庫安裝
點擊安裝並啟用。
從 Github 安裝
下載並使用。 欢迎提出任何合并请求。
輸入 API 金鑰
至少需要 Slack Payload URL for Incoming Webhooks。如需更詳細資訊,請前往我們的支援網站。
進行操作
如前所述,這個外掛預設情況下什麼都不會做。如需更多資訊,請閱讀我們的文件。
如果您有任何需求,請在GitHub 的專案中提出。
外掛標籤
開發者團隊
原文外掛簡介
This plugin integrates Slack and WordPress.
Core Conception
By default, this plugin does nothing. It’s true.
Slack has many API integration, but hameslack uses 2 of them.
Incoming Webhook to post to slack.
Slack App to interact with slack.
Upper is easier. This plugin helps the connection between Slack and WordPress and you can concentrate on what you should do with slack.
Use Cases
Here is a list of use case of us on WordPress with many editors.
Easy Post notification to slack if some post is awaiting review.
Difficult Post access summary to slack once a week, because my colleague doesn’t open Google Analytics.
Very Difficult Convert slack conversation to single post and make interview post.
For more details, please read the Addons documentation.
How to Integrate
The simplest usage is post to slack. You can do like below:
do_action( 'hameslack', $text_to_post, $attachments, $channel );
Function hameslack_post( $content, $attachment, $channel ) is also available, but I prefer to use do_action to avoid annoying if ( function_exists('func_name')).
Everything works fine if you set properly.
Deprecated API
Sending Invitation deprecated at 2.0: this endpoint was unofficial and official one is only for Enterprise grid. Users now can send invitation reqeust from their profile page.
Outgoind Webhook deprecated at 2.0: Slack recommends Events API instead.
Install
From Plugin Repository
Click install and activate it.
From GitHub
Download from Releases and you can use it. Any pull requests are welcomed.
Enter Credentials
To post a message to slack, you need Payload URL. Create an app and activate “Incoming Webhooks”.
Now you can get payload URL.
To get Bot Token, go to “OAuth & Permissions”. By installing your app to your workspace, Bot token will be generated.
Do something
As mentioned above, this plugin does nothing by default. Enable built-in addons from the settings page, or read the Addons documentation to write your own.
If you have any request, please make issue on github.
Development
This plugin requires custom code to work with your Slack workspace. Here’s how to set up a local development environment.
Prerequisites
Node.js >= 22 (managed via Volta)
Docker Desktop (for wp-env)
cloudflared (for Slack Webhook testing)
Getting Started
Install dependenciesnpm install
composer installStart WordPress local environmentnpm startBuild assetsnpm run packageWatch for changes during developmentnpm run watch
Receiving Slack Webhooks Locally
Slack requires a public HTTPS URL for Event Subscriptions and Interactive Components. Use Cloudflare Tunnel to expose your local environment:
In a separate terminal, start the tunnelnpm run tunnel
This gives you a temporary public URL like https://random-name.trycloudflare.com. Then:
Go to your Slack App settings
Update Event Subscriptions Request URL to https://random-name.trycloudflare.com/wp-json/hameslack/v1/...
Update Interactivity & Shortcuts Request URL similarly
The URL changes each time you restart the tunnel
Note: Make sure WordPress permalink settings are not set to “Plain” — pretty permalinks are required for /wp-json/ to work through the tunnel.
NPM Scripts
Command
Description
npm start
Start wp-env
npm run package
Build all assets (CSS + JS)
npm run watch
Watch for file changes
npm run tunnel
Open Cloudflare Tunnel to localhost:8888
npm run lint
Run ESLint + Stylelint
npm run fix
Auto-fix lint errors
npm test
Run PHPUnit tests
