This is an example project for TalkJS's tutorial on how to build a Flask chat app with TalkJS.
This example demonstrates how to integrate TalkJS with a Python application that uses the Flask framework. There are two projects present inside the repo:
talkjs-flask-python
: This project contains the Flask backend, which serves a REST endpoint with user data.talkjs-frontend
: This project contains the frontend code, which uses TalkJS's JavaScript SDK to create chats between users.
To run this tutorial, you will need:
-
Clone or download this project.
-
From the
talkjs-flask-python
directory:- Run
pip install flask
andpip install flask-cors
to install the dependencies - Run
python3 flask-python.py
to run the project
- Run
-
Add example users to the database by making POST requests to
localhost:8080/createUser
. For example, you can create two example users with the followingcurl
queries:curl -X POST -H "Content-Type: application/json" -d '{ "id": 1, "name": "Tom Hardy", "dp": "https://randomuser.me/api/portraits/men/1.jpg", "email": "[email protected]", "role": "AGENT" }' http://localhost:8080/createUser/
curl -X POST -H "Content-Type: application/json" -d '{ "id": 2, "name": "John Morrison", "dp": "https://randomuser.me/api/portraits/men/62.jpg", "email": "[email protected]", "role": "USER" }' http://localhost:8080/createUser/
-
From the
talkjs-frontend
directory:- Replace
<APP_ID>
inscript.js
with the value found in the Settings tab of your TalkJS dashboard. - Open
index.html
from a browser, or through an extension like VS Code's Live Server, to view the app
- Replace