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 classic JavaScript SDK to create chats between users.
To run this tutorial, you will need:
-
Clone or download this project.
-
From the
talkjs-flask-pythondirectory:- Run
pip install flaskandpip install flask-corsto install the dependencies - Run
python3 flask-python.pyto 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 followingcurlqueries:curl -X POST -H "Content-Type: application/json" -d '{ "id": 1, "name": "Tom Hardy", "dp": "https://randomuser.me/api/portraits/men/1.jpg", "email": "tom.hardy@operator.com", "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": "john.morrison@operator.com", "role": "USER" }' http://localhost:8080/createUser/
-
From the
talkjs-frontenddirectory:- Replace
<APP_ID>inscript.jswith the value found in the Settings tab of your TalkJS dashboard. - Open
index.htmlfrom a browser, or through an extension like VS Code's Live Server, to view the app
- Replace