{"id":15714483,"url":"https://github.com/zspecza/slock","last_synced_at":"2025-10-25T11:45:39.688Z","repository":{"id":57155303,"uuid":"41855067","full_name":"zspecza/slock","owner":"zspecza","description":"under construction","archived":false,"fork":false,"pushed_at":"2016-11-09T08:39:04.000Z","size":41,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-12T23:49:33.739Z","etag":null,"topics":[],"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/zspecza.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-03T10:55:02.000Z","updated_at":"2016-03-02T17:11:03.000Z","dependencies_parsed_at":"2022-08-26T09:50:07.950Z","dependency_job_id":null,"html_url":"https://github.com/zspecza/slock","commit_stats":null,"previous_names":["declandewet/slack-frp","declandewet/slock"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Fslock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Fslock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Fslock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Fslock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zspecza","download_url":"https://codeload.github.com/zspecza/slock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843167,"owners_count":21972868,"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":[],"created_at":"2024-10-03T21:37:32.871Z","updated_at":"2025-10-25T11:45:39.590Z","avatar_url":"https://github.com/zspecza.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n![slock logo](http://imgh.us/slock-logo_2.svg)\n\u003e Slock is not affiliated with or endorsed by Slack in any way\n\nInfo | Badges\n-----|-------\nVersion | [![github release](https://img.shields.io/github/release/declandewet/slock.svg?style=flat-square)](https://github.com/declandewet/slock/releases/latest) [![npm version](https://img.shields.io/npm/v/slock.svg?style=flat-square)](http://npmjs.org/package/slock)\nLicense | [![npm license](https://img.shields.io/npm/l/slock.svg?style=flat-square)](https://github.com/declandewet/slock/blob/master/license.md)\nPopularity | [![npm downloads](https://img.shields.io/npm/dm/slock.svg?style=flat-square)](http://npm-stat.com/charts.html?package=slock)\nTesting | [![build status](https://img.shields.io/travis/declandewet/slock.svg?style=flat-square)](https://travis-ci.org/declandewet/slock) [![test coverage](https://img.shields.io/coveralls/declandewet/slock.svg?style=flat-square)](https://coveralls.io/github/declandewet/slock)\nQuality | [![dependency status](https://img.shields.io/david/declandewet/slock.svg?style=flat-square)](https://david-dm.org/declandewet/slock) [![dev dependency status](https://img.shields.io/david/dev/declandewet/slock.svg?style=flat-square)](https://david-dm.org/declandewet/slock#info=devDependencies)\nHelp/Community | [![Join the chat at https://gitter.im/declandewet/slock](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/declandewet/slock?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nSlock\n---------\n\n\u003e **Note** this module is in _extremely_ early development. There are no\n\u003e tests yet, documentation is missing and\n\u003e [versioning might be a little different](http://markup.im/#q4_cRZ1Q).\n\u003e So don't use this in production at the moment - but feel free to play with it!\n\nSlock is a Node.js module for working with the various Slack APIs, built atop\nfunctional reactive programming principles.\n\nThe benefit of using functional reactive programming for such\na library means that events can be `filter`ed, `map`ped, `reduce`ed,\nand so on - just like arrays!\n\nFunctional Reactive code can also be very expressive while still remaining\nterse, and this makes maintainability an absolute dream.\n\nInstallation\n============\n\nSlock can be installed by executing the following command in a terminal:\n\n```\nnpm install slock --save\n```\n\nUsage\n==========\n\nSlock tries to be as inexplicit as possible, and as such doesn't require\nmuch of a learning curve (even if functional reactive programming, observables\nand EventStreams are not quite your strong point).\n\nEvery event and method correlates directly to the events and methods listed\non the Slack API documentation site, so if those docs expect a payload,\njust call the relevant method with the expected payload as a regular JS object.\n\nLet's get started building a realtime bot that echoes out what users say.\n\nFirst thing's first - we have to connect to the Slack API by passing in\nour bot's API token.\n\n```js\n// import the module\nvar Slack = require('slock');\n\n// give it our token\nvar slack = new Slack('insert api token here');\n```\n\nThat was pretty simple and straightforward - but now we need to connect to\nthe RTM API. Simple enough:\n\n```js\nslack.connect();\n```\n\nBoom. How's about we post a message to Slack letting users know we've connected?\n\n```js\nslack.connect()\n  .onValue(function(response) {\n    slack.chat.postMessage({\n      text: \"Hello! I'm now active on your team.\",\n      channel: \"#general\"\n    });\n  });\n```\n\nNow, for the logic that echoes out what users say...\n\n```js\nslack.events.message\n  .filter(function(message) {\n    return ~message.text.indexOf('bot echo');\n  })\n  .onValue(function(message) {\n    var echo = message.text.split('bot echo ')[1];\n    slack.chat.postMessage({\n      text: echo,\n      channel: message.channel\n    })\n  });\n```\n\nPutting it all together, we have something that looks like this:\n\n```js\n// import the module\nvar Slack = require('slock');\n\n// give it our token\nvar slack = new Slack('insert api token here');\n\nslack.events.message\n  .filter(function(message) {\n    return ~message.text.indexOf('bot echo');\n  })\n  .onValue(function(message) {\n    var echo = message.text.split('bot echo ')[1];\n    slack.chat.postMessage({\n      text: echo,\n      channel: message.channel\n    })\n  });\n\nslack.connect()\n  .onValue(function(response) {\n    slack.chat.postMessage({\n      text: \"Hello! I'm now active on your team.\",\n      channel: \"#general\"\n    });\n  });\n```\n\nAs you can see, the methods are fairly straightforward.\n\nAny time you want to get access to a Slack RTM event, just\ncall `slack.events.\u003cevent type\u003e`.\n[Here's a list of all of them](https://api.slack.com/rtm).\n\nSimilarly, if you want to use a particular Slack Web API method, just\ncall `slack.\u003cname of method group\u003e.\u003cname of method\u003e`, so if you\nwanted to post a message, it'd be `slack.chat.postMessage`. If you\nwant to add a reaction, call `slack.reactions.add`.\n[Here's a list of all the methods](https://api.slack.com/methods) you can call.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzspecza%2Fslock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzspecza%2Fslock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzspecza%2Fslock/lists"}