{"id":18571833,"url":"https://github.com/johnagan/tinyspeck","last_synced_at":"2025-04-10T07:30:43.917Z","repository":{"id":66093413,"uuid":"64564467","full_name":"johnagan/tinyspeck","owner":"johnagan","description":"A lightweight adapter for node.js to interact with Slack's Web and RTM APIs","archived":false,"fork":false,"pushed_at":"2018-06-17T12:28:48.000Z","size":40,"stargazers_count":39,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-26T22:03:25.519Z","etag":null,"topics":["client","node","rtm","slack","tinyspeck","websockets"],"latest_commit_sha":null,"homepage":"","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/johnagan.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":"2016-07-30T21:17:35.000Z","updated_at":"2024-06-19T22:51:10.736Z","dependencies_parsed_at":"2023-07-20T23:30:45.131Z","dependency_job_id":null,"html_url":"https://github.com/johnagan/tinyspeck","commit_stats":{"total_commits":63,"total_committers":4,"mean_commits":15.75,"dds":"0.46031746031746035","last_synced_commit":"d4ccf021e447dbfa84d8d0b5c1a86eb80c639492"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Ftinyspeck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Ftinyspeck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Ftinyspeck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Ftinyspeck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnagan","download_url":"https://codeload.github.com/johnagan/tinyspeck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223281460,"owners_count":17119111,"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":["client","node","rtm","slack","tinyspeck","websockets"],"created_at":"2024-11-06T23:03:55.315Z","updated_at":"2024-11-06T23:03:55.866Z","avatar_url":"https://github.com/johnagan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinySpeck\n\nA lightweight adapter for node.js to interact with Slack's Web and RTM APIs.\n\n## Usage\n* [Installation](#install)\n* [Sending Data](#sending-data)\n  * [Posting Messages](#posting-messages)\n  * [Updated Messages](#updating-messages)\n  * [Respond to WebHooks](#respond-to-webhooks)\n  * [Calling Other API Methods](#calling-other-api-methods)\n* [Instances](#creating-an-instance)\n* [Events](#events)\n* [RTM](#rtm)\n* [WebServer](#webserver)\n* [WebSockets Proxy](#websocket-proxy)\n\n## Install\n```\nnpm i tinyspeck --save\n```\n\n## Sending Data\nThe TinySpeck client is a minimal wrapper around Slack's Web API Web. The default action is sending messages.\n\n### Posting Messages\nThe `send` method defaults to calling [`chat.postMessage`](https://api.slack.com/methods/chat.postMessage).\n```js\nconst slack = require('tinyspeck')\n\nlet message = {\n  unfurl_links: true,\n  channel: 'C1QD223DS1',\n  token: 'xoxb-12345678900-ABCD1234567890',\n  text: \"I am a test message http://slack.com\",\n  attachments: [{\n    text: \"And here's an attachment!\"\n  }]\n}\n\n// send message defaults to calling chat.postMessage\nslack.send(message).then(data =\u003e {\n  // Success!\n})\n```\n\n### Updating Messages\nIf your messages includes an `ts` property, it will call [`chat.update`](https://api.slack.com/methods/chat.update) instead.\n\n```js\nlet message = {\n  ts: \"123422342134.234\",\n  channel: 'C1QD223DS1',\n  token: 'xoxb-12345678900-ABCD1234567890',\n  text: \"Updated Message!!\"\n}\n\ninstance.send(message)\n```\n\n### Respond to WebHooks\nTo respond to response urls, pass the url in place of a method name.\n```js\n// respond to webhooks\nslack.send('https://hooks.slack.com/services/T0000/B000/XXXX', message)\n```\n\n### Calling Other API Methods\nAccess any of Slack's [API Methods](https://api.slack.com/methods) by passing in the method name.\n```js\nlet message = {\n  token: 'xoxb-12345678900-ABCD1234567890'\n}\n\n// pass in the method name to call\nslack.send('auth.test', message).then(data =\u003e {\n  // Success!\n})\n```\n\n## Creating an Instance\nUse to create a new instance of TinySpeck with a custom defaults\n\n```js\n// create an instance with defaults\nlet instance = slack.instance({\n  unfurl_links: true,\n  channel: 'C1QD223DS1',\n  token: 'xoxb-12345678900-ABCD1234567890'  \n})\n\nlet message = {\n  text: \"I am a test message http://slack.com\",\n  attachments: [{\n    text: \"And here's an attachment!\"\n  }]\n}\n\n// send message to any Slack endpoint\ninstance.send('chat.postMessage', message)\n```\n\n## Events\nEvent handlers that are triggered when messages are received from Slack.\n\n```js\n// usage\nslack.on('event name', [... 'event name',] callback)\n\n// handle the \"/test\" slash commands\nslack.on('/test', message =\u003e { })\n\n// handle all slash commands\nslack.on('slash_command', message =\u003e { })\n\n// handle the outgoing webhooks trigger word \"googlebot\"\nslack.on('googlebot', message =\u003e { })\n\n// handle multiple events\nslack.on('googlebot', '/test', 'slash_commands', message =\u003e { })\n\n// wildcard support\nslack.on('*', message =\u003e { })\n```\n\n\n\n## RTM\nCreates a connection to Slack's RTM API.\n```js\n// options to pass to rtm.start\nslack.rtm({ options }) // returns a promise\n\n// basic\nslack.rtm({ token: 'xoxb-12345678900-ABCD1234567890' }).then(ws =\u003e {    \n  // connected are the websock is returned\n})\n\n// with defaults\nlet instance = slack.instance({\n  token: 'xoxb-12345678900-ABCD1234567890'  \n})\n\ninstance.rtm()\n```\n\n## WebServer\nA simple http server to receive JSON posts from Slack's WebHooks or Events.\n\n```js\n// usage\nslack.listen(port, 'validation token (optional)')\n\n// example\nslack.listen(3000, 'gIkuvaNzQIHg97ATvDxqgjtO')\n```\n\n## WebSocket Proxy\nTinySpeck can act as a WebSocket proxy, forwarding requests from Slack's HTTP POSTS to an open WebSocket connection and back. Because this will be an open connection, it will require a querystring verification to connect to.\n\n### Using Verification Token To Authenticate\nPassing in `true` to the third parameter of `listen` will enable WebSockets using the Slack's Verification Token for authentication.\n\n#### Server\n```js\nslack.listen(3000, 'gIkuvaNzQIHg97ATvDxqgjtO', true)\n```\n\n#### Client\n```js\nconst WebSocket = require('ws')\nconst ws = new WebSocket('ws://yourserver.com?token=qtGI5L0SXbtiQfPY53UhkSIs');\n```\n\n### Customizing Token and Parameters\nIf you would like more control over the token and parameter, you can call `proxy` after calling `listen` and provide custom values.\n\n#### Server\n```js\nlet server = slack.listen(3000, 'gIkuvaNzQIHg97ATvDxqgjtO')\nlet proxy = slack.proxy(server, \"CUSTOM_TOKEN\", \"custom_param\")\n```\n\n#### Client\n```js\nconst WebSocket = require('ws')\nconst ws = new WebSocket('ws://yourserver.com?custom_param=CUSTOM_TOKEN');\n```\n\n### Sending Messages Over WebSockets\nSending messages over the websocket will call the [`send method`](#calling-api-methods) and pass through your message to `chat.postMessage`.\n\n#### Client\n```js\nconst WebSocket = require('ws')\nconst ws = new WebSocket('ws://yourserver.com?token=qtGI5L0SXbtiQfPY53UhkSIs');\n\nlet message = {\n  unfurl_links: true,\n  channel: 'C1QD223DS1',\n  token: 'xoxb-12345678900-ABCD1234567890',\n  text: \"I am a test message http://slack.com\",\n  attachments: [{\n    text: \"And here's an attachment!\"\n  }]\n}\n\nws.send( JSON.stringify(message) )\n```\n\n### Calling Other Methods\nIf you wanted to call another Slack API method, you can include the `method` property to your message object and it will all that method instead.\n\n#### Client\n```js\nlet message = {\n  method: 'auth.test',\n  token: 'xoxb-12345678900-ABCD1234567890'\n}\n\nws.send( JSON.stringify(message) )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnagan%2Ftinyspeck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnagan%2Ftinyspeck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnagan%2Ftinyspeck/lists"}