Git Product home page Git Product logo

slack-python-onboarding-tutorial's Introduction

An updated version of this tutorial can now be found in the Python Slack SDK

pythOnBoarding Bot

Building a simple bot using Slack's Events API in Python

This bot is an example implementation of building a Slack App with Slack's Python SDK, python-slackclient. We'll cover all the basic steps you'll need to create and configure your first Slack App in python.

PythOnBoarding Bot is designed to greet new users on your team and introduce them to some nifty features in Slack.

onboarding

Let's go write some code. You got this! โœจ

The first thing you'll need to do is make a local copy of this git repository. If you are familiar with git you can use:

git clone https://github.com/slackapi/Slack-Python-Onboarding-Tutorial.git

Otherwise you can download and unzip the project.

Technical Requirements

This example uses Python, specifically version 2.7 so you'll need to make sure you are using the correct version of Python. We'll also use a number of python packages you can install through pip.

Here's a list of what we'll need:
  • Python, the programming language we're going to use.
  • Pip, the Python package manager we'll use for installing packages we need.
  • Virtualenv or another tool to manage a virtual environment

Once you've installed Python, pip and virtualenv, you can install all additional dependent libraries using pip and the requirements.txt file included in this project, including Flask, a web development micro framework for Python and python-slackclient, a Slack client for Python. ๐Ÿ

After you've cloned this repository locally, you'll want to create a virtual environment to keep the dependencies for this project isolated from any other project you may be working on.

If you're using virtualenv run the following commands from the root of your project directory:

virtualenv env

Then activate your new virtual environment:

source env/bin/activate

After that, you can install all the Python packages this project will need with this command:

pip install -r requirements.txt
Server Requirements

Slack will be delivering events to your app's server so your server needs to be able to receive incoming HTTPS traffic from Slack.

If you are running this project locally, you'll need to set up tunnels for Slack to connect to your endpoints. Ngrok is an easy to use tunneling tool that supports HTTPS, which is required by Slack.

You'll likely want to test events coming to your server without going through the actions on your Slack team. Postman is a useful tool you can use to recreate requests sent from Slack to your server. This is especially helpful for events like user join, where the workflow to recreate the event requires quite a bit of set up.

Let's get started ๐ŸŽ‰

Further Reading and Getting Help

Documentation

Slack Documentation
Documentation for Tools

Where to Find Help

Wondering what to do if you can't get this dang tutorial to work for you? The Slack Developer community is an awesome place to get help when you're confused or stuck. We have an excellent 'search first' culture and Slack is committed to improving our tutorials and documentation based on your feedback. If you've checked the Slack API documentation, reached the end of your google patience and found StackOverflow to be unhelpful, try asking for help in the Dev4Slack Slack team.

Feedback

I'd love to improve this project, so if you've got some ideas ๐Ÿ’ก, feedback ๐Ÿ™‹ or praise ๐Ÿ’Œ please file an issue, submit a PR or reach out to me through Github or on Twitter!

slack-python-onboarding-tutorial's People

Contributors

harrisongrodin avatar henrymei avatar karishay avatar roach avatar rodneyu215 avatar walterbender avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-python-onboarding-tutorial's Issues

update message comes to early

Hi,

I'm trying to write something similar.
My Bot is supposed to update an message. however the response to the message comes afterwards the update api call, so it gets changed immediately after.
U know what I mean.
it's like if in your program the return make_response("Welcome Message Sent", 200,) comes after the bot updates the message

Issue with Werkzeug on Windows

I've been helping someone with running your project on Windows, turns out a Werkzeug in a version stated in requirements.txt has a bug, could you bump it to Werkzeug==0.11.15 to avoid problems for other people?

Pull request fixing the issue, pallets/werkzeug#999

Sorry for not providing a patch, but it's just one line.

Errors out of the box

"Created" the app using a git clone of this project. Followed instructions, and connected successfully to my url/team. When performing any action, I get output such as:

127.0.0.1 - - [31/May/2017 15:02:04] "POST /listening HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 2000, in call
return self.wsgi_app(environ, start_response)
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/home/slackdev/env/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/slackdev/Slack-Python-Onboarding-Tutorial/app.py", line 139, in hears
return _event_handler(event_type, slack_event)
File "/home/slackdev/Slack-Python-Onboarding-Tutorial/app.py", line 60, in _event_handler
pyBot.update_emoji(team_id, user_id)
File "/home/slackdev/Slack-Python-Onboarding-Tutorial/bot.py", line 168, in update_emoji
message_obj = self.messages[team_id].get(user_id)
KeyError: u'T0G61B5K9'

I'm running Python2 on a Ubuntu 16.04 server as a hyper-v, routing through ngrok.

This is my first attempt at using self-created bots, and python is my preferred language.

Thank you,
Larry

Onboarding message not shown.

I followed the tutorial and everything went smooth. Even got the 'Thank you' page. But when I add the bot under the 'Apps' section on my Slack app, no Onboarding message is shown.

I send a message to the bot and the ngrok shows POST /listening 200 OK.

Where am I going wrong?

Thank you for the great tutorial though!

How do you install the app to your team?

The final step doesn't delve into the details of how to install the app to your team.

This could mean it's either so easy that it doesn't warrant covering that step in this tutorial, or it could mean it's too complicated and out of scope for this tutorial.

Either way, I've been spinning my wheels. Any help?

Update steps to reflect Verification Token availability

In a past life of this tutorial, you had to have the server up and running, then submit the Request URL in order to get the Verification Token to run your app. Since then, the verification token has been made available at the time an app is created. We need to update the order of instructions in this tutorial to reflect that change.

problems getting started

hi,

after my first trial 'converting' my already existing slack app using this tutorial I tried to test it by adding another condition to the _event_handler function: ...
so when I message the bot, I want it to respond.

    elif event_type == 'message':
        user_id = slack_event['event']['user']
        print user_id, team_id
        pyBot.onboarding_message(team_id, user_id)
        return make_response("Welcome Message Sent", 200, )

However everything always ends at the bot.open_dm function. the call
new_dm = self.client.api_call("im.open", user=user_id) returns
{"ok": false, "error": "not_authed"}

I'm not sure what I am missing...

creating responses to interactive messages

Hi,

I want to create a response to an interactive message updating the original text.
how can I create/send the repsonse as a return of the flask function that handles the request?

duplicate Messages

on slack, we get multiple messages. for one request root cause Responding to Events in 3 seconds.
Any method to avoid it

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.