Giter Site home page Giter Site logo

slackapi / python-slack-events-api Goto Github PK

View Code? Open in Web Editor NEW
341.0 34.0 114.0 145 KB

Slack Events API adapter for Python (Flask required)

Home Page: https://api.slack.com/events

License: MIT License

Python 98.19% Shell 1.81%
python slack slackapi

python-slack-events-api's Introduction

Slack Events API adapter for Python

The Slack Events Adapter is a Python-based solution to receive and parse events from Slack’s Events API. This library uses an event emitter framework to allow you to easily process Slack events by simply attaching functions to event listeners.

This adapter enhances and simplifies Slack's Events API by incorporating useful best practices, patterns, and opportunities to abstract out common tasks.

πŸ’‘ We wrote a blog post which explains how the Events API can help you, why we built these tools, and how you can use them to build production-ready Slack apps.

⚠️ Important Notice

If you use this library for Events API handling, you may need to use threads for stable event acknowledgement. See #84 for details.

If you're looking for the best recommended library at this point, check Bolt for Python: https://github.com/slackapi/bolt-python

The framework covers not only Events API but also all the latest Slack Platform features.

πŸ€– Installation

pip install slackeventsapi

πŸ€– App Setup

Before you can use the Events API you must create a Slack App, and turn on Event Subscriptions.

πŸ’‘ When you add the Request URL to your app's Event Subscription settings, Slack will send a request containing a challenge code to verify that your server is alive. This package handles that URL Verification event for you, so all you need to do is start the example app, start ngrok and configure your URL accordingly.

βœ… Once you have your Request URL verified, your app is ready to start receiving Team Events.

πŸ”‘ Your server will begin receiving Events from Slack's Events API as soon as a user has authorized your app.

πŸ€– Development workflow:

  1. Create a Slack app on https://api.slack.com/apps
  2. Add a bot user for your app
  3. Start the example app on your Request URL endpoint
  4. Start ngrok and copy the HTTPS URL
  5. Add your Request URL and subscribe your app to events
  6. Go to your ngrok URL (e.g. https://myapp12.ngrok.com/) and auth your app

πŸŽ‰ Once your app has been authorized, you will begin receiving Slack Events

⚠️ Ngrok is a great tool for developing Slack apps, but we don't recommend using ngrok for production apps.

πŸ€– Usage

⚠️ Keep your app's credentials safe!

  • For development, keep them in virtualenv variables.
  • For production, use a secure data store.
  • Never post your app's credentials to github.
SLACK_SIGNING_SECRET = os.environ["SLACK_SIGNING_SECRET"]

Create a Slack Event Adapter for receiving actions via the Events API

Using the built-in Flask server:

from slackeventsapi import SlackEventAdapter


slack_events_adapter = SlackEventAdapter(SLACK_SIGNING_SECRET, endpoint="/slack/events")


# Create an event listener for "reaction_added" events and print the emoji name
@slack_events_adapter.on("reaction_added")
def reaction_added(event_data):
  emoji = event_data["event"]["reaction"]
  print(emoji)


# Start the server on port 3000
slack_events_adapter.start(port=3000)

Using your existing Flask instance:

from flask import Flask
from slackeventsapi import SlackEventAdapter


# This `app` represents your existing Flask app
app = Flask(__name__)


# An example of one of your Flask app's routes
@app.route("/")
def hello():
  return "Hello there!"


# Bind the Events API route to your existing Flask app by passing the server
# instance as the last param, or with `server=app`.
slack_events_adapter = SlackEventAdapter(SLACK_SIGNING_SECRET, "/slack/events", app)


# Create an event listener for "reaction_added" events and print the emoji name
@slack_events_adapter.on("reaction_added")
def reaction_added(event_data):
  emoji = event_data["event"]["reaction"]
  print(emoji)


# Start the server on port 3000
if __name__ == "__main__":
  app.run(port=3000)

For a comprehensive list of available Slack Events and more information on Scopes, see https://api.slack.com/events-api

πŸ€– Example event listeners

See example.py for usage examples. This example also utilizes the SlackClient Web API client.

πŸ€” Support

Need help? Join Slack Community and talk to us in #slack-api.

You can also create an Issue right here on GitHub.

python-slack-events-api's People

Contributors

515hikaru avatar agurgel-te avatar aoberoi avatar benoitlavigne avatar brad-alexander avatar calvinhp avatar datashaman avatar dependabot[bot] avatar equal-l2 avatar hippocrates avatar jefffranklin avatar kirby-jobber avatar maryum375 avatar navinpai avatar psykzz avatar roach avatar seratch avatar shaydewael avatar sirdan69 avatar temurchichua 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-slack-events-api's Issues

Lack of X-Slack-Request-Timestamp and/or X-Slack-Signature in requests results in 500

Description

I noticed that a test I wrote to simulate a user probing the events URL returned a 500 when I would have expected a 400.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them. -- However, Spotify, my employer, has not yet signed the CLA to my knowledge, so I will not be able to submit a patch until they do.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 2.2.0
python version: 3.6
OS version(s): irrelevant, but Linux and MacOS

Steps to reproduce:

  1. Make a POST request to a slack events URL without X-Slack-Events-Timestamp in the headers.
  2. Observe response of 500 and subsequent TypeError raised

Expected result:

A 400 error.

Actual result:

500 and unhandled exception.

Attachments:

SlackEventAdapter not working with AWS S3 Bucket, AWS Lambda & API Gateway

Description

I'm using AWS Lambda and API Gateway to host my Flask code for a Slack App. Currently, I'm struggling with responding to the challenge parameter when entering the Request URL. The way I'm implementing my code is:

  1. Use serverless framework to develop code in a test environment
  2. Once the code works in the test environment, I download the zip file from the test Lambda function, unzip it, change the variables to production environment variables and zip it.
  3. I upload the code to the production S3 bucket, which is linked to the production AWS Lambda.

Here are some routes that I have in my code:

app = Flask(__name__)
slack_event_adapter = SlackEventAdapter(os.environ["TEST_SLACK_SIGNING_SECRET"], "/slack/events", app)

@app.route("/")
def hello_from_root():
    return jsonify(message=f'Slack signing secret: {os.environ["TEST_SLACK_SIGNING_SECRET"]}'). 

@app.route("/interactions", methods=['GET', 'POST'])
def parse_interactions():
    """
    Parse interactions here
    """

I suspected that the environment variables weren't being read, but I am able to receive the slack signing secret when sending a GET request to the API Gateway URL

What could be the issue?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 3.0.1
python version: 3.9.6
OS version(s): macOS Ventura 13.2.1

Steps to reproduce:

  1. Deploy serverless framework
  2. Export function
  3. Unzip function, change env variables to prod variables, upload to prod S3 bucket
  4. Enter "prod-api-gateway-url/slack/events" to Slack events subscription request url

Expected result:

The request url to be accepted

Actual result:

The request url not accepted

Attachments:

Issues signing incoming slash command requests (Flask)

Description

I have been trying to use the verify_signature function from the events server to securely authenticate slash command requests. The issue here is that the Flask request body is coming up as empty bytes for a slash command b'' where the actual slash command data is form encoded.

It would be great to have some guidance as to how to verify the signature of incoming slash command requests in Flask as I am currently having to rely on token authentication. Please let me know if anymore details are required.

@aoberoi

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Reproducible in:

slackeventsapi version: latest
Flask version: 1.0.2
OS version(s): N/A

Steps to reproduce:

  1. Call the verify_signature function from a slash command request context

Expected result:

Signed secret successfully reproduced from the request body

Actual result:

Error is raised as request content/json is blank

RFC: Python 2.7 Support Timeline

Why are we doing this?
Python 2.7 will reach it’s official β€˜end of life’ (EOL) on December 31st, 2019. This means that it will no longer be supported by its maintainers. Accordingly, we will retire python-slack-events-api support for Python 2.7.

β€œPython 2.x is legacy, Python 3.x is the present and future of the language.β€œ

How will this change the project?
All new python-slack-events-api features and bug fixes will continue to be supported in Python 2.7 until Dec 31st, 2019.

After January 1, 2020 we’ll be creating a new version of the python-slack-events-api. This version will remove any Python 2.x specific code. We’ll also immediately stop fixing any bugs and security vulnerabilities that are specific to this older version.

We’d love your feedback!
Please let us know what you think by commenting on this issue. We’d love feedback on this timeline; does it work for you?

TypeError: the JSON object must be str, not 'bytes' for challenge

Description

Using the API with python 3.5 gives the following error when Slack sends the challenge token to authenticate app request URL.

[2017-10-28 19:10:31,597] ERROR in app: Exception on /slack/events [POST]
Traceback (most recent call last):
  File "/mnt/code/sendgrid-tutorial/venv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/mnt/code/sendgrid-tutorial/venv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/mnt/code/sendgrid-tutorial/venv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/mnt/code/sendgrid-tutorial/venv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/mnt/code/sendgrid-tutorial/venv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/mnt/code/sendgrid-tutorial/venv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/mnt/code/sendgrid-tutorial/venv/lib/python3.5/site-packages/slackeventsapi/server.py", line 18, in event
    event_data = json.loads(request.data)
  File "/Users/naveenpai/.pyenv/versions/3.5.0/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

Checked the data that slack returns and it is:

b'{"token":"ABCDEFGH","challenge":"12345678","type":"url_verification"}'

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 1.0.0
python version: 3.5
OS version(s): Mac OSX (High Sierra)

Steps to reproduce:

  1. Set up Slack app.
  2. Run example.py and use ngrok to tunnel
  3. Paste url in Request URL field for Slack app

Expected result:

The Slack app successfully gets validated

Actual result:

Error mentioned in description gets thrown.

Attachments:

None.

handling Request URL for interactive messages

Description

While reading your example you have used verify_request() to verify the signature, this function does not exist in python-slack-events-api repo.

Is there a way to use python-slack-events-api to handle request URL for interactive messages (like button clicks) or do i need to build the low level verification on my own?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • [ X] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [X ] I've read and agree to the Code of Conduct.
  • [ X] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

Enable proxy support for slackeventsapi

Description

Describe your issue here.

Hi Team ,

In my current setup the flask server is behind a proxy. In this scenario from slackeventsapi does not have a option to define proxy server details.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • [X ] enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • [ X] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

from slackeventsapi import SlackEventAdapter
slack_events_adapter = SlackEventAdapter(SLACK_SIGNING_SECRET, "/slack/events", app)
[Mon Jan 13 13:11:00.817386 2020] [:error] [pid 11922] [client 132.240.205.180:29626]   File "/usr/lib/python2.7/site-packages/slackclient/slackrequest.py", line 116, in post_http_request
[Mon Jan 13 13:11:00.817407 2020] [:error] [pid 11922] [client 132.240.205.180:29626]     proxies=self.proxies
[Mon Jan 13 13:11:00.817412 2020] [:error] [pid 11922] [client 132.240.205.180:29626]   File "/usr/lib/python2.7/site-packages/requests/api.py", line 116, in post
[Mon Jan 13 13:11:00.817416 2020] [:error] [pid 11922] [client 132.240.205.180:29626]     return request('post', url, data=data, json=json, **kwargs)
[Mon Jan 13 13:11:00.817421 2020] [:error] [pid 11922] [client 132.240.205.180:29626]   File "/usr/lib/python2.7/site-packages/requests/api.py", line 60, in request
[Mon Jan 13 13:11:00.817425 2020] [:error] [pid 11922] [client 132.240.205.180:29626]     return session.request(method=method, url=url, **kwargs)
[Mon Jan 13 13:11:00.817429 2020] [:error] [pid 11922] [client 132.240.205.180:29626]   File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
[Mon Jan 13 13:11:00.817433 2020] [:error] [pid 11922] [client 132.240.205.180:29626]     resp = self.send(prep, **send_kwargs)
[Mon Jan 13 13:11:00.817438 2020] [:error] [pid 11922] [client 132.240.205.180:29626]   File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
[Mon Jan 13 13:11:00.817442 2020] [:error] [pid 11922] [client 132.240.205.180:29626]     r = adapter.send(request, **kwargs)
[Mon Jan 13 13:11:00.817448 2020] [:error] [pid 11922] [client 132.240.205.180:29626]   File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 516, in send
[Mon Jan 13 13:11:00.817453 2020] [:error] [pid 11922] [client 132.240.205.180:29626]     raise ConnectionError(e, request=request)
[Mon Jan 13 13:11:00.817461 2020] [:error] [pid 11922] [client 132.240.205.180:29626] ConnectionError: HTTPSConnectionPool(host='slack.com', port=443): Max retries exceeded with url: /api/chat.postMessage (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6de251e910>: Failed to establish a new connection: [Errno 110] Connection timed out',))

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

slackeventsapi.server.SlackEventAdapterException: Invalid request signature

Description

My App was working well using events API so far, but today i got this error " slackeventsapi.server.SlackEventAdapterException: Invalid request signature". I know that somewhere i messed up something but not able figure out . what could be the reason for this issue?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

health endpoint

Description

Running a slack events server in Kubernetes requires a liveness / rediness endpoint per: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

As is, this is not natively supported by the server embedded in python-slack-events.

Many other PaaS / Orchestrated environments have similar requirements.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • [ X] enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • [X ] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [ X] I've read and agree to the Code of Conduct.
  • [X ] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: master
python version: 2.7
OS version(s): Linux Alpine 3.7 based container running in Kubernetes

Steps to reproduce:

  1. Run this server in Kubernetes

Expected result:

Should pass Liveness / Rediness

Actual result:

It fails Liveness / Rediness

Potential Resolution:

Yes, I can handle this with a reverse proxy in front of this service, but IMO that's a bit kludgey if health is its only purpose. Additionally, that's somewhat error prone as the reverse proxy status would need to be tied to the health of the process running this service.

If you're open to a PR, I can create one from: https://github.com/immuta/python-slack-events-api/tree/health_endpoint

It provides a single default health endpoint at /health and allows users to provide an alternate endpoint and / or a custom health function.

This doesn't currently allow for distinguishing between liveness and readiness, but I can extend it to do so if desired.

Proposal: Remove Python 2.7.6 support

Description

PR #51 has tests failing because Travis's test runner errors out on 2.7..6: https://travis-ci.org/slackapi/python-slack-events-api/jobs/529462763

I submitted a PR to simply remove the 2.7..6 environment from the travis configs, but closed it when I remembered that we have specific request signing logic for Python 2.7..6:
https://github.com/slackapi/python-slack-events-api/blob/master/slackeventsapi/server.py#L47-L83

2.7..6 was released in 2013, and PSF actively recommends 2.7.15 for new downloads: https://www.python.org/download/releases/2.7/

I'd like to remove the custom logic and test config for 2.7.6.

Add more comprehensive example application (LunchTrain example)

Description

To better showcase the functionality of this library, we need to add a more comprehensive and functional example app using V2 of the SlackClient Web API library.

Example: https://lunchtrain.builtbyslack.com/

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

API for verifying Signature?

Description

The module verifies requests using verification token. Does it support Signing Secret based verification? I couldn't find it by going through the docs although I do see it's occurences in the code.

To be more specific, I want to be able to verify requests from slack using the signing secret in my flask app but not just for Events requests. I have already written my app.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

Is it possible to use Tornado?

Description

Hi there, I'm writing an issue because I can't connect with the slack workspace that is at the end of the README (Need help? Join Slack Community and talk to us in #slack-api). I've created an account but it still says that it isn't part of the workspace.

So to my question. Is it possible to use Tornado instead of Flask with this package? I want to create a mini app using slackclient + Tornado. I have an HTTP slack app.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Incorrect screenshot in `example/README.rst`

Description

Excellent library!

One very minor issue: the screenshot for adding your ngrok url is out of sync with the instructions (example/README.rst)

In the Subscribe your app to events section, the text accurately says you should add /slack/events to your URL, the screenshot only includes /events

https://cloud.githubusercontent.com/assets/32463/24877867/b39d4384-1de5-11e7-9676-9e47ea7db4e7.png

Currently:

b39d4384-1de5-11e7-9676-9e47ea7db4e7

It should look like this:

challenge_url

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

message.app_home event

Description

Following the message example, when sending a direct message to an App, the message event type is showing the channel_type as im instead of app_home.

What type of issue is this?

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

slackeventsapi version: 2.2.1
python version: 3.9.1
OS version(s): macOS 11.01

Steps to reproduce:

  1. Per message.app_home, subscribe to app_home_opened and message.im event(s) for the ngrok /slack/events URL.
  2. Have your App print incoming events. (See the example attached below.)
  3. In Slack, send a direct message to your App consisting of the string hi.

Expected result:

Per this article, when sending a direct message to an App, channel_type should be app_home instead of im.

Actual result:

Example of received event(s):

{
    "client_msg_id": "5c4a5cb4-dd2f-4dd0-ab2d-c960079d3a64",
    "type": "message",
    "text": "hi",
    "user": "U01FA1X7WBV",
    "ts": "1610743774.093000",
    "team": "T01FNECMMT3",
    "blocks": [
        {
            "type": "rich_text",
            "block_id": "0fso1",
            "elements": [
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "hi"
                        }
                    ]
                }
            ]
        }
    ],
    "channel": "D01HHS5V71A",
    "event_ts": "1610743774.093000",
    "channel_type": "im"
}
{
    "bot_id": "B01J1GQHGMN",
    "type": "message",
    "text": "Hello",
    "user": "U01HQAGQLJV",
    "ts": "1610743775.093100",
    "team": "T01FNECMMT3",
    "bot_profile": {
        "id": "B01J1GQHGMN",
        "deleted": false,
        "name": "test",
        "updated": 1608525077,
        "app_id": "A01HHS177E0",
        "icons": {
            "image_72": "https://avatars.slack-edge.com/2020-12-20/1589929255555_7550dbf394f22892292b_72.png"
        },
        "team_id": "T01FNECMMT3"
    },
    "channel": "D01HHS5V71A",
    "event_ts": "1610743775.093100",
    "channel_type": "im"
}

Attachments:

App code to reproduce the issue:

#!/usr/local/bin/python3

from slackeventsapi import SlackEventAdapter
from slack_sdk import WebClient
import json
import os

# App Credentials
secret = os.environ['TEST_SECRET']
slack_events_adapter = SlackEventAdapter(secret, "/slack/events")

# Instantiating Slack Client
client = WebClient(token=os.environ['TEST_TOKEN'])

# Slack Message
@slack_events_adapter.on("message")
def handle_message(event_data):
    message = event_data["event"]
    # Print Event(s)
    print(json.dumps(message, indent=4))

    # If the incoming message contains "hi", then respond with a "Hello" message
    if message.get("subtype") is None and "hi" in message.get('text'):
        channel_id = message["channel"]
        message = "Hello" % message
        client.chat_postMessage(channel=channel_id, text=message)

# Server Port 8242
slack_events_adapter.start(port=8242)

Add support for request signing

Description

Request signing went live and we should add support into our SDKs. https://api.slack.com/docs/verifying-requests-from-slack

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Ignore https requests

Description

Sometimes, my bot crashes when someone tries to attempt into the https

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

For example, I'm getting this:

[22/Apr/2021 10:50:38] "GET / HTTP/1.1" 404 -
[22/Apr/2021 10:51:11] code 400, message Bad request syntax
('\x03ΓΏT\x81`\x00\x00\x00\x00\x00\x00\x00\x..... (I cut the rest )
- [22/Apr/2021 10:51:11] "ΓΏT`" 400 -
[22/Apr/2021 10:51:11] "GET / HTTP/1.1" 404 -
Exception happened during processing of request from ('x.y.z.39', 55254)
Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py", line 320, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 351, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3.6/http/server.py", line 386, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------
74.120.14.39 - - [23/Apr/2021 03:11:40] code 400, message Bad request version ('Γ€\x14Γ€')
74.120.14.39 - - [23/Apr/2021 03:11:40] "{wΒ΄%Γ‚j¦»ºààocess_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 351, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3.6/http/server.py", line 386, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)

Steps to reproduce:

I am not sure how to reproduce it, but it seems that sometimes, the Flask is getting an https request instead of HTTP and crashes.

  1. Is it enough to add SSL_DISABLE=True to the flask app?
  2. Is https://slack.dev/bolt-python/concepts#errors going to resolve this issue?

Expected result:

App stay online 24/7 :)

Ref search:

  1. https://stackoverflow.com/questions/49389535/problems-with-flask-and-bad-request
  2. https://slack.dev/bolt-python/concepts#errors

can the adapter be run as a blueprint instead of as a flask server?

Description

My current event listener was a flask blueprint, while the new adapter is a flask app on its own. I will therefore have to run 2 flask apps now to support the events adapter. Although, running 2 flask apps is possible, sharing data models across the 2 apps becomes difficult and leads to unnecessary complication.

So, wanted to check with you guys if at any point down the line, the adapter abstraction can be simplified?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

Stable acknowledgement for incoming requests

Description

This library runs an event listener before responding to an incoming request from Slack with 200 OK. This means if an event handler takes over 3 seconds, the event request times out and the Slack API server resends the same event up to 3 times. You can easily reproduce this issue with the following code snippet.

import time
@slack_events_adapter.on("app_mention")
def handle_app_mentions(event_data):
    time.sleep(5)
    print("Done!")

As a workaround, developers can use threads to run time-consuming tasks asynchronously. Mixing asyncio may not be a great idea as this is a Flask extension and Flask does not support the mechanism.

import time
from concurrent.futures.thread import ThreadPoolExecutor
executor = ThreadPoolExecutor(5)
@slack_events_adapter.on("app_mention")
def handle_app_mentions(event_data):
    def do_something():
        time.sleep(5)
        print("Done!")
    executor.submit(do_something)
    print("Accepted!")

Improving this library is of course worth considering but in the short run, it's not a priority. Also, not only due to this matter, we recommend using Bolt for Python. The new library supports not only Events API but also all the latest features including interactivity.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Set the bind host via API?

Description

I'd like to be able to bind to 0.0.0.0 instead of localhost and I'd rather not have to modify the included module. Is this documented anywhere? Without it, you can't really run a slack event listener in a docker container. At this point I only see a way to change the port.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • [x ] question
  • documentation related
  • testing related
  • discussion

Requirements

  • [ x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [ x] I've read and agree to the Code of Conduct.
  • [ x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

example.py doesnt reply to slack message even though message seams to be received

Description

I followed the example documentation but example.py doesn't respond to the slack message, even though I can see the POST message received. It seams message_handler is not called at all.
Python 2.7.17 in virtualenv on Ubuntu 18.04
Is this a bug or I am missing something? Example should work...

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

  1. Run example.py

Expected result:

message_handler receives the message and responds to the message if hi detected

Actual result:

message_handler not called, no reply to message even though POST from slack server is received and 200 code is replied.

Attachments:

127.0.0.1 - - [22/Apr/2020 09:38:59] "POST /slack/events HTTP/1.1" 200 -
127.0.0.1 - - [22/Apr/2020 09:39:05] "POST /slack/events HTTP/1.1" 200 -
127.0.0.1 - - [22/Apr/2020 09:43:29] "POST /slack/events HTTP/1.1" 200 -

Accessable Restricted Browning Content

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

HTTP 200 Response question

Description

I've read in the documentation and several forum posts about sending a HTTP 200 status back to slack and am unsure of how to do so and cannot find an example of how to do this with the slack event api. What would the proper way to send this response be?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Reproducible in:

slackeventsapi version: 2.1.0
python version: 3.7.0
OS version(s): Fedora 30

Steps to reproduce:

  1. use my code to start a slack bot
  2. call the fetch command in slack
  3. wait for duplicates to be sent

Expected result:

I expect only one response to be posted in the slack channel

Actual result:

The bot replies back with multiple responses like its retrying to send the command.

Attachments:

Here is the code producing the issue:

# Initialize a Flask app to host the events adapter
app = Flask(__name__)
slack_events_adapter = SlackEventAdapter(SIGINING_SECRET, "/slack/events", app)

# Initialize a Web API client
slack_web_client = WebClient(token=OAUTH_TOKEN)

def fetch(command):
    num_args = 2
    if len(command) != num_args:
        response = "Incorrect number of arguments ({})".format(num_args)

    else:
        t_id = command[1]

        try:
            response = "Fetched"
        except Exception as e:
            response = ("*Failed!*")
            raise

    return response

@slack_events_adapter.on("app_mention")
def on_mention(payload):
    """Parse commands sent from a mention
        ex command: @Bot fetch 12345
    """
    event = payload.get("event", {})

    if "bot_id" not in event:
        channel_id = event.get("channel")
        command_args = event.get("text").split(" ")
        # strip out the mention and leave the other elements in the list
        mention = command_args[0]
        command_args = command_args[1:] if len(command_args) > 1 else []

        if command_args:
            response = None

            # Check for fetch command
            if command_args[0].lower() == "fetch":
                response = fetch(command_args)

            if response:
                return bot_respond(response, channel_id)
            else:
                return bot_respond("Unrecognized command, use help for more information", channel_id)

def run_bot():
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    logger.addHandler(logging.StreamHandler())
    ssl_context = ssl_lib.create_default_context(cafile=certifi.where())
    app.run(port=3000)


if __name__ == "__main__":
    run_bot()

How to effectively handle a server sleep?

Description

Hello guys! I searched and tried some workarounds, including a script to don't let the server in sleep mode, but I really want this to work in the right way. The issue is that I receive three messages when I send an event to my flask server when it is on sleep mode. I've faced this on Heroku, now on Render. And that makes me wonder if there is a way to solve this problem for good.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

slackeventsapi version: 3.0.1
python version: 3.7
OS version(s):

Steps to reproduce:

  1. Let the app sleep on Heroku or Render free plans (now only using in Render)
  2. Send a message in slack to generate an event to the server
  3. Wait for the response

Expected result:

I expect to receive only one response from the server.

Actual result:

Several messages are returned from the server.

Attachments:

Socket mode is duplicating the messages

We have enabled the socket mode and when we send a message to the app, it is keep sending the same message,

'type': 'events_api', 'accepts_response_payload': False, 'retry_attempt': 0, 'retry_reason': ''
'type': 'events_api', 'accepts_response_payload': False, 'retry_attempt': 1, 'retry_reason': 'timeout'
'type': 'events_api', 'accepts_response_payload': False, 'retry_attempt': 2, 'retry_reason': 'timeout'
'type': 'events_api', 'accepts_response_payload': False, 'retry_attempt': 2, 'retry_reason': 'timeout'
'type': 'events_api', 'accepts_response_payload': False, 'retry_attempt': 3, 'retry_reason': 'timeout'
'type': 'events_api', 'accepts_response_payload': False, 'retry_attempt': 3, 'retry_reason': 'timeout'

How to address this? We are not using any SDK to handle the case instead interested in rest APIs.

Groom supported Python versions and declare in setup.py metadata

Description

It seems like a bunch of unsupported Python versions are running in the tests. I think it should be the same as those for slackclient, which are py{27,34,35,36}. This seems to be the cause of failures in open PRs.

Also, declaring the specific versions that are supported in the setup.py metadata, as done in slackclient would make it easier for users and machines to understand if their system is compatible or not.

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Exception on receiving new slack events

Description

SlackEventAdapter is throwing an exception on receiving slack events.

[2020-10-13 16:46:54,786] ERROR in app: Exception on /api/slack/events/ [POST]
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/slackeventsapi/server.py", line 97, in event
    self.emitter.emit('error', slack_exception)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 111, in emit
    self._emit_handle_potential_error(event, args[0] if args else None)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
    raise error
slackeventsapi.server.SlackEventAdapterException: Invalid request timestamp

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

slackeventsapi version: 2.1.0
python version: 3.6.9
OS version(s): Ubuntu 18.04.4 LTS (Bionic Beaver)

Steps to reproduce:

  1. Create a simple Flask server with SlackEventAdapter
  2. Send a message on slack
  3. Check server console for the error.

Expected result:

No error should be thrown when an event is received from slack (message or reaction).

Actual result:

Error is thrown whenever a slack event is received (message or reaction).

Attachments:

Screencast

ezgif com-gif-maker

Logs
[2020-10-13 16:46:54,786] ERROR in app: Exception on /api/slack/events/ [POST]
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/slackeventsapi/server.py", line 97, in event
    self.emitter.emit('error', slack_exception)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 111, in emit
    self._emit_handle_potential_error(event, args[0] if args else None)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
    raise error
slackeventsapi.server.SlackEventAdapterException: Invalid request timestamp

Is it possible to create a link to the thread from a event message?

Description

Hello there!

Let's assume the function below that receives message events:

...
@slack_events_adapter.on("message")
def func(event_data):
   ...
...

I'd like to know if it is currently possible to create a thread link (same as we get from the image button bellow), based on the event_data I receive from the message event:
image

The link is generated as the example: https://your_workspace.slack.com/archives/channel_id/msg_id

Real life example: https://workspace.slack.com/archives/CR3SUPEMU/p1234567891234561

As far as I know, I got only the channel property id from the Slack API, and I couldn't find a reference to the msg_id I'd need to create a correct link.

I'm not sure if I'm missing something... Is there any alternatives to that?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Is this compatible with AWS Lambda?

Deploy with Zappa to AWS Lambda

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: SlackEventAdapter
python version: 3.6
OS version(s): Linux (Virtual Env inside Docker container)

Expected result:

I want it to run as a regular Flask app or be able to specify an AWS gateway URL

Actual result:

Running on http://127.0.0.1:5000/

It treats my AWS environment as local host.

Attachments:

Error message after trying to deploy to Lambda:

Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 504 response code.

[1537802873064] [INFO] 2018-09-24T15:27:53.27Z 6395b256-c00e-11e8-8c99-f1ee495556a5 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[1537802898072] 2018-09-24T15:28:18.071Z 6395b256-c00e-11e8-8c99-f1ee495556a5 Task timed out after 30.03 seconds

Not getting channel events except "at mention" events

We have below permissions set for our app and for the past few hours we are not getting any events which we have posted on the channel except "at mention" events. Anything changed?

Also direct messages to app working without at mention.


Event Name | Description | Required Scope
app_mention | Subscribe to only the message events that mention your app or bot | app_mentions:read | Β 
message.channels | A message was posted to a channel | channels:history | Β 
message.im | A message was posted in a direct message channel | im:history

`link_shared` event mangles the URL

Description

When subscribing to link_shared events, the URLs received in the event aren't always exactly what was written in the message. Specifically, & turn into &amp;, as if having been through HTML character encoding, but never converted back.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion-

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

slackeventsapi version: 2.1.0
python version: 3.6.7
OS version(s): Ubuntu 18.04.2

Steps to reproduce:

  1. Set your Slack app to subscribe to link_shared events for the domain example.com.
  2. Have your Slack app to print out incoming events. (See below for an example app to use.)
  3. In Slack, write a message consisting of the string https://example.com/?a=0&b=1.

Expected result:

The URL field of the received event holds the unmodified URL https://example.com/?a=0&b=1.

Actual result:

The URL field of the received event holds https://example.com/?a=0&amp;b=1.

Example of received event:

{'channel': 'C1TT2EJ7K',
           'links': [{'domain': 'example.com',
                      'url': 'https://example.com/?a=0&amp;b=1'}],
           'message_ts': '1553472186.004100',
           'type': 'link_shared',
           'user': 'U1TT79QSE'}

Attachments:

App code to reproduce the issue:

#!/usr/bin/env python3                                                                               
                                                                                                     
from slackeventsapi import SlackEventAdapter                                                         
import os                                                                                            
from pprint import pprint                                                                            
                                                                                                     
slack_signing_secret = os.environ["SLACK_SIGNING_SECRET"]                                            
slack_events_adapter = SlackEventAdapter(slack_signing_secret, "/slack/events")                      
                                                                                                     
# Subscribe to, and print, incoming link events.                                                     
@slack_events_adapter.on('link_shared')                                                              
def link_shared(event_data):                                                                         
    pprint(event_data['event'])                                                                      
                                                                                                     
# Start server with a `/slack/events` endpoint.                                                      
slack_events_adapter.start(port=8000)

Edit: Changed two occurrences of "client" to "app", which is what I meant to say all along.

Edit: Fixed typo "ap" β†’ "app".

Need help for running Flask app using this package

Hi
I am using slack api
to render the automatic message reply from the slack boat

This is My Code:

  ss = "***"


  slack_event_adapter = SlackEventAdapter(ss,'/slack/events',app)
  print("slack_event_adapter:",slack_event_adapter)
  print("slack_event_adaptor_event_name",slack_event_adapter.on('message'))
  
  @slack_event_adapter.on('message')
  def message(payload):
      # def message(payload):
          st = "xoxb-***"
          client = slack.WebClient(token=st)
          BOT_ID = client.api_call("auth.test")['user_id']
          print("BOT_ID",BOT_ID)
          print("Hiii")
          event = payload['event']
          print(event)
          channel_id = event.get('channel')
          print("channel_id",channel_id)
          # channel_id ='#sample'
          user_id = event.get('user')
          print("user_id",user_id)
          # user_id = "Manikantha Sekhar"
          text = event.get('text')
          print("test:",text)
          # text = "Hi"
          if BOT_ID != user_id:
              print("if_condition")
              print("bot_id not equal")
              #msg = "this is arkatiss new experiment"
              reply = reply_the_user(text,user_id)
              print("reply",reply)
              client.chat_postMessage(channel=channel_id,text=reply)

# # message()
if __name__ == "__main__":
	app.run(host='localhost',debug=False,port=5030)

This is my payload through postman

{   "event":"message",
    "channel_id":"C03NNTWTE1F",
    "user_id": "U01DQQR0ZK8",
    "text":"hi"
}

This is my url

1.http://localhost:5030/slack/events/
getting error like

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try
	again.</p>

any solution for this can you help me in this

Invalid request signature error

Description

Hello, not sure if this is the appropriate place for this question. I have been following How To Build a Slackbot in Python on Ubuntu 20.04 guide using this api but is unable to complete the final step. I have setup the slack app settings, verified the address by using port forward and I get "invalid request signature" error which I am not sure what it means since it does not refers to the app.py.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 2.2.1
python version: 3.9.0
OS version(s): Mac OS 10.15.7

Steps to reproduce:

  1. follows the steps in the tutorial
  2. error happens in the last step

Expected result:

bot responds in the channel

Actual result:

unknown error, nothing is processed

Attachments:

127.0.0.1 - - [11/Nov/2020 11:34:08] "POST /slack/events HTTP/1.1" 500 -
Exception on /slack/events [POST]
Traceback (most recent call last):
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/slackeventsapi/server.py", line 102, in event
    self.emitter.emit('error', slack_exception)
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyee/_base.py", line 111, in emit
    self._emit_handle_potential_error(event, args[0] if args else None)
  File "/Users/wang.shuochen/.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
    raise error
slackeventsapi.server.SlackEventAdapterException: Invalid request signature
127.0.0.1 - - [11/Nov/2020 11:39:08] "POST /slack/events HTTP/1.1" 500 -

Possible to handle HTTP headers from Slack within event adapter?

Description

Not sure if I just missed something, but if I wanted to handle an event with a particular header from Slack differently (ie, X-Slack-Retry-Num, from here) I don't see how to actually do that. I'm using the event adapter attached to an existing Flask instance; I can catch the header on my dedicated endpoints, just not sure how to within the event hook.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Darn - that slash command didn't work (error message: `500_service_error`). Manage the command at slash-command.

Hi,

I am working on WorkflowMax API. I am integrating WFM with Slack using API gateway and Lambda. I created slash command which invokes API gateway and that in turn invokes Lambda. Simple Lambda Function gets triggered but when I add API calls of WFM I get following error:-
"Darn - that slash command didn't work (error message: 500_service_error). Manage the command at slash-command."
I am stuck in this issue.
Any suggestions here would be helpful.

Thanks,
Reena.

Missing example usage with flask app factory pattern

Description

There's no example on how to register the server as a blueprint that would then be added to a flask app. Is it possible?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • [x ] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x ] I've read and agree to the Code of Conduct.
  • [ x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 2.1.0
python version: 3.6.0
OS version(s): Ubuntu 18

Steps to reproduce:

  1. Try to use app factory pattern and create a blueprint for slackevents that is not yet asociated with any app
  2. Try to add it
  3. Fail because there's no example on the docs

Expected result:

Documentation on whether this approach is supported or not

Actual result:

No relevant documentation

Question about the current state of verification token and proper usage of signing secret

I see the below notification at https://api.slack.com/authentication/verifying-requests-from-slack

Verification token deprecation
We'll continue allowing apps to use verification tokens for now. However, we will retire them completely in coming months. We strongly recommend switching to request signing as soon as possible.

Do we have any other alternative to verify whether requests from SLack are authentic?

SlackEventAdapter object creates even if the signing_secret parameter gets NoneType argument

Description

I've set the env. variable for the Slack Event Token and used it to create Adapter as following:

slack_event_adapter = SlackEventAdapter(os.environ.get("SLACK_EVENTS_TOKEN"), "/slack/events", app)

I made a typo while setting the variable, thus I was getting "Your URL didn't respond with the value of the challenge parameter." on the Event Subscription page with the following error in my terminal:

Traceback (most recent call last):
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\slackeventsapi\server.py", line 100, in event
    if req_signature is None or not self.verify_signature(req_timestamp, req_signature):
  File "D:\PycharmProjects\Slackbot\flipper\venv\lib\site-packages\slackeventsapi\server.py", line 60, in verify_signature
    str.encode(self.signing_secret),
TypeError: descriptor 'encode' for 'str' objects doesn't apply to a 'NoneType' object

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 2.2.1
python version: 3.8.6
OS version(s): Windows 10

Steps to reproduce:

  1. Create SlackEventAdapter object with NoneType value as a signing_secret parameter.
  2. Try an event subscription for your app.

Expected result:

Get the error that I've used the wrong value while creating the slack_event_adapter object

Actual result:

I got an error which was confusing at first and took some time to research

Attachments:

Logs, screenshots, screencasts, sample projects, funny gifs, etc.

Unable to cross `url_verification` phase in Event Request URL setup

Description

unable to cross url_verification phase in slack.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 3.0.1
python version: 3.8
OS version(s): Mac 13

Steps to reproduce:

Follow the steps as mentioned in Readme

Expected result:

App Events is verified in Slack

Actual result:

Our Request:
POST
"body": { 
	 "type": "url_verification",
	 "token": "",
	 "challenge": ""
}
Your Response:
"code": 
"error": "challenge_failed"
"body": {
  
}

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

Screenshot 2023-04-25 at 12 05 53

slackeventsapi.server.SlackEventAdapterException: Invalid request timestamp

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version:
python version:
OS version(s):

Steps to reproduce:

  1. Make a post request through POSTMAN to the slack_event_adapter to replicate sending a message through channel
  2. The json component of the request is given below which is sent as a "Pre-request Script".

Expected result:

The expected result was that the request would be parsed by my application and dealt accordingly.

Actual result:

I run into an error saying "slackeventsapi.server.SlackEventAdapterException: Invalid request timestamp" despite having HTTP_X_SLACK_REQUEST_TIMESTAMP configured and this is set dynamically to ensure that the timestamp is of the time when the request is sent. This is highlighted in the screenshot below.
Screen Shot 2021-05-14 at 11 42 23 AM
Screen Shot 2021-05-14 at 11 43 57 AM

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

Pyee expects an exception when emitting an error

Description

Pyee expects an exception when emitting an error

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 1.1.0
python version: 3.6.1
OS version(s): ubuntu within docker

Steps to reproduce:

  1. Fail a verification token check

Expected result:

The correct exception to be thrown

Actual result:

An exception about throwing an incorrect exception.

Attachments:

10.x.x.x - - [27/Jun/2018 08:13:45] "POST /slack/events HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.6/site-packages/slackeventsapi/server.py", line 63, in event
    self.emitter.emit('error', 'invalid verification token')
  File "/usr/local/lib/python3.6/site-packages/pyee/__init__.py", line 178, in emit
    raise args[0]
TypeError: exceptions must derive from BaseException

Should add the required bot events for the example program

The example program and instructions provided were very helpful, however they do not mention anything about the reaction_added event that the user needs to subscribe to in order to make the example work properly with the emoji reaction (in this case, it should mention both message.channels and reaction_added). It didn't take me too long to figure it out, but I could see this being an unneeded source of frustration.

It seems that this is along the same lines as issue #64, however the user closed the issue once they figured it out. I think just a small addition of an image (and mentioning the other permissions) would prevent further repeats of this issue.

BotSubscribe

Asynchronous event dispatching to allow Flask to respond immediately

Description

As per the Events API documentation, we should send a valid response in 3 seconds, when using this API I found it quite difficult to figure out how to achieve this when I tried to implement something which lasted longer than 3 seconds.

We are still trying to get it working in our bot, but it got somewhat messy and I feel like that it would be much nicer if it were in this library rather than having to make our own.

The way I'd see this being implemented is that the event emitter would run each handler in a background process by default (or maybe a way to opt-in to this behaviour?). I understand this might cause issues for bots which are already dependent on the current behaviour of the API though, but I would be curious to know your thoughts about whether this is something you'd like to include in some form.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

itsdangerous package conflict with latest version of flask

Description

The latest version of Flask (2.0.1) released on 2021-05-21 requires itsdangerous>=2.0 this package required itsdangerous<2 can this be safely changed so we can install the latest version of Flask

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 2.2.1
python version: 3.7
OS version(s): Mac OS 10.15.7

Steps to reproduce:

  1. Using Pipenv for depency resolution. pipenv install flask slackeventsapi

Actual result:

Resolving dependencies...
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
 Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: Could not find a version that matches itsdangerous<2,>=2.0 (from slackeventsapi==2.2.1->-r /var/folders/l2/z3fcfqdn6g56xqzyp36r6yyc0000gq/T/pipenv9_syt5ffrequirements/pipenv-4_xicpka-constraints.txt (line 14))
Tried: 0.9, 0.9.1, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 1.1.0, 1.1.0, 2.0.0, 2.0.0, 2.0.1, 2.0.1
Skipped pre-versions: 2.0.0a1, 2.0.0a1, 2.0.0rc1, 2.0.0rc1, 2.0.0rc2, 2.0.0rc2
There are incompatible versions in the resolved dependencies:
  itsdangerous<2 (from slackeventsapi==2.2.1->-r /var/folders/l2/z3fcfqdn6g56xqzyp36r6yyc0000gq/T/pipenv9_syt5ffrequirements/pipenv-4_xicpka-constraints.txt (line 14))
  itsdangerous>=2.0 (from flask==2.0.1->-r /var/folders/l2/z3fcfqdn6g56xqzyp36r6yyc0000gq/T/pipenv9_syt5ffrequirements/pipenv-4_xicpka-constraints.txt (line 6))

SSL Issue(?) when running on GAE Standard

Description

Fails to respond/create request to reply to slack when running on GAE Standard with a Flask backend.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 2.0.0
python version: 2.7
OS version(s): Google App Engine Standard

Steps to reproduce:

  1. Send an api call to "conversations.open" when passing in a user received from the "app_mention" event.
  2. Error
    (Relevant code):
@slack_events_adapter.on("app_mention")
 def mention_bot(data):
     logging.info(data)
     event = data["event"]
     user= event["user"]
     channel = event["channel"]
     logging.info(event)
     logging.info(user)
     dm_data = slack_client.api_call(
         "conversations.open",
         users="{0}".format(user))

Expected result:

Conversation to be opened without issue

Actual result:

Failed to open conversation

Stack Trace below

Attachments:

Exception on /slack/events [POST] (/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py:1761)
Traceback (most recent call last):
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackeventsapi/server.py", line 120, in event
    self.emitter.emit(event_type, event_data)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/pyee/__init__.py", line 151, in emit
    result = f(*args, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/main.py", line 35, in mention_bot
    users=user)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/client.py", line 184, in api_call
    self.token, request=method, timeout=timeout, **kwargs
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/server.py", line 349, in api_call
    response = self.api_requester.do(token, request, kwargs, timeout=timeout)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/slackrequest.py", line 84, in do
    return self.post_http_request(token, request, post_data, files, timeout, domain)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/slackrequest.py", line 116, in post_http_request
    proxies=self.proxies
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connection.py", line 304, in connect
    if self._tunnel_host:
AttributeError: 'VerifiedHTTPSConnection' object has no attribute '_tunnel_host'

Passing Flask app proxy as server

Hi Guys,

I have an app factory on my setup and the app object usually it is invoked as :
from flask import current_app as app

However, the slackeventsapi complains about the app object :
TypeError("Server must be an instance of Flask")

I have fixed adding the following to server.py :

from werkzeug.local import LocalProxy # Importing the localproxy class

Line 25
Changed from :
if isinstance(server, Flask):
to :
if isinstance(server, Flask) or isinstance(server, LocalProxy):

Basically, if a Flask app proxy is passed the api will carry on without complaining since it has the same methods as the Flask app object.

I hope this help other people and it is considered as a solution if more information is needed I am help to provide.

Thanks for the good work with the API.

What type of issue is this? (place an x in one of the [ ])

  • bug ?
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Reproducible in:

slackeventsapi version: slackeventsapi==2.1.0
python version: Python 3.7.3
OS version(s):

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.