@thzero/library_server_messaging_slack
v0.19.1
Published
  [ - Invite the bot to each channel you intend to post to —
chat.postMessagefails withnot_in_channelotherwise
Installation
npm install @thzero/library_server_messaging_slackPeer dependencies
@thzero/library_common@thzero/library_common_service@thzero/library_server
What it provides
index.js — default export MessagingService, extending Service.
| Method | Purpose |
|---|---|
| init(injector) | Reads the token from config and builds the WebClient. A failure here is logged, not thrown — the service stays constructed but unusable. |
| message(correlationId, channel, message) | Posts message to channel via chat.postMessage. Returns a success response, or an error response carrying the correlationId when Slack rejects it. |
message never throws. A Slack outage produces a failed response and a logged exception rather than taking down the caller.
Configuration
{
"app": {
"messaging": {
"slack": {
"token": "xoxb-<bot user oauth token>"
}
}
}
}Keep the token out of source control — supply it from an environment variable through config/custom-environment-variables.json, the same way the database connection is handled.
Wiring it up
Register it with the injector from _initServices in your BootMain derived class, or from a boot plugin's initServices, then resolve it where you need it:
const serviceMessaging = injector.getService(AppConstants.InjectorKeys.SERVICE_MESSAGING_SLACK);
await serviceMessaging.message(correlationId, '#ops', `Deploy ${version} completed.`);channel accepts either a channel name (#ops) or a channel ID (C0123456789). An ID is more robust — a renamed channel keeps its ID.
Development
npm run lint # eslint .
npm run lint:fix # eslint . --fix
npm test # node --test "test/*.test.js"
