GithubHelp home page GithubHelp logo

colematthew4 / slack-eventbot Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 23 KB

Create or leave events, and view the Slack users attending an event

License: MIT License

HTML 2.09% Python 97.91%
slack slackapi slack-api slack-commands python python-2 python2 python27

slack-eventbot's Introduction

Slack EventScheduler

Published by: Matthew Cole

Class: CST 223 - Concepts of Programming Langauges

Publishing Date: Spring 2017


Welcome to the setup for the Slack EventScheduler application.

Let me begin by stating that setup for this project is fairly long and complex. When clone the repository, you will find a Templates folder and a couple files:

  • app.py
  • bot.py
  • DB script.sql
  • security_fields.py

The DB script.sql file is strictly for setting up the database to store the information. You will need to create your own MSSQL database for this project to work. Within the Templates folder is 2 .html files, which are used for installing the bot to other teams. These will only be needed if you deploy the application to Slack and other teams can install it. Before we can run the application, we need to make sure we have all the required Python libraries and update the request URLs that Slack will send events to so our application can communicate with Slack. This is where we need ngrok.

Before we start using ngrok, you will need to install the python-slackclient, flask, and pymssql Python packages. This can be done using pip or easy_install (easy_install is the old version for installing Python packages). In order to do this, type one of the following (depending on what installer you are using) in the Python console to install Slack's Python API library:

  • pip install python-slackclient
  • sudo easy_install python-slackclient

You may need to authenticate yourself as a "sudoer" in order to use easy_install. Now try to run the application, and you should see something like this:

  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 223-166-435

This means that the application is running correctly and listening for incoming JSON requests.

Ngrok is an application that takes your localhost IP address and converts it into a unique HTTP/HTTPS URL. Slack requires an appliction's request URLs to be SSL certified, that's why we can't just use our localhost IP address. While the application is running, execute ngrok.exe and type:

ngrok.exe http 5000

This will open the communication channel and display the HTTP URLs that we need for Slack to communicate with our application. We will specifically need the HTTPS URL. Now we need to log in to Slack and add an integration to your team.

Signing in, creating an application, and setting it up

Go to your browser and navigate to slack.com and click on the "Sign In" button in the top right. From here Slack should redirect you to the team itself, where you can go to https://api.slack.com/apps to create the integration and apply the necessary application settings. In order for the application to work correctly, you need to add some permissions and event subscriptions.

Interactive Messages

Now we need the HTTPS URL from ngrok. In the EventScheduler application settings page, go to the Interactive Messages tab and enable Interactive Mesages. This is how we can communicate with the application. Now copy the ngrok URL, and paste it into the request URL with the /button endpoint. Your new request URL should look something like this:

https://4f72b87c.ngrok.io/button

Slash Commands

Click "Save Changes" and go to the Slash Commands tab and click on Create New Command. Here we will create the /event command. For the Command field, we will be using /event to signify what the command does. Now do the same thing as you did for the Interactive Messages request URL, but use the /event endpoint instead of the /button endpoint. The request URL for the slash command should look something like this:

https://4f72b87c.ngrok.io/event

Now we will give the command a description by typing "Create, leave, or view existing events!" into the Short Description field. Now we need to tell people how to use the command via the Usage Hint. In order for the application to correct process the message, users need to following the following guideline to use the command:

[help|all|me|new : [description] : [hh:mm am|pm] : [mm/dd/yy]

Toggle Escape channels, users, and links sent to your app and we're done setting up the slash command. Click "Save", then "Save Changes".

OAuth & Permissions

Now go to the OAuth & Permissions tab, and again do the same for the redirect URL. It's rare you will actaully use this, as it will only be invoked if you distribute it using the Add to Slack button, but it's better for it to be there for consistency's sake. The endpoint for the OAuth & Permissions should be /thanks, so your redirect URL should look like this:

https://4f72b87c.ngrok.io/thanks

Now we need to add Permission Scopes. The application requires the following Permission Scopes in order to communicate with Slack:

  • commands
  • channels:history
  • chat:write:bot
  • reminders:read
  • reminders:write
  • users:read

Event Subscriptions

Click "Save Changes", and the permissions will be added to the application. Now we can go to the Event Subscriptions tab, but make sure you have saved everything before moving on.

We need to enable events in order to subscribe to post messages to the #general channel when new users join your team. Toggle the Enable Events. Here you will see another Request URL; this is the last URL we need to change with the application. However, make sure the application itself is still running, because when we change this request URL Slack will send a "challenge" message to the application for it to verify. Make sure the endpoint for the Event Subscriptions Request URL is /listening. If successful, it will look something like this:

https://4f72b87c.ngrok.io/listening

Now we will subscribe to the message.channels and team_join events, which will allow the application to post messages and detect when somebody has joined your team.

After you click "Save Changes", the EventScheduler application should be fully up and running, and you can create and view events. Make sure to type "/event help" before you use it so you understand how it works and teach others to use it!


Thanks for using the Slack EventScheduler application. If you have questions or issues, post something on the wiki and I will attempt to help you as best I can.

MIT License

Copyright (c) 2017 Matthew Cole

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

slack-eventbot's People

Contributors

colematthew4 avatar

Watchers

 avatar  avatar

Forkers

grayzu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.