class_docstr: Slack input channel implementation. Based on the HTTPInputChannel.
class_docstr_tok: ["Slack","input","channel","implementation",".","Based","on","the","HTTPInputChannel","."]
docstr: Extracts the metadata from a slack API event.
  
  Slack Documentation: https://api.slack.com/types/event
  
  Args:
      request: A `Request` object that contains a slack API event in the body.
  
  Returns:
      Metadata extracted from the sent event payload. This includes the output
          channel for the response, and users that have installed the bot.
docstr_tok: ["Extracts","the","metadata","from","a","slack","API","event",".","Slack","Documentation",":","https",":","\/\/api.slack.com\/types\/event","Args",":","request",":","A","`","Request","`","object","that","contains","a","slack","API","event","in","the","body",".","Returns",":","Metadata","extracted","from","the","sent","event","payload",".","This","includes","the","output","channel","for","the","response",",","and","users","that","have","installed","the","bot","."]
code: def get_metadata(self, request: Request) -> Dict[Text, Any]:
      """Extracts the metadata from a slack API event.
  
      Slack Documentation: https://api.slack.com/types/event
  
      Args:
          request: A `Request` object that contains a slack API event in the body.
  
      Returns:
          Metadata extracted from the sent event payload. This includes the output
              channel for the response, and users that have installed the bot.
      """
      content_type = request.headers.get("content-type")
  
      # Slack API sends either a JSON-encoded or a URL-encoded body depending on the
      # content
      if content_type == "application/json":
          # if JSON-encoded message is received
          slack_event = request.json
          event = slack_event.get("event", {})
          thread_id = event.get("thread_ts", event.get("ts"))
  
          users = []
          if "authed_users" in slack_event:
              users = slack_event.get("authed_users")
          elif (
              "authorizations" in slack_event
              and len(slack_event.get("authorizations")) > 0
          ):
              users.append(
                  slack_event.get("authorizations")[0].get("user_id")
              )
  
          return {
              "out_channel": event.get("channel"),
              "thread_id": thread_id,
              "users": users,
          }
  
      if content_type == "application/x-www-form-urlencoded":
          # if URL-encoded message is received
          output = request.form
          payload = json.loads(output["payload"][0])
          message = payload.get("message", {})
          thread_id = message.get("thread_ts", message.get("ts"))
  
          users = []
          if payload.get("user", {}).get("id"):
              users.append(payload.get("user", {}).get("id"))
  
          return {
              "out_channel": payload.get("channel", {}).get("id"),
              "thread_id": thread_id,
              "users": users,
          }
  
      return {}
  
imports: import asyncio
  import hashlib
  import hmac
  from http import HTTPStatus
  import json
  import logging
  import re
  import time
  from typing import Any, Awaitable, Callable, Dict, List, Optional, Set, Text
  from rasa.core.channels.channel import InputChannel, OutputChannel, UserMessage
  from rasa.shared.constants import DOCS_URL_CONNECTORS_SLACK
  from rasa.shared.exceptions import InvalidConfigException
  import rasa.shared.utils.io
  from sanic import Blueprint, response
  from sanic.request import Request
  from sanic.response import HTTPResponse
  from slack_sdk.web.async_client import AsyncWebClient
label_desc: Use image node_id 11 for calling the SlackInput obj's underlying member method code with example usage: obj.get_metadata(request) and returns: dict, dict, dict