{"id":17551081,"url":"https://github.com/ttu/office-slack-bot","last_synced_at":"2025-04-24T02:22:33.134Z","repository":{"id":44839093,"uuid":"75557645","full_name":"ttu/office-slack-bot","owner":"ttu","description":"BotKit Slack bot. Show free meeting rooms, book rooms (Google Calendar API) etc.","archived":false,"fork":false,"pushed_at":"2022-01-22T09:23:42.000Z","size":359,"stargazers_count":12,"open_issues_count":10,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T10:23:23.682Z","etag":null,"topics":["botkit","google-api","nodejs","slack"],"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/ttu.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}},"created_at":"2016-12-04T19:02:26.000Z","updated_at":"2024-07-03T15:57:04.000Z","dependencies_parsed_at":"2022-09-03T19:10:17.387Z","dependency_job_id":null,"html_url":"https://github.com/ttu/office-slack-bot","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/ttu%2Foffice-slack-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttu%2Foffice-slack-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttu%2Foffice-slack-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttu%2Foffice-slack-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ttu","download_url":"https://codeload.github.com/ttu/office-slack-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250546426,"owners_count":21448328,"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":["botkit","google-api","nodejs","slack"],"created_at":"2024-10-21T04:44:49.118Z","updated_at":"2025-04-24T02:22:33.117Z","avatar_url":"https://github.com/ttu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Slack Bot\n------------------------------\n\nSlack bot for office use.\n\n * Send a message anonymously\n * Is there anyone at the office\n * Office temperature\n * List free meeting rooms\n * List next meeting room reservations\n * Book a meeting room\n * Cancel a booking made with the SlackBot\n * Suggest a lunch place\n * Suggest a beer place\n * Send an email to a predefined address\n * Show current bitcoin price\n * Show current channel user activity statistics\n * Automatically translate conversation to selected language\n * WebScraping\n\n## Get Started\n\n1) Create new configuration file (_src/configuration.js_)\n    * Copy template from configuration file [section](https://github.com/ttu/office-slack-bot#configuration-file)\n1) Create a new App for your Slack workspace\n    * Add App's token to configuration's `botToken`\n1) Run bot e.g. with [forever](https://github.com/foreverjs/forever), supervisord etc.\n    * `$ forever start src/app.js`\n\n## Functionality\n\nBot sends a reply to the channel or to private chat where the command was sent from.\n\nSends exceptions and errors to the user defined in the configuration file (`slackAdminUserId`).\n\n#### Anonymous message\n\nAnonyous messages are sent to the home channel defined in the configuration file (`homeChannelId`)\n\n![Anonymous message](docs/anon.jpg \"Anonymous message\")\n\n#### Anyone at the office\n\nReturns _Office has people_ or _Office is empty_ message, depending if there is currently people at the office.\n\n`GET /api/haspeople/{id}` from [Sensordata API](https://github.com/ttu/sensordata-node-restapi) for all sensors in the configuration file. If any of the requests return true, then there is someone at the office.\n\n#### Get Temperture\n\nReturns lates sensors data for all sensors defined in the configuration file.\n\n`GET /api/data/{id}` from [Sensordata API](https://github.com/ttu/sensordata-node-restapi).\n\n```\n{\"name\":\"5krs\",\"temperature\":21.25,\"humidity\":23,\"noise\":47,\"light\":124,\"time\":\"11:47 19.01.\"}\n{\"name\":\"6krs\",\"temperature\":22.64,\"humidity\":23,\"noise\":45,\"light\":571,\"time\":\"11:47 19.01.\"}\n``` \n\n#### Free meeting rooms, current events \u0026 book a room\n\nFree meeting rooms shows a list of rooms that are free and duration how long they are available. Current events shows a list of next 2 events for each calendar defined in the configuration file. It will hide info from private events. Book a room makes a reservation for the next X minutes if that time is available. Bookings made with the SlackBot can also be cancelled by the same user.\n\n![Book a meeting room](docs/book.jpg \"Book a meeting room\")\n\nUses [Google Calendar API](https://developers.google.com/google-apps/calendar/v3/reference/). Meeting room calendars are defined in the configuration file. Booker info from [Slack User Info](https://api.slack.com/methods/users.info).\n\nRequirements:\n* Execute Step 1: Turn on the Google Calendar API from [quicksart](https://developers.google.com/google-apps/calendar/quickstart/nodejs). Save file as client_secret.json\n* Execute `npm run create_token` to store authentication token to json-file. This file is not in version control\n* Both files need to be in the workspace root\n\n#### Suggest a lunch or a beer place \n\nGet list of restaurants/bars from [Google Places API](https://developers.google.com/places/web-service/search) that are max 500m/800m from the office and return random item from that list. Office location is defined in the configuration file. \n\n![Suggest a lunch place](docs/lunch.jpg \"Suggest a lunch place\")\n\nRequirements:\n* [Get an API key](https://developers.google.com/places/web-service/get-api-key)\n\n#### Translate service\n\nAutomatically translate the conversation to selected language.\n\n![Translate](docs/translate.jpg \"Translate\")\n\nRequirements:\n* [Get API Key file](https://cloud.google.com/translate/docs/quickstart)\n\n```js\ntranslator: {\n    keyPath: '/home/user123/office-slack-bot/translate_secret.json',\n    prefix: ':flag-england:',\n    language: 'en',\n    maxCharacters: 1000,\n    channels: {\n        aaaaa: {\n            enabled: true\n        },\n        xxxxx: {\n            enabled: true\n        }\n    }\n}\n```\n\nBot adds a channel to the channel list when `translate` command is issued from the channel.\n\n#### Send email\n\n[Nodemailer](https://nodemailer.com/) is used to sen email. Add `mailConfig` to the configuration file. Will send email to defined email address and cc to sender. Add information to the configuration's `emailMessage`.\n\nBot's source code has an implementation to send an email to the maintenane company.\n\nRequirements:\n* If Google is used to send emails, enable less secure apps for the account https://myaccount.google.com/lesssecureapps\n\n#### WebScraping\n\nUses Cheerio to scrape text from html. Selector is executed with eval it's result is shown to user. Use `helpers\\cheerioTester.js` to verify selector.\n\n```js\nreddit : {\n    url: 'https://www.reddit.com/r/all',\n    description: 'Top link from Reddit all',\n    selector: `const link = $('#siteTable').find('a').first().attr('href'); link.startsWith('http') ? link : 'https://www.reddit.com' + link;`\n}\n```\n\n#### Doorbell\n\nSend GET request to the defined url. External service will send a command to IoT device.\n\n## Files\n\n* src/app.js\n  * Slack Botkit related communication\n* src/consoleApp.js\n  * Console application for testig\n* src/bot.js\n  * Logic for executing correct functionality\n* src/configuration.js\n  * __Required__ configuration for the application. Not in version control.\n  * Add this file manually\n* src/calendarServices.js\n  * Google Calendar integration\n* src/emailSender.js\n  * Email sending functionality\n* src/googlePlacesService.js\n  * Google Places API integration\n\n## ConsoleApp for testing\n\nConsole app wraps the same functionality as BotKit, so it works with same commands and returns same responsens.\n\n```sh\n$ npm run console\n```\n\n## Configuration file\n\nconfiguration.js containts tokens, passwords, locations, sensors etc.\n\nIf `allowGuestsToUse` is set to _false_, then restricted users will get an error messages when trying to send messages to the bot. \n\nconfiguration.js:\n```js\n'use strict';\n\nmodule.exports = {\n  botToken: 'xxxx',\n  homeChannelId: 'xxxx',\n  slackAdminUserId: 'xxxx',\n  allowGuestsToUse: false,\n  apiUserName: 'xxxx',\n  apiPassword: 'xxxx',\n  apiUrl: 'xxxx',\n  locationApiKey: 'xxxx',\n  office: { lat: 60.17, lon: 24.94 },\n  sensors: [\n    { id: 'xxx', name: 'xx' },\n    { id: 'xxx', name: 'xx' }\n  ],\n  meetingRooms: [\n    { name: 'xxxx', id: 'xxxx' }\n  ],\n  translator: {\n    keyPath: '/home/my-user/office-slack-bot/translate_secret.json',\n    prefix: ':flag-england:',\n    language: 'en',\n    maxCharacters: 1000,\n    channels: {\n      AAAA: {\n        enabled: true\n      },\n      BBBB: {\n        enabled: true\n      }\n    }\n  },\n  webScraperOptions: {\n    reddit: {\n      url: 'https://www.reddit.com/r/all',\n      description: 'Top link from Reddit all',\n      selector: `const link = $('#siteTable').find('a').first().attr('href'); link.startsWith('http') ? link : 'https://www.reddit.com' + link;`\n    },\n    vincit_kurssi: {\n      url: 'https://www.kauppalehti.fi/5/i/porssi/porssikurssit/osake/index.jsp?klid=2073',\n      description: 'Vincit stock value',\n      selector: `$('.stock_number').text() + \"€\";`\n    },\n    hs_top: {\n      url: 'https://www.hs.fi/',\n      description: 'Most read link from Helsingin Sanomat',\n      selector: `'https://www.hs.fi/' + $('.is-most-read-articles-list').find('a').first().attr('href');`\n    }\n  },\n  emailConfig: {\n    service: 'gmail',\n    host: 'smtp.gmail.com',\n    auth: {\n      user: 'xxx@gmail.com',\n      pass: 'xxxxx'\n    }\n  },\n  emailMessage: {\n    receiver: 'test@test.com',\n    subject: 'Maintenance request',\n    template: `\nHi,\n\n{content}\n\nBr,\n{senderName}\n`\n  },\n  doorBell: {\n    url: 'https://webhook.site/0e1a0101-7435-48e4-8bf7-fcea6e812a5e',\n    message: 'Opening the door'\n  }\n};\n```\n\n## Tests\n\nTest folder contains tests. Some tests require correct Google API keys in the configuration file.\n\n```sh\n$ npm test\n```\n\nRun test matchin the pattern:\n\n```sh\n$ npm run test:g [pattern]\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nLicensed under the [MIT](LICENSE) License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttu%2Foffice-slack-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fttu%2Foffice-slack-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttu%2Foffice-slack-bot/lists"}