Two sessions get collides in chat

Question:
when two users interact with my application they end up in the same chat interface how can I create separate sessions for user
Thank you in Advance !!
Repl link:

from function import text_complition, ref_prompt
from twilio_api import send_message

from flask import Flask, request, session

app = Flask(__name__)
app.secret_key = 'mall_data'


@app.route('/')
def home():
  return 'All is well...'


@app.route('/twilio/receiveMessage', methods=['POST'])
def receiveMessage():
  try:
    # Extract incoming parameters from Twilio
    message = request.form['Body']
    sender_id = request.form['From']
    sending_id = request.form['To']

    if sending_id in session:
      # Get response from OpenAI
      result = text_complition(message)
      # print(result['response'])
      if result['status'] == 1:
        send_message(sender_id, result['response'])
    else:
      session['sending_id'] = sending_id
      # Get response from OpenAI
      result = text_complition(message)
      # print(result['response'])
      if result['status'] == 1:
        send_message(sender_id, result['response'])
  except:
    pass
  return 'OK', 200


if __name__ == '__main__':
  app.run()

You could try making a Replit Bounty for this.

1 Like

okay I will do that. Thank you :smile: