Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 2.13 KB

README.md

File metadata and controls

49 lines (36 loc) · 2.13 KB

TalkJS and Flask example

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.

Prerequisites

To run this tutorial, you will need:

How to run the tutorial

  1. Clone or download this project.

  2. From the talkjs-flask-python directory:

    1. Run pip install flask and pip install flask-cors to install the dependencies
    2. Run python3 flask-python.py to run the project
  3. Add example users to the database by making POST requests to localhost:8080/createUser. For example, you can create two example users with the following curl 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/
    
  4. From the talkjs-frontend directory:

    1. Replace <APP_ID> in script.js with the value found in the Settings tab of your TalkJS dashboard.
    2. Open index.html from a browser, or through an extension like VS Code's Live Server, to view the app