{"id":20285431,"url":"https://github.com/mramshaw/gcp-slackbot","last_synced_at":"2025-04-11T08:39:03.679Z","repository":{"id":42387228,"uuid":"99662746","full_name":"mramshaw/GCP-Slackbot","owner":"mramshaw","description":"Building a Slack Bot with Node.js Microservices","archived":false,"fork":false,"pushed_at":"2024-07-03T05:59:59.000Z","size":265,"stargazers_count":3,"open_issues_count":11,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T06:11:16.355Z","etag":null,"topics":["express","gcp","microservices","natural-language-processing","natural-language-understanding","nlp","nodejs","npm","rtm","slack","slackbot","superagent","websockets"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mramshaw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-08-08T07:18:53.000Z","updated_at":"2020-12-09T17:25:25.000Z","dependencies_parsed_at":"2024-02-03T03:26:03.531Z","dependency_job_id":"5168af18-40ec-450c-91fb-f628a747cc87","html_url":"https://github.com/mramshaw/GCP-Slackbot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FGCP-Slackbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FGCP-Slackbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FGCP-Slackbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FGCP-Slackbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mramshaw","download_url":"https://codeload.github.com/mramshaw/GCP-Slackbot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248362189,"owners_count":21091065,"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":["express","gcp","microservices","natural-language-processing","natural-language-understanding","nlp","nodejs","npm","rtm","slack","slackbot","superagent","websockets"],"created_at":"2024-11-14T14:26:39.699Z","updated_at":"2025-04-11T08:39:03.661Z","avatar_url":"https://github.com/mramshaw.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Building a Slack Bot with Node.js Microservices\n\nThis was a fun exercise, I learned a little bit about __Slack__ as well as quite a lot about __NLP__ (Natural-language processing).\n\n![GCP Slackbot](./images/GCP_Slackbot.png)\n\n## Index\n\nThe contents are as follows:\n\n* [NLP](#nlp)\n* [Requirements](#requirements)\n* [Node.js](#nodejs)\n* [Slack](#slack)\n* [Wit](#wit)\n    * [Time](#time)\n    * [Weather](#weather)\n* [Slack and Wit Secrets](#slack-and-wit-secrets)\n* [Time Service](#time-service)\n    * [Google Secrets](#google-secrets)\n* [Weather Service](#weather-service)\n    * [OpenWeatherMap Secrets](#openweathermap-secrets)\n* [Privacy](#privacy)\n* [To Do](#to-do)\n* [Credits](#credits)\n\n## NLP\n\nLike a lot of people, I learned a certain amount of programming from the old text-based computer games.\n\nI knew that I had learned some __Basic__ and __Fortran__ there, also some __GMAP__ (an obscure assembly language,\nor - specifically - GCOS Macro Assembler Program). But I hadn't realized that I also learned about __NLP__:\n\n\tA threatening little dwarf bars your way. He throws an axe at you, but misses.\n\t\u003e kill dwarf\n\tI'm sorry, but I don't know how to do that. Perhaps there is a weapon nearby?\n\t\u003e use axe\n\tYou don't have an axe!\n\t\u003e take axe\n\tOK\n\t\u003e use axe\n\tI'm sorry, but I don't know how to do that.\n\t\u003e throw axe\n\tYou missed!\n\t\u003e take axe\n\tOK\n\t\u003e throw axe\n\tYou missed!\n\n[If anyone is interested, this exchange occurred in the text-based game [Colossal Cave Adventure](http://gitlab.com/esr/open-adventure).]\n\nThings have changed in the many years that have elapsed since then, but I'm not sure they've changed all that much.\nThe slackbot we will implement here is very reminiscent of [__Eliza__](http://en.wikipedia.org/wiki/ELIZA) - which\nwas an early natural language processing program.\n\n## Requirements\n\nA __GitHub__ account will be needed, as well as a __Google Cloud Platform__ account.\n\n## Node.js\n\nThe __Node.js__ modules will use the [@slack/client](http://github.com/slackapi/node-slack-sdk), [express](http://www.npmjs.com/package/express),\n[superagent](http://www.npmjs.com/package/superagent) and [moment](http://www.npmjs.com/package/moment) frameworks.\n\n## Slack\n\nFor the __Slack__ portion, we will create a real-time messaging (RTM) client which will use __websockets__.\n\nWe will also create a _bot user_ in Slack. This will create a Slack token.\n\n## Wit\n\nWe will create and train a natural-language processing (NLP) client with __Wit.ai__.\n\nIn order to do this, it will be necessary to sign in with a __GitHub__ account.\n\nWe will need to train our client to recognize __Intents__ (I have been unable to find a good definition but broadly speaking the main concept of a question or statement.\n Intents will also be important for [AWS Alexa](http://github.com/mramshaw/Alexa-Stuff)).\n\nOnce our client has been trained, we will need to create a Wit token.\n\n#### Time\n\n![Time intent](./images/Time.png)\n\nSome sample questions to train the __time__ intent.\n\n#### Weather\n\n![Weather intent](./images/Weather.png)\n\nSome sample questions to train the __weather__ intent.\n\n## Slack and Wit Secrets\n\nWe will embed our Slack token and our Wit token in a __secrets.json__ file as follows:\n\n\t{\n\t    \"slackToken\" : \"xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\n\t    \"witToken\"   : \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\t}\n\n## Time Service\n\nTo determine the requested time, we will geolocate the location and then request its time offset.\n\nTo do this we will use Google's Geocoding API and Google's Timezone API.\n\nIt will be necessary to sign in with a __Google Cloud Platform__ account.\n\nGoogle's Geocoding documentation:\n\n\thttp://developers.google.com/maps/documentation/geocoding/start\n\nGoogle's Timezone documentation:\n\n\thttp://developers.google.com/maps/documentation/timezone/start\n\nThe tutorial recommends creating two API keys, one for each service however we will use the same key for both.\n\nWe will also restrict our GCP project to __only__ these two APIs:\n\n![Google APIs](./images/Google_APIs.png)\n\n#### Google Secrets\n\nWe will embed our Google token in a __secrets.json__ file as follows:\n\n\t{\n\t    \"googleToken\" : \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\t}\n\nThis file must be created in the __Iris-time__ directory. Note that this is not a valid token!\n\n## Weather Service\n\nTo determine the requested weather, we will use the OpenWeatherMap API.\n\n#### OpenWeatherMap Secrets\n\nWe will embed our OpenWeatherMap token in a __secrets.json__ file as follows:\n\n\t{\n\t    \"openWeatherMapToken\" : \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\t}\n\nThis file must be created in the __Iris-weather__ directory. Note that this is not a valid token!\n\n## Privacy\n\n[Wit.ai](http://wit.ai/) was acquired by [Facebook](http://www.facebook.com) in 2016.\n\nIf you are at all concerned about Facebook and their concern for user privacy or the uses to which Facebook puts its data,\n this might be something to bear in mind.\n\nWit.ai publishes its [privacy policy](http://wit.ai/privacy) and also has a [BLOG](http://wit.ai/blog).\n\nFacebook are the creators of [React](http://github.com/facebook/react) and [React native](http://github.com/facebook/react-native).\n\n## To Do\n\n- [x] Add a note about Wit.ai ownership and privacy policy\n- [x] Add links for express, superagent and moment frameworks\n- [ ] Replace console logging [`console.log(\"listening\");`] with either __util__ logging or a package like [bunyan](http://www.npmjs.com/package/bunyan) or [winston](http://www.npmjs.com/package/winston).\n- [ ] Check for duplicates from the Google Geocoding (Lat/Long) lookup and if found, request a more specific location.\n- [ ] Update the Service Registry to allow for proxies (currently assumes all services are directly reachable).\n- [ ] Update the Service Registry to more randomly return matching services for load-balancing purposes (rather than simply the first one that matches).\n- [ ] Update the Weather API service call to either use City ID or Lat/Long (from Google) instead of City Name.\n\n## Credits\n\nBased upon:\n\n\thttp://www.lynda.com/Node-js-tutorials/Building-Slack-Bot-Node-js-Microservices/509406-2.html\n\nThis tutorial is worth viewing for some great insight into how to structure the code in a __Node.js__ project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Fgcp-slackbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmramshaw%2Fgcp-slackbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Fgcp-slackbot/lists"}