slackapi / python-slack-events-api

Slack Events API adapter for Python (Flask required)
https://api.slack.com/events
MIT License
343 stars 116 forks source link

Added value check to init method #91

Closed temurchichua closed 3 years ago

temurchichua commented 3 years ago

Added the value check to the init method.

Summary

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

I took some time to look through the source code and see what went wrong. I think value checking could come in handy for other developers to easily find the error in their project.

Requirements (place an x in each [ ])

seratch commented 3 years ago

Hi @temurchichua, thanks for taking the time to make this pull request! We are happy to merge this improvement but I have a few comments. Can you check them when you have a chance?

temurchichua commented 3 years ago

@seratch thanks for reviewing the pull request. Good points. I've included changes in the commit.

seratch commented 3 years ago

@temurchichua Thanks for the contribution!