{"id":13990017,"url":"https://github.com/magnetikonline/slack-post","last_synced_at":"2025-04-28T16:12:27.561Z","repository":{"id":56406884,"uuid":"41625367","full_name":"magnetikonline/slack-post","owner":"magnetikonline","description":"Node.js module for sending posts to Slack via the incoming webhooks API. Supports both simple and advanced messaging formats.","archived":false,"fork":false,"pushed_at":"2024-05-10T02:25:59.000Z","size":26,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-28T16:12:21.773Z","etag":null,"topics":["chat","npm-package","slack"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/slackpost","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magnetikonline.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-30T11:00:17.000Z","updated_at":"2024-05-10T02:26:02.000Z","dependencies_parsed_at":"2024-08-09T13:21:18.459Z","dependency_job_id":null,"html_url":"https://github.com/magnetikonline/slack-post","commit_stats":null,"previous_names":["magnetikonline/slackpost"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fslack-post","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fslack-post/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fslack-post/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fslack-post/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magnetikonline","download_url":"https://codeload.github.com/magnetikonline/slack-post/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251342725,"owners_count":21574245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat","npm-package","slack"],"created_at":"2024-08-09T13:02:16.745Z","updated_at":"2025-04-28T16:12:27.541Z","avatar_url":"https://github.com/magnetikonline.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Slack Post\nNode.js module for sending posts to [Slack](https://slack.com/) via the [incoming webhooks API](https://api.slack.com/incoming-webhooks). Supports both simple and advanced messaging formats.\n\n[![NPM](https://nodei.co/npm/slackpost.png?downloads=true)](https://nodei.co/npm/slackpost/)\n\nAn existing incoming webhook integration will be required and can be created via the [Slack administration system](https://my.slack.com/services/new/incoming-webhook/) to successfully use this module.\n\nFor further API details refer to the [Incoming Webhooks](https://api.slack.com/incoming-webhooks) and [Message Attachments (advanced messaging)](https://api.slack.com/docs/message-attachments) documents.\n\n- [Methods](#methods)\n\t- [slackPost.post(webhookURL,postText)](#slackpostpostwebhookurlposttext)\n\t- [slackPost.setUsername(name)](#slackpostsetusernamename)\n\t- [slackPost.setChannel(channel)](#slackpostsetchannelchannel)\n\t- [slackPost.setIconEmoji(iconEmoji)](#slackpostseticonemojiiconemoji)\n\t- [slackPost.setIconURL(iconURL)](#slackpostseticonurliconurl)\n\t- [slackPost.enableUnfurlLinks()](#slackpostenableunfurllinks)\n\t- [slackPost.disableMarkdown()](#slackpostdisablemarkdown)\n\t- [slackPost.setColor(color)](#slackpostsetcolorcolor)\n\t- [slackPost.setPreText(preText[,enableMarkdown])](#slackpostsetpretextpretextenablemarkdown)\n\t- [slackPost.setAuthor(name[,authorURL][,iconURL])](#slackpostsetauthornameauthorurliconurl)\n\t- [slackPost.setTitle(title[,URL])](#slackpostsettitletitleurl)\n\t- [slackPost.setRichText(richText[,enableMarkdown])](#slackpostsetrichtextrichtextenablemarkdown)\n\t- [slackPost.addField(title,value[,isShort])](#slackpostaddfieldtitlevalueisshort)\n\t- [slackPost.enableFieldMarkdown()](#slackpostenablefieldmarkdown)\n\t- [slackPost.setThumbnail(URL)](#slackpostsetthumbnailurl)\n\t- [slackPost.setImage(URL)](#slackpostsetimageurl)\n\t- [slackPost.setFooter(text[,timestamp][,iconURL])](#slackpostsetfootertexttimestampiconurl)\n\t- [slackPost.send(callback)](#slackpostsendcallback)\n- [Example usage](#example-usage)\n\n## Methods\n\n### slackPost.post(webhookURL,postText)\n- Returns new `slackPost` message instance.\n- `webhookURL` must be in the format expected by the Slack administration integration endpoint - method will throw an error if web hook URL invalid.\n- `postText` is implemented as follows:\n\t- For simple messages (text posts) this will be the message text.\n\t- For [advanced messages](https://api.slack.com/docs/message-attachments) will be used as the fall back text for scenarios where advanced rendering is unsupported.\n\nExample:\n\n```js\nlet slackPost = require('slackpost');\n\nlet myNewPost = slackPost.post(\n\t'https://hooks.slack.com/services/ABCDEF012/012345ABC/fjdke456HRekdftFOGRPh21s',\n\t'Hello, HAL. Do you read me, HAL?'\n);\n```\n\n### slackPost.setUsername(name)\n- Override default username for the incoming webhook.\n- Returns `slackPost` instance.\n\n### slackPost.setChannel(channel)\n- Override default target channel for the incoming webhook with either:\n\t- An alternative channel.\n\t- Direct message Slack username.\n- Format must be one of `#channel` or `@username`, anything else will throw an error.\n- Returns `slackPost` instance.\n\n### slackPost.setIconEmoji(iconEmoji)\n- Override default icon for incoming webhook with a defined emoji.\n- Provide desired emoji name _without_ leading/trailing `:` characters.\n- Returns `slackPost` instance.\n\nExample:\n\n```js\nlet slackPost = require('slackpost');\n\nlet myNewPost = slackPost.post(WEBHOOK_URL,'Message');\n\n// set the post icon to \":chicken:\"\nmyNewPost.setIconEmoji('chicken');\n```\n\n### slackPost.setIconURL(iconURL)\n- Override the default icon for incoming webhook with a public image URL.\n- Returns `slackPost` instance.\n\n### slackPost.enableUnfurlLinks()\n- When enabled, Slack will automatically attempt to extract and display summarized details for URLs within the post content.\n- By default URLs referenced in posts made by an incoming webhook will _not_ be unfurled - unless they are deemed [media content links](https://api.slack.com/docs/message-attachments#unfurling).\n- Returns `slackPost` instance.\n\n### slackPost.disableMarkdown()\n- When disabled, Slack will avoid marking up post text with Markdown-like syntax.\n- Method applies only to the _simple message format_, which by default is automatically marked up.\n- Returns `slackPost` instance.\n\n### slackPost.setColor(color)\n- Sets left hand border color for advanced message format posts.\n- Given `color` is either a HTML color code (e.g. `#439fe0`) or one of `good`, `warning` or `danger`.\n- Color names are also defined at `require('slackpost').COLOR_LIST`.\n- If `color` is `undefined` then `GOOD` will be used by default.\n- Returns `slackPost` instance.\n\nExample:\n\n```js\nlet slackPost = require('slackpost');\n\nlet myNewPost = slackPost.post(WEBHOOK_URL,'Message');\n\n// color options\nmyNewPost.setColor(slackPost.COLOR_LIST.GOOD);\nmyNewPost.setColor(slackPost.COLOR_LIST.WARNING);\nmyNewPost.setColor(slackPost.COLOR_LIST.DANGER);\nmyNewPost.setColor('#439fe0');\n```\n\n### slackPost.setPreText(preText[,enableMarkdown])\n- Set the optional text that appears above the advanced message block.\n- If `enableMarkdown` is true, will action Slack Markdown-like formatting of given `preText`.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\n### slackPost.setAuthor(name[,authorURL][,iconURL])\n- Sets a small display section at the top of the message for the post author.\n- Optional `authorURL` allows setting of a URL for the author (will link both the `name` and `iconURL` within the rendered Slack post).\n- Optional `iconURL` will set a small 16x16px image to the left of the author `name`.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\n### slackPost.setTitle(title[,URL])\n- Sets a `title`, in bold text near the top of the message area.\n- Optional `URL` allows for the title to be hyperlinked.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\n### slackPost.setRichText(richText[,enableMarkdown])\n- Sets the `richText` (main text) for an advanced message post.\n\t- Content will automatically collapse if it contains 700+ characters or 5+ linebreaks, and will display a \"Show more...\" link to expand the content.\n- If `enableMarkdown` is true, will action Slack Markdown-like formatting of given `richText`.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\n### slackPost.addField(title,value[,isShort])\n- Adds message meta data in a tabular format at the footer of the message area. Method can be called multiple times to add multiple field items to the rendered table.\n- Optional `isShort` boolean controls if field data is considered short enough to allow side-by-side tabular display with the following/next field item, otherwise field `title`/`value` will consume its own full table row.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\nExample:\n\n```js\nlet slackPost = require('slackpost');\n\nlet myNewPost = slackPost.post(WEBHOOK_URL,'Message');\n\n// add some fields - Name and Company will appear side-by-side\nmyNewPost.addField('Name','Don Draper',true);\nmyNewPost.addField('Company','Sterling Cooper',true);\n\n// Job title field will appear on its own row\nmyNewPost.addField('Job title','Creative Director');\n```\n\n### slackPost.enableFieldMarkdown()\n- When called, will action Slack to markup field item values added via [`slackPost.addField()`](#slackpostaddfieldtitlevalueisshort) with Markdown-like syntax.\n- Method only applies to the advanced message format with one or more fields created.\n- Returns `slackPost` instance.\n\n### slackPost.setThumbnail(URL)\n- Provides a public URL to an image that will be displayed as a thumbnail to the right of an advanced message.\n- Image formats of GIF, JPEG, PNG and BMP are supported.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\n### slackPost.setImage(URL)\n- Provides a public URL to an image that will be displayed as an image inside the message area.\n- Image formats of GIF, JPEG, PNG and BMP are supported.\n- Large images will be resized to a maximum width of 400px or a maximum height of 500px - whilst maintaining aspect ratio.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\n### slackPost.setFooter(text[,timestamp][,iconURL])\n- Adds brief text to contextualize and identify referenced post content.\n- Optional `timestamp` provided as a [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time) will display a reference date/time to the right of the footer credit.\n- Optional `iconURL` will set a small 16x16px image to the left of the footer `text`.\n- When called will enable the advanced message format.\n- Returns `slackPost` instance.\n\n### slackPost.send(callback)\n- Sends a composed message, using the methods presented above to the Slack incoming webhook API endpoint.\n- `callback` is a function, receiving exactly one argument:\n\t- Upon success argument will be `null`.\n\t- In case of error, argument will be an instance of `Error()`.\n\n## Example usage\nSending a simple message:\n\n```js\nlet slackPost = require('slackpost');\n\nlet simpleMsg = slackPost.post(\n\t'https://hooks.slack.com/services/ABCDEF012/012345ABC/fjdke456HRekdftFOGRPh21s',\n\t'Hello, HAL. Do you read me, HAL?'\n);\n\nsimpleMsg\n\t.setUsername('HAL9000')\n\t.setChannel('#spaceship')\n\t.enableUnfurlLinks()\n\t.disableMarkdown();\n\nsimpleMsg.send((err) =\u003e {\n\n\tif (err) {\n\t\t// error sending message to Slack API\n\t\tconsole.dir(err);\n\t\treturn;\n\t}\n\n\t// success!\n});\n```\n\nSending an advanced message:\n\n```js\nlet slackPost = require('slackpost');\n\nlet advancedMsg = slackPost.post(\n\t'https://hooks.slack.com/services/ABCDEF012/012345ABC/fjdke456HRekdftFOGRPh21s',\n\t'This is my fallback text for mobile notifications and IRC users/etc.'\n);\n\nadvancedMsg\n\t.setUsername('magnetik')\n\t.setChannel('@alexandra')\n\t.setColor(slackPost.COLOR_LIST.WARNING)\n\t.setAuthor(\n\t\t'Peter Mescalchin',\n\t\t'http://magnetikonline.com'\n\t)\n\t.setRichText('This is some *rich-text* messaging!',true);\n\nadvancedMsg.send((err) =\u003e {\n\n\tif (err) {\n\t\t// error sending message to Slack API\n\t\tconsole.dir(err);\n\t\treturn;\n\t}\n\n\t// success!\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetikonline%2Fslack-post","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagnetikonline%2Fslack-post","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetikonline%2Fslack-post/lists"}