This is an example project for TalkJS's tutorial on how to build a Spring Boot chat app with TalkJS.
This example demonstrates how to integrate TalkJS with a Java application that uses the Spring Boot framework. There are two projects present inside the repo:
- The
SpringBootTalkJS
project contains the Spring Boot backend, which serves a REST endpoint with user data. - The
talkjs-springboot-frontend
project contains the frontend code, which uses TalkJS's JavaScript SDK to create chats between users.
To run this tutorial, you will need:
- A TalkJS account
- The Java Development Kit
- Maven to build the project
-
Clone or download this project.
-
From the
SpringBootTalkJS
directory:- Run
mvn clean install
to build the project - Run
mvn spring-boot:run
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 http://localhost:8080/createUser \ -H "Content-Type: application/json" \ -d '{ "name": "Tom Hardy", "dp": "https://randomuser.me/api/portraits/men/1.jpg", "email": "tom.hardy@operator.com", "role": "AGENT" }'
curl -X POST http://localhost:8080/createUser \ -H "Content-Type: application/json" \ -d '{ "name": "John Morrison", "dp": "https://randomuser.me/api/portraits/men/62.jpg", "email": "john.morrison@operator.com", "role": "USER" }'
-
From the
talkjs-springboot-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