title: How to pass data received via HTTP POST from a Python Flask script to a separate Python script for processing?
body: <p>Alright guys, so here's my problem.</p>
  
  <p>I am in the process of developing a Slack app with a packaged bot that allows the user to play a game in Slack. I have successfully built the bot and packaged it with the app as per the <a href="https://api.slack.com/slack-apps" rel="nofollow noreferrer">API guidelines</a>. Once I discovered the <a href="https://api.slack.com/docs/message-buttons" rel="nofollow noreferrer">Interactive Messages</a> feature, I decided to implement said feature for a more user-friendly take on the game. </p>
  
  <p>The interactive messages feature allows you to post messages with buttons, which the user can click to invoke an action. My bot script, let's call it <code>bot.py</code>, prompts the user (using the Slack <a href="https://api.slack.com/methods/chat.postMessage" rel="nofollow noreferrer">chat.postMessage</a> function) with a message containing some buttons from which to choose. This script has one class (I know it should be more modular but all in good time), which opens a web-socket for communication via the <a href="https://api.slack.com/rtm" rel="nofollow noreferrer">Slack RTM API</a>. As such, when the script runs, it is always "listening" for a command from a user in a channel directed as follows: <code>@botname command</code>. The portion of the script that invokes this "always listening" state looks like this:  </p>
  
  <pre><code>#bot.py
  ...
  if slack_client.rtm_connect():
          print("MYBOT v1.0 connected and running!")
          while True:
              command, channel, user = self.parse_slack_output(slack_client.rtm_read())
              if command and channel:
                  if channel not in self.channel_ids_to_name.keys():
                      #this (most likely) means that this channel is a PM with the bot
                      self.handle_private_message(command, user)
                  else:
                      self.handle_command(command, channel, user)
              time.sleep(READ_WEBSOCKET_DELAY)
      else:
          print("Connection failed. Invalid Slack token or bot ID?")
  </code></pre>
  
  <p>That's all good and fine. Now, let's say the user has used a command to successfully create a game instance and has started playing. At a certain point, the user is prompted for a trump suit like so:  </p>
  
  <pre><code>#bot.py
  ...
  attachments =[{
  "title":"Please select index for trump suit:",
  "fallback":"Your interface does not support interactive messages.",
  "callback_id":"prompt_trump_suit", 
  "attachment_type":"default", 
  "actions":
          [{"name":"diamonds","text":":diamonds:","type":"button","value":"0"},
          {"name":"clubs","text":":clubs:","type":"button","value":"1"},
          {"name":"hearts","text":":hearts:","type":"button","value":"2"},
          {"name":"spades","text":":spades:","type":"button","value":"3"}]
  }]
  slack.chat.post_message(
          channel=player_id,
          as_user=True,
          attachments=attachments
          )
  </code></pre>
  
  <p>The interactive message <a href="https://api.slack.com/docs/messages/builder?msg=%7B%22username%22%3A%22mybot%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22Please%20select%20index%20for%20trump%20suit%3A%22%2C%22fallback%22%3A%22Your%20interface%20does%20not%20support%20interactive%20messages.%22%2C%22callback_id%22%3A%22prompt_trump_suit%22%2C%22attachment_type%22%3A%22default%22%2C%22actions%22%3A%5B%7B%22name%22%3A%22diamonds%22%2C%22text%22%3A%22%3Adiamonds%3A%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%220%22%7D%2C%7B%22name%22%3A%22clubs%22%2C%22text%22%3A%22%3Aclubs%3A%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%221%22%7D%2C%7B%22name%22%3A%22hearts%22%2C%22text%22%3A%22%3Ahearts%3A%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%222%22%7D%2C%7B%22name%22%3A%22spades%22%2C%22text%22%3A%22%3Aspades%3A%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%223%22%7D%5D%7D%5D%7D" rel="nofollow noreferrer">looks like this</a>. The action of clicking on one of the buttons in this message sends a payload via an HTTP POST to a web server. My other script in the project, which we will call <code>app.py</code>, is a Flask script which successfully receives this POST request when the user clicks one of the buttons. The portion of the script that receives the POST request looks like this:</p>
  
  <pre><code>#app.py
  ...
  # handles interactive button responses for mybot
  @app.route('/actions', methods=['POST'])
  def inbound():
      payload = request.form.get('payload')
      data = json.loads(payload)
      token = data['token']
      if token == SLACK_VERIFICATION_TOKEN:
          print 'TOKEN is good!'
          response_url = data['response_url']
          channel_info = data['channel']
          channel_id = channel_info['id']
          user_info = data['user']
          user_id = user_info['id']
          user_name = user_info['name']
          actions = data['actions'][0]
          value = actions['value']
          print 'User sending message: ',user_name
          print "Value received: ",value
      return Response(), 200
  </code></pre>
  
  <p>When the button is clicked, I get the expected output:   </p>
  
  <pre><code>TOKEN is good!
  User sending message:  my_username
  Value received:  3
  </code></pre>
  
  <p>So everything is successful up to this point. Now, what I want to do is to take that POST information and use it to invoke a function in my <code>bot.py</code> script that handles the trump suit selection. The problem is that if I were to invoke that function, let's call it <code>handle_trump_suit_selection()</code>, I would first have to instantiate a <code>Bot()</code> object in the <code>app.py</code> file, which of course would not work as desired because the function would be called with a new <code>Bot()</code> instance, and therefore would not be in the same state as the current game.</p>
  
  <p>So how the heck can I get the POST information back to the desired <code>Bot()</code> instance in <code>bot.py</code> for further processing? I'm new to OOP in Python and especially new to Flask and the Slack API, so go easy on me ;).</p>
  
  <p>Thanks in advance.</p>