text: import socket
  import os
  import logging
  from flask import Flask
  from slack import WebClient
  from slackeventsapi import SlackEventAdapter
  #import ssl as ssl_lib
  #import certifi
  from onboarding_tutorial import OnboardingTutorial
  
  # Initialize a Flask app to host the events adapter
  app = Flask(__name__)
  slack_events_adapter = SlackEventAdapter("ccd1f98596823d4681f08a633832eb98", "/slack/events", app)
  #slack_events_adapter = SlackEventAdapter(os.environ["SLACK_SIGNING_SECRET"], "/slack/events", app)
  
  # Initialize a Web API client
  slack_web_client = WebClient(token="xoxb-872466766737-994159634896-lzX9oxG9IikZuoJ3ddHhNPIm")
  #slack_web_client = WebClient(token=os.environ['SLACK_BOT_TOKEN'])
  
  
  
  
  # For simplicity we'll store our app data in-memory with the following data structure.
  # onboarding_tutorials_sent = {"channel": {"user_id": OnboardingTutorial}}
  onboarding_tutorials_sent = {}
  
  
  def start_onboarding(user_id: str, channel: str):
      # Create a new onboarding tutorial.
      onboarding_tutorial = OnboardingTutorial(channel)
  
      # Get the onboarding message payload
      message = onboarding_tutorial.get_message_payload()
  
      # Post the onboarding message in Slack
      response = slack_web_client.chat_postMessage(**message)
  
      # Capture the timestamp of the message we've just posted so
      # we can use it to update the message after a user
      # has completed an onboarding task.
      onboarding_tutorial.timestamp = response["ts"]
  
      # Store the message sent in onboarding_tutorials_sent
      if channel not in onboarding_tutorials_sent:
          onboarding_tutorials_sent[channel] = {}
      onboarding_tutorials_sent[channel][user_id] = onboarding_tutorial
  
  
  # ================ Team Join Event =============== #
  # When the user first joins a team, the type of the event will be 'team_join'.
  # Here we'll link the onboarding_message callback to the 'team_join' event.
  @slack_events_adapter.on("team_join")
  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_id)
      channel = response["channel"]["id"]
  
      # Post the onboarding message.
      start_onboarding(user_id, channel)
  
  
  # ============= Reaction Added Events ============= #
  # When a users adds an emoji reaction to the onboarding message,
  # the type of the event will be 'reaction_added'.
  # Here we'll link the update_emoji callback to the 'reaction_added' event.
  @slack_events_adapter.on("reaction_added")
  def update_emoji(payload):
      """Update the onboarding welcome message after receiving a "reaction_added"
      event from Slack. Update timestamp for welcome message as well.
      """
      event = payload.get("event", {})
  
      channel_id = event.get("item", {}).get("channel")
      user_id = event.get("user")
  
      if channel_id not in onboarding_tutorials_sent:
          return
  
      # Get the original tutorial sent.
      onboarding_tutorial = onboarding_tutorials_sent[channel_id][user_id]
  
      # Mark the reaction task as completed.
      onboarding_tutorial.reaction_task_completed = True
  
      # Get the new message payload
      message = onboarding_tutorial.get_message_payload()
  
      # Post the updated message in Slack
      updated_message = slack_web_client.chat_update(**message)
  
      # Update the timestamp saved on the onboarding tutorial object
      onboarding_tutorial.timestamp = updated_message["ts"]
  
  
  # =============== Pin Added Events ================ #
  # When a users pins a message the type of the event will be 'pin_added'.
  # Here we'll link the update_pin callback to the 'reaction_added' event.
  @slack_events_adapter.on("pin_added")
  def update_pin(payload):
      """Update the onboarding welcome message after receiving a "pin_added"
      event from Slack. Update timestamp for welcome message as well.
      """
      event = payload.get("event", {})
  
      channel_id = event.get("channel_id")
      user_id = event.get("user")
  
      # Get the original tutorial sent.
      onboarding_tutorial = onboarding_tutorials_sent[channel_id][user_id]
  
      # Mark the pin task as completed.
      onboarding_tutorial.pin_task_completed = True
  
      # Get the new message payload
      message = onboarding_tutorial.get_message_payload()
  
      # Post the updated message in Slack
      updated_message = slack_web_client.chat_update(**message)
  
      # Update the timestamp saved on the onboarding tutorial object
      onboarding_tutorial.timestamp = updated_message["ts"]
  
  
  # ============== Message Events ============= #
  # When a user sends a DM, the event type will be 'message'.
  # Here we'll link the message callback to the 'message' event.
  @slack_events_adapter.on("message")
  def message(payload):
      """Display the onboarding welcome message after receiving a message
      that contains "start".
      """
      event = payload.get("event", {})
      channel_id = event.get("channel")
      user_id = event.get("user")
      text = event.get("text")
  #    ts = event.get("ts")
      ts = ""
      if text != None and user_id != "UV84PJNSC":
          print("New message: "+text+" user: "+user_id) 
          host = socket.gethostname()
  
          slack_web_client.chat_postMessage(channel=channel_id,text=host+": te conteste :D",thread_ts=ts)
      else:
          print("Encontre None")
  
      if text and text.lower() == "start":
          return start_onboarding(user_id, channel_id)
  
  
  if __name__ == "__main__":
      logger = logging.getLogger()
      logger.setLevel(logging.DEBUG)
      logger.addHandler(logging.StreamHandler())
  #    ssl_context = ssl_lib.create_default_context(cafile=certifi.where())
  #    ssl_context = ssl_lib.create_default_context(cafile="/etc/letsencrypt/live/bot.curzona.net/fullchain.pem")
  #    ssl_context = ssl_lib.create_default_context(cafile="/etc/letsencrypt/live/bot.curzona.net/privkey.pem")
  
  #   /etc/letsencrypt/live/bot.curzona.net/fullchain.pem
  #   Your key file has been saved at:
  #   /etc/letsencrypt/live/bot.curzona.net/privkey.pem
  #    app.run(host='0.0.0.0',port=3000, debug=True)
      app.run(host='0.0.0.0',port=443,ssl_context=('/etc/letsencrypt/live/bot.curzona.net/fullchain.pem', '/etc/letsencrypt/live/bot.curzona.net/privkey.pem'))
  