# Buggy code
def onboarding_message(payload):
    """Create and send an onboarding welcome message to new users. Save the
    time stamp of this message so we can update this message in the future.
    """
    event = payload.get("event", {})

    # Get the id of the Slack user associated with the incoming event
    user_id = event.get("user", {}).get("id")

    # Open a DM with the new user.
    response = slack_web_client.im_open(user=user_id)
    channel = response["channel"]["id"]

    # Post the onboarding message.
    start_onboarding(user_id, channel)


# Traceback (slack_sdk.errors.SlackApiError)
Traceback (most recent call last):
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\slackeventsapi\server.py", line 120, in event
self.emitter.emit(event_type, event_data)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\pyee\_base.py", line 113, in emit
handled = self._call_handlers(event, args, kwargs)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\pyee\_base.py", line 96, in _call_handlers
self._emit_run(f, args, kwargs)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\pyee\_base.py", line 81, in _emit_run
f(*args, **kwargs)
File "D:/_pyCharm/mySlackWebClient2/app.py", line 57, in onboarding_message
response = slack_web_client.conversations_open(user=user_id)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\slack_sdk\web\client.py", line 1224, in conversations_open
return self.api_call("conversations.open", json=kwargs)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\slack_sdk\web\base_client.py", line 121, in api_call
return self._sync_send(api_url=api_url, req_args=req_args)
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\slack_sdk\web\base_client.py", line 164, in _sync_send
additional_headers=headers,
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\slack_sdk\web\base_client.py", line 292, in _urllib_api_call
status_code=response["status"],
File "D:\_pyCharm\mySlackWebClient2\venv\lib\site-packages\slack_sdk\web\slack_response.py", line 201, in validate
raise e.SlackApiError(message=msg, response=self)
slack_sdk.errors.SlackApiError: The request to the Slack API failed.


The server responded with: {'ok': False, 'error': 'channel_not_found'}


127.0.0.1 - - [06/Dec/2020 03:50:07] "POST /slack/events HTTP/1.1" 500 -

# Fixed code
def onboarding_message(payload):
    """Create and send an onboarding welcome message to new users. Save the
    time stamp of this message so we can update this message in the future.
    """
    event = payload.get("event", {})

    # Get the id of the Slack user associated with the incoming event
    user_id = event.get("user", {}).get("id")

    # Open a DM with the new user.
    response = slack_web_client.conversations_open(users=user_id)
    channel = response["channel"]["id"]

    # Post the onboarding message.
    start_onboarding(user_id, channel)