For developers and enthusiasts eager to explore the Lingo project's API capabilities, we've prepared comprehensive documentation to guide you through the integration process. The API documentation covers endpoints, request methods, response formats, and authentication mechanisms, providing all the essential information for seamless integration into your applications.
Explore the Lingo API Documentation: https://documenter.getpostman.com/view/19488087/2s9YJXZ4sv
The WebSocket integration in Lingo enables real-time communication during quizzes, enhancing the interactive and dynamic nature of the language learning experience. To connect to the WebSocket server, use the following details:
WebSocket URL:
wss://lingo-6mpr.onrender.com
- Description: Proficiency level of the quiz.
- Example:
?level=1
- Description: Language code for the quiz.
- Example:
?lang=en
- Description: Access token for authentication and authorization.
- Example:
?token=your-access-token
const socket = new WebSocket(
"wss://lingo-6mpr.onrender.com?level=Intermediate&lang=en-US&token=your-access-token"
);
socket.addEventListener("open", (event) => {
// Connection is established
console.log("WebSocket Connection Opened:", event);
});
socket.addEventListener("message", (event) => {
// Handle incoming messages during the quiz
console.log("WebSocket Message Received:", event.data);
});
socket.addEventListener("close", (event) => {
// Connection is closed
console.log("WebSocket Connection Closed:", event);
});
socket.addEventListener("error", (event) => {
// Handle errors
console.error("WebSocket Error:", event);
});
-
quiz-start
Event:- Description: Triggered when the quiz starts.
- Example:
{ "type": "start", "id": "650fcbbd460b509b4bc10de0", "diff": 1, "ques": "Choose the correct verb form: 'She _____ the door open.'", "opt": ["Hold", "Holding", "Holds", "Held"], "score": 0 }
-
question
Event:- Description: Triggered when a new question is presented.
- Example:
{ "type": "ques", "id": "650fcbbd460b509b4bc10dcd", "diff": 0, "ques": "What part of speech is the word 'quickly'?", "opt": ["Noun", "Verb", "Adjective", "Adverb"], "score": -5 }
-
error
Event:- Description: Triggered when an error is occured.
- Example:
{ "type": "error", "accessTokenExpired": true, "message": "An error occured, Please Try again", "error": "Access Token Expired" }
-
quiz-end
Event:-
Description: Triggered when the quiz concludes.
-
Example:
{ "type": "end", "message": "Quiz Complete", "score": -50, "bonus": 14 }
-
-
Send Answer
socket.send:- Description: When user submits the quiz answer. Send it to the socket in the following format.
- Example:
{ "id": "650fcbbd460b509b4bc10de0", "ans": "3" } <!-- id : questionId -->
- Ensure that the WebSocket connection is established before attempting to interact with the quiz events.
- The access token provided in the query parameters should be valid for authentication.
Integrate the WebSocket connection into your application to provide users with a real-time and engaging language learning quiz experience. If you have any questions or need assistance, connect with our development community.
Happy coding with Lingo WebSocket! 🌐🎉